Extract MiniTest detection logic into a couple of methods.

Also make them a bit more rigorous.

Similar logic is used elsewhere and I plan to move these methods into a new
shared module.