God had abandoned Saul, rejecting him from being king over Israel (1 Sam. 15:23). Immediately thereafter God sent Samuel to contact a youth, David, who was perhaps only fifteen years old. This shows that while Saul was usurping and even abusing the God-given kingship in order to build up his own monarchy, God was aware of the situation and was doing something marvelous to prepare the right person. God went secretly to David, the great grandson of Boaz and Ruth (Ruth 4:21-22).
David was created and prepared by God to be a man according to the heart of God (1 Sam. 13:14a). Otherwise, he could not have been such a man. However, as shown in chs. 16—17, he still needed to pass through the process of being chosen, trained, anointed, tested, and approved. David was thirty years old when he began to reign (2 Sam. 5:4). After David was anointed by Samuel, he was tested for about fifteen years. In particular, he was bothered and troubled by Saul. Eventually, David passed the test and was approved by God.