But in verse 51:56, Allah says he created mankind only to worship him - which suggests that god wants to be worshipped, rather than creating life as a test. This paints a picture of a needy god driven by ego.
In fact, the "test" idea is a kind of circular reasoning because if no one exists there is no need to test them. The test only becomes possible once humanity has been created. So creating them simply in order to test them seems irrational, especially if the consequences of failure are so great, and the circumstances that lead to failure are engineered by god himself.