Prefer God in Lived-Out Reality

The Bible tells us that God knows the hearts of all men and that he even fashioned them himself (1 Kings 8:39; Acts 1:24; Psalm 33:15). But then why are there tests, like in Abraham's case in Genesis 22:1-2? If God knew Abraham's heart and what he would do, what was the point in having him climb the mountain and lay Isaac on the altar?

John Piper writes:

God wills to know the actual, lived-out reality of our preference for him over all things. And he wills that we have the testimony of our authenticity through acts of actual preference of God over his gifts.

Lewis is right that God may as well not have created the world, but only imagined it, if his knowing what "would be" is as good as his knowing it in the very act [The Problem of Pain, 101-102].

God wills that he have an experiential-knowing, an actual seeing-knowing, a watching-knowing. A real lived-out human act of preference for God over his gifts is the actual lived-out glorification of God's excellence for which he created the world.

A Hunger for God: Desiring God Through Fasting and Prayer, (Wheaton: Crossway, 1997), 18.