diff --git a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/system/ApplicationHome.java b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/system/ApplicationHome.java index 0e70dee354..05e3e5ddea 100644 --- a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/system/ApplicationHome.java +++ b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/system/ApplicationHome.java @@ -105,7 +105,9 @@ public class ApplicationHome { private boolean isUnitTest() { try { - for (StackTraceElement element : Thread.currentThread().getStackTrace()) { + StackTraceElement[] stackTrace = Thread.currentThread().getStackTrace(); + for (int i = stackTrace.length - 1; i >= 0; i--) { + StackTraceElement element = stackTrace[i]; if (element.getClassName().startsWith("org.junit.")) { return true; }