One wonders why YHWH "tested" Avraham in Genesis 22 when He commanded him to "sacrifice" Isaac. Well, the answer can actually be found as far back as Genesis 15, where we see our first Patriarch complaining to YHWH that he had no heirs to pass an inheritance on to - and YHWH TOLD him he would one day have a child of his own. But neither Avraham nor Sarah believed it! Take a look:
Genesis 15: 1 Some time later the word of ADONAI came to Avram in a vision: "Don't be afraid, Avram. I am your protector; your reward will be very great." 2 Avram replied, "ADONAI, God, what good will your gifts be to me if I continue childless; and Eli'ezer from Dammesek inherits my possessions? 3 You haven't given me a child," Avram continued, "so someone born in my house will be my heir."
4 But the word of ADONAI came to him: "This man will not be your heir. No, your heir will be a child from your own body." 5 Then he brought him outside and said, "Look up at the sky, and count the stars - if you can count them! Your descendants will be that many!" 6 He believed in ADONAI, and he credited it to him as righteousness. (CJB)
Did you notice verse 4? Hello! The typical human reaction! "Naaaah! Surely we can't get pregnant at our age!" And so in Genesis 16 we see Abraham and his wife Sarah panicking about not having an heir yet, and (at the urging of Sarah) they took matters into their own hands to have Avraham sleep with his wife's pagan/Egyptian servant Hagar, the result of which was a son they named Ishmael (who was the forefather of today's Arab nations, most of which are Muslim...).
But YHWH, filled with patience, grace and mercy, continued to work in Avraham, constantly revealing that He could and should be trusted. And then one day, He "tested" Avraham - for the purpose of showing Avraham just how much he (Avraham) had grown when it came to his belief in God. This "testing" resulted in Avraham being so trusting of, and dependent on YHWH in ALL things, that he was even willing to kill his own son! If YHWH commanded it, the Avraham was DOING it - no questions asked!
THAT is how YHWH wants us all to be!