Nothing on earth is created in vain, but rather with wisdom. Understanding this fact depends on the wisdom of people themselves. One whose faith and consequently whose wisdom and prudence increase, will happen to grasp this reasoning much better in time.
One of the most important precepts is that we are being tested throughout our whole lives. Allah tests our sincerity and our faith on different occasions. He may give favours to test whether we are grateful to Him or not. He may create difficulties, for us, to reveal whether we behave with patience or not:
"Every soul shall have a taste of death: and We test you by evil and by good by way of trial. To Us you will be returned." (Surat al-Anbiya, 21:35)
We are to be tested in various ways. This is explained in the Qur'an in the verse below:
"Be sure we shall test you with fear and hunger, someloss in goods or lives or the fruits (of your toil), but give glad tidings to those who patiently persevere." (Surat al-Baqara, 2:155)
Our lives have indeed been planned with the mystery of our being tested. First of all, we are being tested in our physical beings. The Qur'an states that "Verily We created Man from a drop of mingled sperm, in order to try him: So We gave him (the gifts of) hearing and sight." (Surat al-Insan, 76:2). Consequently, everything we hear and see is actually a part of the test. In all kinds of situations, we will be tested to see whether we behave in accordance with the Qur'an or with our own vain desires.
Allah tests the steadfastness of the believers with various difficulties. One of the most important of these is the oppression of the believers by the unbelievers. All these misdeeds, like verbal attacks, mocking, physical oppression and even torture and murder attempts, are only a means of trial for the believers. In one of the verses; it is said:
"You shall certainly be tried and tested in your possessions and in your personal selves; and you 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 you persevere patiently, and guard against evil, then that will be a determining factor in all affairs." (Surat Aal-e-Imran, 3:186)
The most important point to comprehend is that all of these deprivations and misadventures are created by Allah as a special kind of test. One who does not understand this will become very superficial. The Qur'an cites a pertinent tale of certain Jews.
"Ask them concerning the town standing close by the sea; when they transgressed in the matter of the Sabbath. For on the day of their Sabbath, their fish did come to them, openly holding up their heads, but on the day they had no Sabbath, they came not: thus did We made a trial for them, for they were given to transgression. " (Surat al-A'raf, 7:163)
Only the individual who has wisdom can realize that he is being tested, and can succeed in these tests by again using his wisdom. Therefore, a believer should not forget that he is being tested throughout his life. These tests cannot be passed or the heaven cannot be attained simply by saying 'I believe'.
"Do men think that they will be left alone on saying 'We believe', and that they will not be tested? We did test those before them, and Allah will certainly know those who are true from those who are false." (Surat al-Ankaboot, 29:2-3)
And in another verse Allah says:
"Did you think that you would enter Heaven without Allah testing those of you who fought hard (in His Cause) and remained steadfast?" (Surat Aal-e-Imran, 3:142)