Detecting if code is running in test mode
Sometimes, we need to know if the code execution was started by a junitĀ test or it was normally started by the application.
boolean isInJunitTest(){
  for (StackTraceElement s : Thread.currentThread().getStackTrace()) {
    if (s.getClassName().contains("TestExecutionListener")) {
      return true;
    }
  }
  return false;
}
			