The answer to this question is from the Noble Qur’an
Allah Almighty said:
And I did not create the jinn and mankind except to worship Me.[51. Adh-Dhāriyāt: 56]
It is Allāh who has created seven heavens and of the earth, the like of them.[1][His] command descends among them so you may know that Allāh is over all things competent and that Allāh has encompassed all things in knowledge.[65. At-Talāq: 12]
[He] who created death and life to test you [as to] which of you is best in deed - and He is the Exalted in Might, the Forgiving -[67. Al-Mulk: 2]
And [mention, O Muḥammad], when your Lord said to the angels, "Indeed, I will make upon the earth a successive authority."[2]They said, "Will You place upon it one who causes corruption therein and sheds blood, while we exalt You with praise and declare Your perfection?"[3]He [Allāh] said, "Indeed, I know that which you do not know."[2. Al-Baqarah: 30]