You're right up to a point: When God doesn't answer our prayers the way we want Him to, our reaction often shows just how strong (or weak) our faith is.
But this doesn't necessarily mean this was the reason why God didn't answer a prayer. Yes, at times He may be testing our faith -- but this isn't His main reason for not answering our prayers. His main reason is that He loves us and knows what's best for us -- far better than we do ourselves. And often what we think is best for us isn't really best -- and God says "No" to our prayer.
Remember: When we know Christ, we know our prayers are heard, because even now Christ sits at the Father's right hand in heaven to intercede for us. The Bible says, "Let us then approach the throne of grace with confidence, so that we may receive mercy and find grace to help us in our time of need" (Hebrews 4:16).
True prayer involves trust -- trust that God's ways are better than ours, even if we can't see it at the time. Ask God to give you this kind of trust.