Mesilas Yesharim says, "Kol inyanei haolam nisyanos heim l'adam -- All matters in this world, everything, are tests for man."
That's a sweeping statement! What does it mean tests? Hashem has to test you to know what you are? He doesn't know beforehand what you're going to do? What's the purpose of a test?
And the answer is when you put gold into a refining furnace and it melts and the dross swims to the surface and you ladle off the dross so only pure gold remains. You're not testing the gold, you're purifying the gold. And so everything in this world is for the purpose of elevating man.
- Greatness Of Work (#662)