Mechanically, Zone of Truth can be defeated only by high-level features
As you say, any attempt to resist or evade the effects of Zone of Truth alerts the caster. And in the context of a loyalty test, avoiding the effect is synonymous with admitting disloyalty. The only exceptions to this are a handful of high-level features: the Mastermind Rogue's Soul of Deceit feature (as mentioned in Louis Wasserman's answer) defeats truth-detection magic, and the 8th level spell Glibness provides a similar ability:
[...] no matter what you say, magic that would determine if you are telling the truth indicates that you are being truthful.
Note that while Glibness causes Zone of Truth to read whatever you say as truthful, it doesn't necessarily protect you from being forced to tell the truth. If you intend to use it, you should ask your DM ahead of time how it will work with Zone of Truth to avoid arguments when it actually happens. (In contrast, Soul of Deceit explicitly says you can't be forced to tell the truth by magic, so there is no ambiguity there.)
In any case, unless you have access to features or spells available around 15th-17th level, you'll have to make it through your loyalty test by telling what your character believes to be the truth.
Believe your lies
However, there is at least one small and difficult-to-exploit loophole that doesn't require any powerful abilities: Zone of Truth only prevents a creature from speaking a deliberate lie. If you can manage to believe your lies, you will be able to speak those lies while under the effect of Zone of Truth. For example, if the loyalty question is something like "Are you loyal to the Empire?", then you would be able to answer with a simple "yes" even if you were plotting to assassinate the emperor, as long as you truly and honestly believed that doing so would help the Empire. Obviously, this is a very situational workaround, but I want to emphasize that this is materially different from being evasive or "lying with the truth". This is a case where you give exactly the truthful answer that is expected of you, but for a completely different reason (while praying that you are never asked to elaborate on that reason).
In practice, when you as a player attempt to use this, you should probably expect some push-back from your DM, asking if your character really believes this. This "loophole" has a heavy character focus rather than a mechanical focus, so if you are planning to do this, be prepared with a solidly fleshed-out backstory to justify your honesty. And of course, be willing to accept that a slightly different question might reveal that your interpretation of loyalty differs from that of your interrogators. In the above example, you would not fare well if you were instead asked "Are you loyal to the emperor?"
Unfortunately, I don't have any experience to share of using this "loophole" in an actual game. I'm just pointing out that it's the only loophole I can think of.