Why is God testing our faith if He is Omniscient?

Question:

God has tested His people through different sufferings to see if their faith will resist or not. Why? If God knows beforehand how we will react to every circumsatnce, He knows even the words we are going to say before they come out of our mouths, why does He do that?

It is true that God is omniscient, and He has no need for anybody to tell Him anything about us. He knows the past, the present and the future. The purpose of the trials that He allows in the lives of His children, is not only to know them, but to build their characters and to sanctify them, only when they are willing to cooperate through the process.

Count it all joy, my brothers, when you meet trials of various kinds, for you know that the testing of your faith produces steadfastness. And let steadfastness have its full effect, that you may be perfect and complete lacking in nothing.  (James 1: 2-4)

The word translasted here as “trials” is the Greek word PEIRASMOS,  and according to the context can be translated as either trial or temptation, the context being what dictates its translation. According to the text mentioned above, the purpose of trials is to produce steadfastness in the characters of those undergoing the trials, if they are ready and willing to endure them and receive them with joy. The same idea is mentioned in the letter to Romans: 

More than that, we rejoice in our sufferings, knowing that the suffering produces endurance, and endurance produces character, and character produces hope, and hope does not put us to shame, becasue God’s love has been poured into our hearts through the Holy Spirit who has been given to us.    (Romans 5: 3-5)

What trials have you been going through lately? In what way were they beneficial to you? If they did not produce anything good and did not work endurance, why? What can you do, in order to change this?