There are some stories in our scriptures when Devtaa had tested the righteous kings. Some stories are very famous among them. Here are three such stories ---
There was a king named Ranti Dev. He was in the lineage of Chandra Vansh - Bharat -> .Bharadwaaj -> Manyu -> Nar -> Sankriti -> Rantidev. It was his principle that he did not take any money from his royal treasury for his own expenditure. he used only those things which he got without any labor. And since he did not touch anything that belonged to the kingdom, gradually his own capital was decreasing. Once it so happened that he could not get even water for drink for 48 days. His family was suffering because of this. On the 49th day he got some Ghee, Halavaa, Kheer and water in the morning.
Rantidev started distributing food among themselves, and wanted to eat it that a Braahman came and asked for some food. Rantidev saw Bhagvaan in everybody, so he gave some food to him and he went away after being satisfied. After he had left, Rantidev again sat for eating, that a Shoodra came to him and asked for some food. Rantidev gave some food to him too, and the Shoodra also left.
After the Shoodra had left, Rantidev again sat to eat that a man came with his dogs. He said - "Raajan, My dogs and I are very hungry, give us some food." The King gave the remaining food to him and bowed to Bhagvaan. Now only water remained with Rantidev. So he wanted to take that water that a Chaandaal came asked him to give some water to him. Rantidev gave that remaining water also to him. After he drank water all three, Brahmaa, Vishnu and Mahesh appeared before him and blessed him. They asked him to ask for a boon but he had no desire so everything just got disappeared and his people also got the same Gati as he got.
Raajaa Harishchandra was a Soorya Vanshee King. Once Indra asked in his court that whether there was any king who was the follower of Truth, on Prithvi? Vashishth Jee said - "Yes, There is one king. He is Harishchandra of Ayodhyaa." Vishwaamitra Jee was also sitting there, he opposed him and said - "No, He is not." Both got ready to test the King Harishchandra. Vishwaamitra said - "He cannot stick to truth, I will put him in such a condition that he will have to move from the truth. And if I could not move him, I will change my name."
So Vishwaamitra Jee went to him and asked the gold in donation. He gave it. Vishwaamitra Jee accepted it but left it with him and went away saying that whenever he would need it he would come and take it. Later he trapped him in such a way that he had to leave his kingdom. At that time he asked his gold. Harishchandra gave that kingdom to Vishwaamitra. Then he asked Dakshinaa. The King did not have anything with him so he sold his wife to a Braahman and himself to a Dom (cremation ground caretaker) and gave that money to him.
Now one day a snake bit the King's son Rohit. He died of its bite. His mother did not have any cloth to wrap the body, so she tore half of her Saaree, wrapped his body in it and brought him to the cremation ground, but Harishchandra would not allow her to burn the body without giving tax. She said - "I don't have anything to give you tax, you may take the other half piece of my Saaree as tax." Harishchandra got ready and as his wife started taking off her half Saaree, Vishnu, Indra, Vishwaamitra and vashishth Jee came there and blessed him. Read the whole story here.
Once the gods, Indra and Dharm Raaj, decided to test Raajaa Shivi for his compassionate nature. Once a living being came under his protection, he used to protect him even at the cost of his life. So one day Indra assumed the form of a pigeon and and Yam Raaj assumed the form of a hawk. The hawk started chasing the pigeon and the pigeon flying came to the King's court and fell in the laps of the King.
As soon as the King saw him, he protected him and when the hawk came to ask for his prey, he clearly refused to give him to the hawk. The King, instead, promised to give the hawk some other animal's flesh. First the hawk did not agree at this but when the King got agreed giving on his own flesh, he got agreed. Still the hawk put two conditions - that when the King will give his own flesh he will not shed any tear, and that his family should be there too. Shivi agreed. His family was called, a scale was brought and Shivi started keeping his flesh on the other side of the scale. He continued to keep his flesh, but still his flesh was not equal to weight of the hawk. At last he himself sat on the scale. As he sat on the scale, hawk and pigeon changed into Indra and Dharm Raaj and blessed him. Read the whole story here.