The Qur'anic perspective is: good things happen to bad people, and bad things happen to good people; both are tests.
Be sure we shall test you with something of fear and hunger, some loss in goods or lives or the fruits (of your toil), but give glad tidings to those who patiently persevere, Who say, when afflicted with calamity: "To God We belong, and to Him is our return." (2:155-56)
Ye shall certainly be tried and tested in your possessions and in your personal selves; and ye shall certainly Hear much that will grieve you, from those who received the Book before you and from those who worship many gods. But if ye persevere patiently, and guard against evil,-then that will be a determining factor in all affairs. (3:186)
Nor strain thine eyes in longing for the things We have given for enjoyment to parties of them, the splendor of the life of this world, through which We test them: but the provision of thy Lord is better and more enduring. (20:131)
Every soul shall have a taste of death: and We test you by evil and by good by way of trial. to Us must ye return. (21:35)
In the first set of verses, 2:155-56, the response, "To God We belong, and to Him is our return," is what Muslims say upon learning of the death of a person. Death, of course, is another test, not only for the person who is dying (assuming he or she knows he/she will be dying soon), but for the people around that person, whether related or not. Indeed, people might be afflicted with some test, not so much that they themselves are being tested, but the other people around them. There is another passage in the Qur'an, where the Prophet Abraham (pbuh) prays,
"Our Lord! Make us not a (test and) trial for the Unbelievers, but forgive us, our Lord! for Thou art the Exalted in Might, the Wise." (60:5)
Muslims believe that Allah (swt) has His plan, but that we are not privy to it. For example, I suspect that the German Holocaust of the Jews was quite possibly a test to both the Germans and the Jews and, likewise, right now, the Jews and the Palestinians are being tested as well. (And we observers on the outside of that conflict may also be currently being tested, to see how we react to the suffering going on.) From this perspective, I believe that thinking of events in the life of an individual or community as being tests helps to sharpen one's moral judgments; i.e., what is the morally correct thing to do or say under the various circumstances? If you are Oskar Schindler, do you help save the lives of your Jewish workers or do you ignore them while collecting your steamer trunks' full of cash? Do you weep over the thought that you could have sold your Nazi membership pin to save the life of one more person (the movie) or do you drive away quietly in the middle of the night with diamonds stashed in the panels of your car's doors? (According to the book, the diamonds were stolen a few days later; easy come, easy go.) Do we follow the example of the Prophet Ayyub (Job, pbuh) when we are tested?
And (remember) Job, when He cried to his Lord, "Truly distress has seized me, but Thou art the Most Merciful of those that are merciful." So We listened to him: We removed the distress that was on him, and We restored his people to him, and doubled their number,- as a Grace from Ourselves, and a thing for commemoration, for all who serve Us. (21:83-84)