Skip to content

Commit bbfbdcb

Browse files
committed
Disable tests that depend on compiled Groovy code in Eclipse
1 parent dff5133 commit bbfbdcb

File tree

2 files changed

+20
-4
lines changed

2 files changed

+20
-4
lines changed

junit-vintage-engine/src/test/java/org/junit/vintage/engine/JUnit4VersionCheckTests.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,4 +84,5 @@ void handlesMissingJUnit() {
8484
+ "an excludeEngines(\"junit-vintage\") filter.",
8585
exception.getMessage());
8686
}
87+
8788
}

junit-vintage-engine/src/test/java/org/junit/vintage/engine/VintageTestEngineExecutionTests.java

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@
4242
import org.assertj.core.api.Condition;
4343
import org.junit.AssumptionViolatedException;
4444
import org.junit.jupiter.api.Test;
45+
import org.junit.jupiter.api.condition.DisabledIf;
46+
import org.junit.platform.commons.util.ReflectionUtils;
4547
import org.junit.platform.engine.EngineExecutionListener;
4648
import org.junit.platform.engine.ExecutionRequest;
4749
import org.junit.platform.engine.TestDescriptor;
@@ -98,7 +100,6 @@
98100
import org.junit.vintage.engine.samples.junit4.PlainJUnit4TestCaseWithSingleTestWhichFails;
99101
import org.junit.vintage.engine.samples.junit4.PlainJUnit4TestCaseWithSingleTestWhichIsIgnored;
100102
import org.junit.vintage.engine.samples.junit4.PlainJUnit4TestCaseWithTwoTestMethods;
101-
import org.junit.vintage.engine.samples.spock.SpockTestCaseWithUnrolledAndRegularFeatureMethods;
102103
import org.opentest4j.MultipleFailuresError;
103104

104105
/**
@@ -862,13 +863,16 @@ void executesJUnit4TestCaseWithRunnerWithDuplicateChangingChildDescriptions() {
862863
}
863864

864865
@Test
866+
@DisabledIf("runningInEclipse")
865867
void executesUnrolledSpockFeatureMethod() {
866-
Class<?> testClass = SpockTestCaseWithUnrolledAndRegularFeatureMethods.class;
868+
// Load Groovy class via reflection to avoid compilation errors in Eclipse IDE.
869+
String testClassName = "org.junit.vintage.engine.samples.spock.SpockTestCaseWithUnrolledAndRegularFeatureMethods";
870+
Class<?> testClass = ReflectionUtils.loadRequiredClass(testClassName, getClass().getClassLoader());
867871
var request = LauncherDiscoveryRequestBuilder.request().selectors(
868872
selectMethod(testClass, "unrolled feature for #input")).build();
869873
execute(request).allEvents().assertEventsMatchExactly( //
870874
event(engine(), started()), //
871-
event(uniqueIdSubstring(testClass.getName()), started()), //
875+
event(uniqueIdSubstring(testClassName), started()), //
872876
event(dynamicTestRegistered("unrolled feature for 23")), //
873877
event(test("unrolled feature for 23"), started()), //
874878
event(test("unrolled feature for 23"), finishedWithFailure()), //
@@ -880,8 +884,11 @@ void executesUnrolledSpockFeatureMethod() {
880884
}
881885

882886
@Test
887+
@DisabledIf("runningInEclipse")
883888
void executesRegularSpockFeatureMethod() {
884-
Class<?> testClass = SpockTestCaseWithUnrolledAndRegularFeatureMethods.class;
889+
// Load Groovy class via reflection to avoid compilation errors in Eclipse IDE.
890+
String testClassName = "org.junit.vintage.engine.samples.spock.SpockTestCaseWithUnrolledAndRegularFeatureMethods";
891+
Class<?> testClass = ReflectionUtils.loadRequiredClass(testClassName, getClass().getClassLoader());
885892
var request = LauncherDiscoveryRequestBuilder.request().selectors(selectMethod(testClass, "regular")).build();
886893
execute(request).allEvents().assertEventsMatchExactly( //
887894
event(engine(), started()), //
@@ -938,4 +945,12 @@ private static boolean atLeastJUnit4_13() {
938945
return JUnit4VersionCheck.parseVersion(Version.id()).compareTo(new BigDecimal("4.13")) >= 0;
939946
}
940947

948+
/**
949+
* Determine if the current code is running in the Eclipse IDE.
950+
*/
951+
static boolean runningInEclipse() {
952+
return StackWalker.getInstance().walk(
953+
stream -> stream.anyMatch(stackFrame -> stackFrame.getClassName().startsWith("org.eclipse.jdt")));
954+
}
955+
941956
}

0 commit comments

Comments
 (0)