The bible says in Jeremiah 17:10 that;
I, the LORD, search the heart, I test the mind, Even to give every man according to his ways, According to the fruit of his doings
The Lord tests us to give us what we deserve according to our ways.
He also does so to keep us in check and lets us know that HE knows us better than we do our own selves, Job 23:10;
But He knows the way that I take; When He has tested me, I shall come forth as gold.
All the tests are HIS glory, 1 Peter 1:7;
that the genuineness of your faith, being much more precious than gold that perishes, though it is tested by fire, may be found to praise, honor, and glory at the revelation of Jesus Christ,
And finally to keep us humble and humane, 2 Corinthians 12:7-10;
or because of these surpassingly great revelations. Therefore, in order to keep me from becoming conceited, I was given a thorn in my flesh, a messenger of Satan, to torment me. Three times I pleaded with the Lord to take it away from me. But he said to me, “My grace is sufficient for you, for my power is made perfect in weakness.” Therefore I will boast all the more gladly about my weaknesses, so that Christ’s power may rest on me. That is why, for Christ’s sake, I delight in weaknesses, in insults, in hardships, in persecutions, in difficulties. For when I am weak, then I am strong.
All this because HE loves you so much, HE doesn’t want your inner evil to destroy you but for you to keep your eyes on HIM and HIM alone no matter.