If God is all knowing, doesn’t he already know whether we’re going to heaven or hell?

If god knows everything, doesn’t he already know exactly what every human will do in their lives, and therefore where we will spend eternity in the afterlife? Why does God test us, or even bother giving us life, if he knows exactly how we will spend it? Shouldn’t he already know the results of all of his tests?