On the assumption of a shared earth (ie unmolested rear lamp unit) does the brake light work normally? If so, the earth is indeed ok.
When you checked the tail light with a battery, are you certain you checked the tail filament, and not the brake filament - assuming you’ve the standard double filament bulb (so sorry if stating the obvious!).
Sometimes the bulb connections can fail; emery / clean up the body earths and pin connections of both the bulb and bulb holder.
A continuity check using a meter may not give the full story, as it uses an extremely low current for this function. This low current will happily flow through furry / corroded connections … which may not subsequently carry the current needed to operate the tail lamp.
Does the bike have a front parking light (2nd position on the key) - and does this work? If yes & no, then perhaps a fault in the ignition switch?
From what you describe, the handlebar switch sounds ok on the assumption the headlight works, but spraying switch cleaner into its slot wouldn’t go amiss.
Before going too deep, perhaps look in the headlamp bowl, hoping to find a disconnected Brown wire? Good luck….