In my code I need to do certain fixes only when it is run inside a JUnit test. How can I find out if code is running inside a JUnit test or not? Is there something like JUni
I can find a justification for this, which is when you want to provide code in a production class to help testing. This would be similar to the Java assert, which only applies when the debug flag is set.
Something like this:
Object debugState() {
// This is only meant to be called when testing
if (!JUnit.isRunning()) {
throw new IllegalStateException("Not in a test!");
}
// Now compute possibly costly debug information
// not to be used in production
Object state = ...
}