“God knows the person whom He is testing and is confident that the outcome will be for the good.
As a certain Midrash teaches: just as the potter knocks on the newly completed vessel to ascertain if it is sound, so does God knock on a man.
A potter will refrain from knocking on an obviously cracked vessel, it would only break.
He tests the pots that are whole”
From The Candle of God, p. 204 by Rabbi Adin Steinsaltz