I think part of the test is when a believer supplicates and receives no response, and he repeats the dua for a long time and sees no sign of a response. He should realize that this is a test and needs patience.
What a person experiences of waswaas (whispers from shaytan) when the response is delayed is a sickness which needs medicine – I have experienced this myself. A calamity befell me and I supplicated and did not see any response, and Iblis started to lay his traps. Sometimes he said: The generosity (of Allah) is abundant and He is not miserly, so why is there a delay?
I said to him: Be gone, O cursed one, for I have no need of anyone to argue my case and I do not want you as a supporter!
Then I told myself: Beware of going along with his whispers, for if there was no other reason for the delay except that Allah is testing you to see whether you will fight the enemy, that is sufficient wisdom.
My soul (nafs) said: How could you explain the delay in the response of Allah to your prayers for relief from this calamity?
I said: It is proven with evidence that Allah, may He be glorified and exalted, is the Sovereign, and the Sovereign may withhold or give, so there is no point in objecting to Him.
The wisdom behind that is proven in definitive evidence. I may think that something is good, but wisdom does not dictate it, but the reason for that may be hidden, just as a doctor may do things that appear outwardly to be harmful, intending some good purpose thereby. Perhaps this is something of that nature.
There may be an interest to be served by delay, and haste may be harmful. The Prophet (peace and blessings of Allah be upon him) said: “A person will be fine so long as he does not become impatient and says, ‘I prayed but I did not receive any answer.’”
The response may be withheld because of some fault in you. Perhaps there was something dubious in what you ate or your heart was heedless at the time when you said the dua, or your punishment is being increased by means of your need being withheld, because of some sin from which you have not repented sincerely. So look for some of these reasons, so that you might achieve your aim.
You should examine the intention behind this request, because attaining it may lead to more sin, or prevent you from doing some good, so withholding it is better.
Perhaps losing what you have missed out on will cause you to turn to Allah and getting it will distract you from Him. This is obvious, based on the fact that were it not for this calamity you would not have turned to Him, because the real calamity is what distracts you from Him, but what makes you stand before Him is good for you and is in your best interests.
If you ponder these things you will focus on what is more beneficial for you, such as correcting a mistake or seeking forgiveness or standing before Allah and beseeching Him, and forget about what you have missed out on.
It was narrated that Faddalah ibn ‘Ubayd said: The Prophet (peace and blessings of Allah be upon him) heard a man making dua after his prayer, but he did not send blessings upon the Prophet (peace and blessings of Allah be upon him). The Prophet (peace and blessings of Allah be upon him) said: “This man is in a hurry.” Then he called him and said to him or to someone else: “When any one of you has finished praying (and makes dua), let him start by praising Allah, then let him send blessings upon the Prophet (peace and blessings of Allah be upon him), then after that let him ask for whatever he wants.” Al-Albani said: it is a saheeh hadeeth. (Saheeh Sunan al-Tirmidhi, 2765.
The Prophet (peace and blessings of Allah be upon him) said: “The slave will receive a response so long as his dua does not involve sin or severing of family ties, and so long as he is not hasty.” It was said, “What does being hasty mean?” He said: “When he says, ‘I made dua and I made dua, and I have not seen any response,’ and he gets frustrated and stops making dua.” Narrated by al-Bukahari, 6340; Muslim, 2735.