Yeah, a test is a terrible idea, for a ton of reasons. Courts would rightly strike it down.
Just set a simple age cap. You are ineligible for election if you will be 65 or older on the day of the election. Done. It's simple, it's predictable, there's no wiggle room, and we already have precedent for limiting representation by age.
Why is that a terrible idea? I'd extend that by mandatory drug testing like it is done for commercial pilots. Not as an absolute disqualifier, just not allowed to enter office for the duration of being 'under the influence', and no business allowed outside of the office :-)