Tests can be unconscious attempts on her part to "rattle you" in order to see how you'd respond. Kind of like some hiker testing a bridge he's about to cross. Just like you'd hope the bridge is strong enough, she'll hope the dude is strong enough.
Guys can see right away if girls are satisfactory, from a DNA perspective, with girls, it ain't so easy. So they test us to see how strong we are. They are genetically programmed to do so, and in most cases don't really have any idea what they're doing.
In these cases, the best thing is to simply "out frame." Which means just let whatever happened roll off your back.
Put whatever behavior you think is disrespectful, or whatever, and the same behavior coming from a 5 y/o. Would you get mad if a 5 y/o dissed you?
The other kind of test is when she's how much she can get away with without crossing any boundaries. It's similar to the first kind, but it's different in that she's kind of trying to get something for nothing, either up front, or trying to push your buttons because she didn't get what she wanted.
Either way, ANY anger is counterproductive.
The BEST thing to do is just ignore it, and carry on with whatever you're doing.
Girls aren't put on earth to give you respect, or show you what an alpha boss you are, or stroke your ego, or make you look good.
Most problems with chicks stem from the fact that most dudes never really grow up to a reasonable level of maturity and self-responsibility. At least in some part, guys see girlfriends/wives as a replacement MOMMY on some level. MOMMY who is supposed to show him love, kindness and respect BECAUSE IT'S HER JOB. Because of who he is, and not how he behaves.
You're girl ain't MOMMY. She's just a normal chic who'd dump you if she could get something better if she wouldn't get into trouble.