"Take care and do not pray to the Lord, saying, "Lord! I pray to You to protect and guard me from temptations and trials", for there is none who is not tempted and tried. But beseech Him to guard you against such temptation as may lead you towards wickedness and sins because Allah says in His Holy Book, Know that your wealth and children are temptations. (Surah al-Anfal, 8: 28) It means Allah tried people through wealth and children so that it may be tested as to who is content with what he gets honestly and who is thankful to Allah for the position he is placed in with regard to his children.
Though Allah knows them better than even they know themselves, yet those trials and tests are for the purpose of their realizing and knowing those deeds which merit reward or which deserve punishment. There are some people who love to have male children and hate daughters and there are some who simply crave for wealth and hate poverty."
Mola Ali (a.s) Ibn e Abu Talib (a.s)
Ref: Nahjul Balagha (Saying # 093)