Nothing on this earth is created in vain, but rather with wisdom. Understanding this fact depends on the wisdom of people themselves. One of the most important precepts is that we are being tested throughout our whole lives. Allah tests our sincerity and our faith in different situations. He may create difficulties to reveal whether we behave with patience or not. He may give us favours to test whether we are grateful to Him or not. Find below few verses from the Glorious Qur'an which point out this fact.
"Did you think that you would enter Heaven without Allah testing those of you who fought hard (in His Cause) and remained steadfast?" The Holy Qur'an, Surat Aal-e-Imran, Chapter 3, Verse 142
"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." The Holy Qur'an, Surat al-Ankaboot, Chapter 29, Verses 2-3
"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." The Holy Qur'an, Surat al-Anbiya, Chapter 21, Verse 35
"Be sure we shall test you with fear and hunger, some loss in goods or lives or the fruits (of your toil), but give glad tidings to those who patiently persevere." The Holy Qur'an, Surat al-Baqara, Chapter 2, Verse 155