Commit 4fe5e9e3 authored by Phillip Webb's avatar Phillip Webb

Remove direct junit-platform-launcher dependency

Replace any direct `junit-platform-launcher` dependencies and instead
rely on the test runner providing it. Launcher related class are not
handled via reflection.

This update allows us to workaround SUREFIRE-1679.

Closes gh-17517
parent 543fcdbb
...@@ -218,7 +218,6 @@ ...@@ -218,7 +218,6 @@
<artifactId>spring-security-test</artifactId> <artifactId>spring-security-test</artifactId>
<optional>true</optional> <optional>true</optional>
</dependency> </dependency>
<!-- Test --> <!-- Test -->
<dependency> <dependency>
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
...@@ -327,11 +326,6 @@ ...@@ -327,11 +326,6 @@
</exclusion> </exclusion>
</exclusions> </exclusions>
</dependency> </dependency>
<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-launcher</artifactId>
<scope>test</scope>
</dependency>
<dependency> <dependency>
<groupId>org.mongodb</groupId> <groupId>org.mongodb</groupId>
<artifactId>mongodb-driver-async</artifactId> <artifactId>mongodb-driver-async</artifactId>
......
...@@ -21,11 +21,6 @@ import java.lang.annotation.RetentionPolicy; ...@@ -21,11 +21,6 @@ import java.lang.annotation.RetentionPolicy;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.junit.platform.engine.discovery.DiscoverySelectors; import org.junit.platform.engine.discovery.DiscoverySelectors;
import org.junit.platform.launcher.Launcher;
import org.junit.platform.launcher.LauncherDiscoveryRequest;
import org.junit.platform.launcher.core.LauncherDiscoveryRequestBuilder;
import org.junit.platform.launcher.core.LauncherFactory;
import org.junit.runners.model.InitializationError;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.AutoConfigurationPackage; import org.springframework.boot.autoconfigure.AutoConfigurationPackage;
...@@ -33,6 +28,9 @@ import org.springframework.boot.autoconfigure.ImportAutoConfiguration; ...@@ -33,6 +28,9 @@ import org.springframework.boot.autoconfigure.ImportAutoConfiguration;
import org.springframework.boot.autoconfigure.domain.EntityScan; import org.springframework.boot.autoconfigure.domain.EntityScan;
import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest; import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest;
import org.springframework.boot.test.autoconfigure.orm.jpa.ExampleEntity; import org.springframework.boot.test.autoconfigure.orm.jpa.ExampleEntity;
import org.springframework.boot.testsupport.junit.platform.Launcher;
import org.springframework.boot.testsupport.junit.platform.LauncherDiscoveryRequest;
import org.springframework.boot.testsupport.junit.platform.LauncherDiscoveryRequestBuilder;
import org.springframework.context.ApplicationContext; import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.ContextConfiguration;
...@@ -51,7 +49,7 @@ class ImportsContextCustomizerFactoryWithAutoConfigurationTests { ...@@ -51,7 +49,7 @@ class ImportsContextCustomizerFactoryWithAutoConfigurationTests {
static ApplicationContext contextFromTest; static ApplicationContext contextFromTest;
@Test @Test
void testClassesThatHaveSameAnnotationsShareAContext() throws InitializationError { void testClassesThatHaveSameAnnotationsShareAContext() throws Throwable {
executeTests(DataJpaTest1.class); executeTests(DataJpaTest1.class);
ApplicationContext test1Context = contextFromTest; ApplicationContext test1Context = contextFromTest;
executeTests(DataJpaTest3.class); executeTests(DataJpaTest3.class);
...@@ -60,7 +58,7 @@ class ImportsContextCustomizerFactoryWithAutoConfigurationTests { ...@@ -60,7 +58,7 @@ class ImportsContextCustomizerFactoryWithAutoConfigurationTests {
} }
@Test @Test
void testClassesThatOnlyHaveDifferingUnrelatedAnnotationsShareAContext() throws InitializationError { void testClassesThatOnlyHaveDifferingUnrelatedAnnotationsShareAContext() throws Throwable {
executeTests(DataJpaTest1.class); executeTests(DataJpaTest1.class);
ApplicationContext test1Context = contextFromTest; ApplicationContext test1Context = contextFromTest;
executeTests(DataJpaTest2.class); executeTests(DataJpaTest2.class);
...@@ -69,8 +67,7 @@ class ImportsContextCustomizerFactoryWithAutoConfigurationTests { ...@@ -69,8 +67,7 @@ class ImportsContextCustomizerFactoryWithAutoConfigurationTests {
} }
@Test @Test
void testClassesThatOnlyHaveDifferingPropertyMappedAnnotationAttributesDoNotShareAContext() void testClassesThatOnlyHaveDifferingPropertyMappedAnnotationAttributesDoNotShareAContext() throws Throwable {
throws InitializationError {
executeTests(DataJpaTest1.class); executeTests(DataJpaTest1.class);
ApplicationContext test1Context = contextFromTest; ApplicationContext test1Context = contextFromTest;
executeTests(DataJpaTest4.class); executeTests(DataJpaTest4.class);
...@@ -78,10 +75,11 @@ class ImportsContextCustomizerFactoryWithAutoConfigurationTests { ...@@ -78,10 +75,11 @@ class ImportsContextCustomizerFactoryWithAutoConfigurationTests {
assertThat(test1Context).isNotSameAs(test2Context); assertThat(test1Context).isNotSameAs(test2Context);
} }
private void executeTests(Class<?> testClass) { private void executeTests(Class<?> testClass) throws Throwable {
LauncherDiscoveryRequest request = LauncherDiscoveryRequestBuilder.request() ClassLoader classLoader = testClass.getClassLoader();
LauncherDiscoveryRequest request = new LauncherDiscoveryRequestBuilder(classLoader)
.selectors(DiscoverySelectors.selectClass(testClass)).build(); .selectors(DiscoverySelectors.selectClass(testClass)).build();
Launcher launcher = LauncherFactory.create(); Launcher launcher = new Launcher(testClass.getClassLoader());
launcher.execute(request); launcher.execute(request);
} }
......
...@@ -19,16 +19,15 @@ package org.springframework.boot.test.autoconfigure.web.servlet.mockmvc; ...@@ -19,16 +19,15 @@ package org.springframework.boot.test.autoconfigure.web.servlet.mockmvc;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith; import org.junit.jupiter.api.extension.ExtendWith;
import org.junit.platform.engine.discovery.DiscoverySelectors; import org.junit.platform.engine.discovery.DiscoverySelectors;
import org.junit.platform.launcher.Launcher;
import org.junit.platform.launcher.LauncherDiscoveryRequest;
import org.junit.platform.launcher.core.LauncherDiscoveryRequestBuilder;
import org.junit.platform.launcher.core.LauncherFactory;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
import org.springframework.boot.test.system.CapturedOutput; import org.springframework.boot.test.system.CapturedOutput;
import org.springframework.boot.test.system.OutputCaptureExtension; import org.springframework.boot.test.system.OutputCaptureExtension;
import org.springframework.boot.testsupport.junit.platform.Launcher;
import org.springframework.boot.testsupport.junit.platform.LauncherDiscoveryRequest;
import org.springframework.boot.testsupport.junit.platform.LauncherDiscoveryRequestBuilder;
import org.springframework.security.test.context.support.WithMockUser; import org.springframework.security.test.context.support.WithMockUser;
import org.springframework.test.web.servlet.MockMvc; import org.springframework.test.web.servlet.MockMvc;
...@@ -47,21 +46,22 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers. ...@@ -47,21 +46,22 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.
class WebMvcTestPrintDefaultIntegrationTests { class WebMvcTestPrintDefaultIntegrationTests {
@Test @Test
void shouldNotPrint(CapturedOutput output) { void shouldNotPrint(CapturedOutput output) throws Throwable {
executeTests(ShouldNotPrint.class); executeTests(ShouldNotPrint.class);
assertThat(output).doesNotContain("HTTP Method"); assertThat(output).doesNotContain("HTTP Method");
} }
@Test @Test
void shouldPrint(CapturedOutput output) { void shouldPrint(CapturedOutput output) throws Throwable {
executeTests(ShouldPrint.class); executeTests(ShouldPrint.class);
assertThat(output).contains("HTTP Method"); assertThat(output).contains("HTTP Method");
} }
private void executeTests(Class<?> testClass) { private void executeTests(Class<?> testClass) throws Throwable {
LauncherDiscoveryRequest request = LauncherDiscoveryRequestBuilder.request() ClassLoader classLoader = testClass.getClassLoader();
LauncherDiscoveryRequest request = new LauncherDiscoveryRequestBuilder(classLoader)
.selectors(DiscoverySelectors.selectClass(testClass)).build(); .selectors(DiscoverySelectors.selectClass(testClass)).build();
Launcher launcher = LauncherFactory.create(); Launcher launcher = new Launcher(testClass.getClassLoader());
launcher.execute(request); launcher.execute(request);
} }
......
...@@ -66,14 +66,6 @@ ...@@ -66,14 +66,6 @@
<artifactId>jakarta.servlet-api</artifactId> <artifactId>jakarta.servlet-api</artifactId>
<optional>true</optional> <optional>true</optional>
</dependency> </dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
</dependency>
<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-launcher</artifactId>
</dependency>
<dependency> <dependency>
<groupId>org.mockito</groupId> <groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId> <artifactId>mockito-core</artifactId>
...@@ -130,6 +122,11 @@ ...@@ -130,6 +122,11 @@
</exclusion> </exclusion>
</exclusions> </exclusions>
</dependency> </dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<scope>provided</scope>
</dependency>
<!-- Test --> <!-- Test -->
<dependency> <dependency>
<groupId>org.hibernate.validator</groupId> <groupId>org.hibernate.validator</groupId>
......
/*
* Copyright 2012-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.boot.testsupport.junit.platform;
import java.lang.reflect.Array;
/**
* Reflective mirror of JUnit 5's {@code Launcher}.
*
* @author Phillip Webb
* @since 2.2.0
*/
public class Launcher extends ReflectiveWrapper {
private final Class<?> testExecutionListenerType;
private final Object instance;
public Launcher(ClassLoader classLoader) throws Throwable {
super(classLoader, "org.junit.platform.launcher.Launcher");
this.testExecutionListenerType = loadClass("org.junit.platform.launcher.TestExecutionListener");
Class<?> factoryClass = loadClass("org.junit.platform.launcher.core.LauncherFactory");
this.instance = factoryClass.getMethod("create").invoke(null);
}
public TestPlan discover(LauncherDiscoveryRequest request) throws Throwable {
return new TestPlan(getClassLoader(),
this.type.getMethod("discover", request.type).invoke(this.instance, request.instance));
}
public void registerTestExecutionListeners(SummaryGeneratingListener listener) throws Throwable {
Object listeners = Array.newInstance(this.testExecutionListenerType, 1);
Array.set(listeners, 0, listener.instance);
this.type.getMethod("registerTestExecutionListeners", listeners.getClass()).invoke(this.instance, listeners);
}
public void execute(LauncherDiscoveryRequest request) throws Throwable {
Object listeners = Array.newInstance(this.testExecutionListenerType, 0);
this.type.getMethod("execute", request.type, listeners.getClass()).invoke(this.instance, request.instance,
listeners);
}
}
/*
* Copyright 2012-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.boot.testsupport.junit.platform;
/**
* Reflective mirror of JUnit 5's {@code LauncherDiscoveryRequest}.
*
* @author Phillip Webb
* @since 2.2.0
*/
public class LauncherDiscoveryRequest extends ReflectiveWrapper {
final Object instance;
LauncherDiscoveryRequest(ClassLoader classLoader, Object instance) throws Throwable {
super(classLoader, "org.junit.platform.launcher.LauncherDiscoveryRequest");
this.instance = instance;
}
}
/*
* Copyright 2012-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.boot.testsupport.junit.platform;
import java.lang.reflect.Method;
import org.junit.platform.engine.DiscoverySelector;
/**
* Reflective mirror of JUnit 5's {@code LauncherDiscoveryRequestBuilder}.
*
* @author Phillip Webb
* @since 2.2.0
*/
public class LauncherDiscoveryRequestBuilder extends ReflectiveWrapper {
final Object instance;
public LauncherDiscoveryRequestBuilder(ClassLoader classLoader) throws Throwable {
super(classLoader, "org.junit.platform.launcher.core.LauncherDiscoveryRequestBuilder");
this.instance = this.type.getMethod("request").invoke(null);
}
LauncherDiscoveryRequestBuilder(ClassLoader classLoader, Class<?> type, Object instance) throws Throwable {
super(classLoader, type);
this.instance = instance;
}
public LauncherDiscoveryRequestBuilder selectors(DiscoverySelector... selectors) throws Throwable {
Class<?>[] parameterTypes = { DiscoverySelector[].class };
Method method = this.type.getMethod("selectors", parameterTypes);
return new LauncherDiscoveryRequestBuilder(getClassLoader(), this.type,
method.invoke(this.instance, new Object[] { selectors }));
}
public LauncherDiscoveryRequest build() throws Throwable {
return new LauncherDiscoveryRequest(getClassLoader(), this.type.getMethod("build").invoke(this.instance));
}
}
/*
* Copyright 2012-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.boot.testsupport.junit.platform;
import org.springframework.util.ClassUtils;
/**
* Base class for all reflective wrappers.
*
* @author Phillip Webb
*/
class ReflectiveWrapper {
final ClassLoader classLoader;
final Class<?> type;
ReflectiveWrapper(ClassLoader classLoader, String type) throws Throwable {
this.classLoader = classLoader;
this.type = loadClass(type);
}
protected ReflectiveWrapper(ClassLoader classLoader, Class<?> type) throws Throwable {
this.classLoader = classLoader;
this.type = type;
}
protected final ClassLoader getClassLoader() {
return this.classLoader;
}
protected final Class<?> loadClass(String type) throws ClassNotFoundException, LinkageError {
return ClassUtils.forName(type, this.classLoader);
}
}
/*
* Copyright 2012-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.boot.testsupport.junit.platform;
/**
* Reflective mirror of JUnit 5's {@code SummaryGeneratingListener}.
*
* @author Phillip Webb
* @since 2.2.0
*/
public class SummaryGeneratingListener extends ReflectiveWrapper {
final Object instance;
public SummaryGeneratingListener(ClassLoader classLoader) throws Throwable {
super(classLoader, "org.junit.platform.launcher.listeners.SummaryGeneratingListener");
this.instance = this.type.newInstance();
}
public TestExecutionSummary getSummary() throws Throwable {
return new TestExecutionSummary(getClassLoader(), this.type.getMethod("getSummary").invoke(this.instance));
}
}
/*
* Copyright 2012-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.boot.testsupport.junit.platform;
import java.util.List;
import org.springframework.util.CollectionUtils;
/**
* Reflective mirror of JUnit 5's {@code TestExecutionSummary}.
*
* @author Phillip Webb
* @since 2.2.0
*/
public class TestExecutionSummary extends ReflectiveWrapper {
private final Class<?> failureType;
private final Object instance;
TestExecutionSummary(ClassLoader classLoader, Object instance) throws Throwable {
super(classLoader, "org.junit.platform.launcher.listeners.TestExecutionSummary");
this.failureType = loadClass("org.junit.platform.launcher.listeners.TestExecutionSummary$Failure");
this.instance = instance;
}
public Throwable getFailure() throws Throwable {
List<?> failures = (List<?>) this.type.getMethod("getFailures").invoke(this.instance);
if (!CollectionUtils.isEmpty(failures)) {
Object failure = failures.get(0);
return (Throwable) this.failureType.getMethod("getException").invoke(failure);
}
return null;
}
}
/*
* Copyright 2012-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.boot.testsupport.junit.platform;
/**
* Reflective mirror of JUnit 5's {@code TestPlan}.
*
* @author Phillip Webb
* @since 2.2.0
*/
public class TestPlan extends ReflectiveWrapper {
final Object instance;
TestPlan(ClassLoader classLoader, Object instance) throws Throwable {
super(classLoader, "org.junit.platform.launcher.TestPlan");
this.instance = instance;
}
}
/*
* Copyright 2012-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* Reflective mirror of JUnit 5 classes required to workaround shurefire bug
* {@code SUREFIRE-1679}.
*/
package org.springframework.boot.testsupport.junit.platform;
...@@ -26,15 +26,11 @@ import org.junit.jupiter.api.extension.ExtensionContext; ...@@ -26,15 +26,11 @@ import org.junit.jupiter.api.extension.ExtensionContext;
import org.junit.jupiter.api.extension.InvocationInterceptor; import org.junit.jupiter.api.extension.InvocationInterceptor;
import org.junit.jupiter.api.extension.ReflectiveInvocationContext; import org.junit.jupiter.api.extension.ReflectiveInvocationContext;
import org.junit.platform.engine.discovery.DiscoverySelectors; import org.junit.platform.engine.discovery.DiscoverySelectors;
import org.junit.platform.launcher.Launcher;
import org.junit.platform.launcher.LauncherDiscoveryRequest; import org.springframework.boot.testsupport.junit.platform.Launcher;
import org.junit.platform.launcher.TestPlan; import org.springframework.boot.testsupport.junit.platform.LauncherDiscoveryRequest;
import org.junit.platform.launcher.core.LauncherDiscoveryRequestBuilder; import org.springframework.boot.testsupport.junit.platform.LauncherDiscoveryRequestBuilder;
import org.junit.platform.launcher.core.LauncherFactory; import org.springframework.boot.testsupport.junit.platform.SummaryGeneratingListener;
import org.junit.platform.launcher.listeners.SummaryGeneratingListener;
import org.junit.platform.launcher.listeners.TestExecutionSummary;
import org.springframework.util.CollectionUtils;
import org.springframework.util.ReflectionUtils; import org.springframework.util.ReflectionUtils;
/** /**
...@@ -99,20 +95,19 @@ public class ModifiedClassPathExtension implements InvocationInterceptor { ...@@ -99,20 +95,19 @@ public class ModifiedClassPathExtension implements InvocationInterceptor {
} }
} }
private void runTest(URLClassLoader classLoader, String testClassName, String testMethodName) private void runTest(ClassLoader classLoader, String testClassName, String testMethodName)
throws ClassNotFoundException, Throwable { throws ClassNotFoundException, Throwable {
Class<?> testClass = classLoader.loadClass(testClassName); Class<?> testClass = classLoader.loadClass(testClassName);
Method testMethod = ReflectionUtils.findMethod(testClass, testMethodName); Method testMethod = ReflectionUtils.findMethod(testClass, testMethodName);
LauncherDiscoveryRequest request = LauncherDiscoveryRequestBuilder.request() LauncherDiscoveryRequest request = new LauncherDiscoveryRequestBuilder(classLoader)
.selectors(DiscoverySelectors.selectMethod(testClass, testMethod)).build(); .selectors(DiscoverySelectors.selectMethod(testClass, testMethod)).build();
Launcher launcher = LauncherFactory.create(); Launcher launcher = new Launcher(classLoader);
TestPlan testPlan = launcher.discover(request); SummaryGeneratingListener listener = new SummaryGeneratingListener(classLoader);
SummaryGeneratingListener listener = new SummaryGeneratingListener();
launcher.registerTestExecutionListeners(listener); launcher.registerTestExecutionListeners(listener);
launcher.execute(testPlan); launcher.execute(request);
TestExecutionSummary summary = listener.getSummary(); Throwable failure = listener.getSummary().getFailure();
if (!CollectionUtils.isEmpty(summary.getFailures())) { if (failure != null) {
throw summary.getFailures().get(0).getException(); throw failure;
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment