下面列出了怎么用org.junit.platform.engine.TestEngine的API类实例代码及写法,或者点击链接到github查看源代码。
@Test
void jvmOnlyInParentSpi() throws IOException {
final Predicate<String> parentClasses = name -> true;
try (final URLClassLoader parent =
new URLClassLoader(new URL[0], Thread.currentThread().getContextClassLoader());
final ConfigurableClassLoader loader = new ConfigurableClassLoader("test", new URL[0], parent,
parentClasses, parentClasses.negate(), new String[0], new String[] {
new File(System.getProperty("java.home")).toPath().toAbsolutePath().toString() })) {
// can be loaded cause in the JVM
assertTrue(ServiceLoader.load(FileSystemProvider.class, loader).iterator().hasNext());
// this is in the (test) classloader but not available to the classloader
final List<TestEngine> junitEngines = StreamSupport
.stream(ServiceLoader.load(TestEngine.class, loader).spliterator(), false)
.collect(toList());
assertTrue(junitEngines.isEmpty());
}
}