There are many ways to answer this question from scripture, but in the letter to Smyrna Jesus said it is so that we may be tested. He allowed each of his Apostles, with the exception of John, to be executed by his enemies. Church tradition says John was sentenced to death by boiling in oil, but miraculously survived it. He was exiled to Patmos when he could not be killed.
The Lord tested Abraham in the matter of offering Isaac. He tested Isaac in the matter of getting a wife. He tested Jacob when His angel wrestled with him through the night hours, dislocating his hip. Moses was tested when the Lord said he would kill the Israelites and start over with him. The Israelites were tested in the desert with hunger, thirst, and Pharaoh’s army. Ruth was tested by extreme poverty. Gideon was tested by an invading force so large it could not be counted. David was tested by his long years waiting in exile after he was anointed to be king. Solomon was tested by wealth. Elijah was tested by Jezebel’s wrath after he killed all the prophets of Baal. Elisha was tested by his master’s attempts to separate from him when it was time for his ascension. Esther was tested by the likelihood of death if she went before the king to challenge his decree. Ezekiel was tested by his long confinement with only a little bread to eat, baked in dung.
Shall I go on? Isaiah was stuffed into a hollow log and sawn in half. Jeremiah was thrown into a cistern, rescued, and carried against his will into Egypt only to be killed there by Jews. Daniel was cast into the lion’s den. Paul was blinded by Jesus on the road to Damascus, flogged, shipwrecked, stoned, jailed, and executed. When he recounts his vision of the third heaven, he was likely dead; the believers prayed over him and he revived.
Nebuchadnezzar threw Shadrach, Meshach, and Abednego into the fiery furnace, but Jesus was with them and the fire did them no harm. In this story, the test was whether they would bow and worship the king as a god, or worship only YHWH.
All the faithful are tested, so that the unsaved cannot point to us at the judgement and say the Lord shows favoritism. The word for “test” in Hebrew means the same thing as testing metal for purity, by fire. Paul wrote:
…you are God’s building. 10 According to the grace of God which was given to me, as a wise master builder I have laid the foundation, and another builds on it. But let each one take heed how he builds on it. 11 For no other foundation can anyone lay than that which is laid, which is Jesus Christ. 12 Now if anyone builds on this foundation with gold, silver, precious stones, wood, hay, straw, 13 each one’s work will become clear; for the Day will declare it, because it will be revealed by fire; and the fire will test each one’s work, of what sort it is. 14 If anyone’s work which he has built on it endures, he will receive a reward. 15 If anyone’s work is burned, he will suffer loss; but he himself will be saved, yet so as through fire.
1 Corinthians 3:9-13
There is no favoritism with the Lord; all are born of water, tested in fire, and judged. We either pass through the fire of the Holy Spirit, or enter the fires of hell. I was judged and died in Christ upon his cross, and am raised again to life in Him, but all my words and works will be tested by fire.
I indeed baptize you with water unto repentance, but He who is coming after me is mightier than I, whose sandals I am not worthy to carry. He will baptize you with the Holy Spirit and fire.