In the name of Allah,
Sometimes I hear people die around me, I want to be like them because their test is over, Is it allowed to wish like that?
May Allah reward us
No it is at least frowned upon due to ahadith such as:
None amongst you should make a request for death, and do not call for it before it comes, for when any one of you dies, he ceases (to do good) deeds and the life of a believer is not prolonged but for goodness. (Sahih Muslim)
"None of you should long for death, for if he is a good man, he may increase his good deeds, and if he is an evil-doer, he may stop the evil deeds and repent."
On the opposite it is recommended to live longer and do good, repent and find joy in worshiping Allah and doing good deeds. And that's why the prophet () prohibited wishing for death as it means the end of all the opportunities to do good, ask for forgiveness etc.
Nevertheless he () recommended for those who insist on making a du'a asking for it to say instead:
None of you should make a request for death because of the trouble in which he is involved, but if there is no other help to it, then say:
O Allah, keep me alive as long as there is goodness in life for me and bring death to me when there is goodness in death for me. (Sahih Muslim and Sahih al-Bukhari)
Imam an-Nawawi commented on the first ahdith above saying:
This hadeeth clearly indicates that it is makrooh to wish for death because of some harm that has befallen one, such as loss or distress caused by an enemy, or other such hardships of this world. But if a person fears harm or fitnah with regard to his religious commitment, it is not makrooh to wish for death, according to this hadeeth, and several of the salaf did that. (Source islamqa #46592)
Another reason for this prohibition was quoted in the linked fatwa:
The throes of death are very hard, and the terror of seeing one's end draw nigh is immense. Man is faced with nothing else like it. Moreover, no one knows what awaits him after death. We ask Allaah to keep us safe and sound. Wishing for death is seeking something which is unknown. Perhaps if he wishes for death because of some hardship that he has fallen into, he may end up like one who jumps out of the frying pan and into the fire, and after death he may find himself in an even worse situation. In that case, wishing for death is akin to seeking to hasten calamity before it happens. No wise man should do that, as the Prophet (peace and blessings of Allaah be upon him) said: “Do not wish to meet the enemy, and ask Allaah to keep you safe and sound.” (Agreed upon). (Source: islamqa #46592)
However it is allowed to wish for death in:
the case of a trial in his faith as quoted in the qur'an as the words of Mariam ():
And the pains of childbirth drove her to the trunk of a palm tree. She said, "Oh, I wish I had died before this and was in oblivion, forgotten." (19:23)
Ibn Kathir commented this verse saying:
(She said: "Would that I had died before this, and had been forgotten and out of sight!'') In this is an evidence of the permissibility to wish for death when a calamity strikes. She knew that she was going to be tested with the birth, the people would not assist her, and they would not believe her story. After she was known as a devout worshipper among them, they now thought that she had become a fornicating whore. (Source: qtafsir)
Another evidence for that is the du'a:
"O Allah, I askYou for good actions and for leaving what is disapproved of and for love of the poor. And if You wish to try people, then bring me to You without being tried." (See here in al-Muwatta' and a longer version in Jami' at-Tirmidhi)
And the du'a mentioned above (3rd hadith) certainly can be used as an evidence here.
When (true) reasons for martyrdom are given. An evidence for that is this part of a long hadith:
and the Messenger of Allah (ﷺ) said. Get up to enter Paradise which is equal in width to the heavens and the earth. 'Umair b. al- Humam al-Ansari said: Messenger of Allah, is Paradise equal in extent to the heavens and the earth? He said: Yes. 'Umair said: My goodness! The Messenger of Allah (ﷺ) asked him: What prompted you to utter these words (i. e. my goodness! ')? He said: Messenger of Allah, nothing but the desire that I be among its residents. He said: Thou art (surely) amona its residents. He took out dates from his bag and began to eat them. Then he said: If I were to live until I have eaten all these dates of mine, it would be a long life. (The narrator said): He threw away all the dates he had with him. Then he fought the enemies until he was killed. (Sahih Muslim)
When the servant has certitude about his good deeds and longs to see His Lord, as in the qur'an we may find good people saying:
My Lord, You have given me [something] of sovereignty and taught me of the interpretation of dreams. Creator of the heavens and earth, You are my protector in this world and in the Hereafter. Cause me to die a Muslim and join me with the righteous." (12:101)
… "My Lord, enable me to be grateful for Your favor which You have bestowed upon me and upon my parents and to do righteousness of which You approve. And admit me by Your mercy into [the ranks of] Your righteous servants." (27:19)
On the other hand the Allah dares and speaks about the wrongdoers and disbelievers saying:
Say, [O Muhammad], "If the home of the Hereafter with Allah is for you alone and not the [other] people, then wish for death, if you should be truthful. (2:94)
Say, "O you who are Jews, if you claim that you are allies of Allah , excluding the [other] people, then wish for death, if you should be truthful." (62:6)
But they will not wish for it, ever, because of what their hands have put forth. And Allah is Knowing of the wrongdoers. (62:7)
For this reason you may find books filled with stories of believers and good people who wanted to die among them Sahabah like abu ad-Dardaa' and Hudayfah etc.
Imam an-Nasa-i presented in his Sunan two versions of a hadith containing this du'a:
اللَّهُمَّ بِعِلْمِكَ الْغَيْبَ وَقُدْرَتِكَ عَلَى الْخَلْقِ أَحْيِنِي مَا عَلِمْتَ الْحَيَاةَ خَيْرًا لِي وَتَوَفَّنِي إِذَا عَلِمْتَ الْوَفَاةَ خَيْرًا لِي اللَّهُمَّ وَأَسْأَلُكَ خَشْيَتَكَ فِي الْغَيْبِ وَالشَّهَادَةِ وَأَسْأَلُكَ كَلِمَةَ الْحَقِّ فِي الرِّضَا وَالْغَضَبِ وَأَسْأَلُكَ الْقَصْدَ فِي الْفَقْرِ وَالْغِنَى وَأَسْأَلُكَ نَعِيمًا لاَ يَنْفَدُ وَأَسْأَلُكَ قُرَّةَ عَيْنٍ لاَ تَنْقَطِعُ وَأَسْأَلُكَ الرِّضَاءَ بَعْدَ الْقَضَاءِ وَأَسْأَلُكَ بَرْدَ الْعَيْشِ بَعْدَ الْمَوْتِ وَأَسْأَلُكَ لَذَّةَ النَّظَرِ إِلَى وَجْهِكَ وَالشَّوْقَ إِلَى لِقَائِكَ فِي غَيْرِ ضَرَّاءَ مُضِرَّةٍ وَلاَ فِتْنَةٍ مُضِلَّةٍ اللَّهُمَّ زَيِّنَّا بِزِينَةِ الإِيمَانِ وَاجْعَلْنَا هُدَاةً مُهْتَدِينَ
"Allahumma bi 'ilmikal-ghaiba wa qudratika 'alal-khalqi ahyini ma 'alimtal-hayata khairan li, wa tawaffani idha 'alimtal-wafata khairan li. Allahumma as'aluka khashyataka fil-ghaibi wash-shahadati wa as'aluka kalimatul-aqua fir-rida'i wal ghadab, wa as'alukal-qasda fil faqr wal-ghina, wa as'aluka na'iman la yanfadu wa as'aluka qurrata ainan la tanqati'u wa as'alukar-rida'i ba'dal-qada'i wa as'aluka bardal 'aishi ba'dal-mawti, wa as'aluka ladhatan-nazari ila wajhika wash-shawqa ila liqa'ika fi fitnatin mudillatin, Allahumma zayyina dizinatil-imani waj'alna hudatan muhtadin
(O Allah, by Your knowledge of the unseen and Your power over creation, keep me alive so long as You know that living is good for me and cause me to die when You know that death is better for me. O Allah, cause me to fear You in secret and in public. I ask You to make me true in speech in times of pleasure and of anger. I ask You to make me moderate in times of wealth and poverty. And I ask You for everlasting delight and joy that will never cease. I ask You to make me pleased with that which You have decreed and for an easy life after death. I ask You for the sweetness of looking upon Your face and a longing to meet You in a manner that does not entail a calamity that will bring about harm or a trial that will cause deviation. O Allah, beautify us with the adornment of faith and make us among those who guide and are rightly guided."
(Sunan an-Nasa-i 1 & 2)
See also this article -in Arabic- on alukah.net.