Allah says:
βAnd I did not create the jinn and mankind except to worship Me.β Quran 51:56
β[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 β Quran 67:2
Allah is free of need, yet He creates what He wills.