Joshua 3:4 And they were to prove Israel by them, to know whether they would hearken unto the commandments of the Lord, which he commanded their fathers by the hand of Moses.
Chapter 3:1 says, “These are the nations which the Lord left, to prove Israel by them.” Here in verse 4, a reason is given why some of the pagan peoples were not driven out of the land. God left them there as thorns in the side to prove (test) His people, to find out whether they would hearken (listen and obey) the Lord, or not. Their response under pressure would reveal the faithfulness or unbelief of the people.
The finding out was not for God to know the heart (He already knows), but to reveal to the people whether they would hearken. They would see themselves. Jesus has forgiven us and delivered us from evil, but God has allowed the devil, the world, and our sinful flesh to remain in order to prove our faith.
In this way we can view the trials, tribulations, tests, and temptations in our own lives. God uses them to strengthen our faith. We see what is in our heart during hard times, miseries, difficulties, oppressions, and such. In the depths we cry out to the Lord and He delivers. In peaceful times we can become complacent and forgetful. Through the pains and problems of living on earth the Lord is asking: Are you still trusting Me? We turn and return to the Lord every day.