A horse will test you as long as you let them. Once they figure out they can get away with it, they will continue to up the ante.
I have a lot of dead to rights broke horses, but even they will try on occasion to get away with going to the gate or refusing to work with a rider that they think they can slip one by. Jana is notorious for it, I also love her for it, she presents a challenge in a safe way to beginner students. Once they get assertive, she's like, "Oh, okay, you can be boss now."
For me, any rude or "testing" type behavior is dealt with swiftly. I have a very low tolerance for disrespectful horses. I'll ask once, if they don't respond, then they get told.