@SuppressWarnings("unused") public static void main(String[] args) { // Discover and filter tests LauncherDiscoveryRequest request = LauncherDiscoveryRequestBuilder .request() .selectors(selectPackage("io.github.bonigarcia"), selectClass(DummyTest.class)) .filters(includeClassNamePatterns(".*Test")).build(); Launcher launcher = LauncherFactory.create(); TestPlan plan = launcher.discover(request); // Executing tests TestExecutionListener listener = new SummaryGeneratingListener(); launcher.registerTestExecutionListeners(listener); launcher.execute(request, listener); }
public static void main(String[] args) throws Exception { try (SocketChannel channel = openSocket()) { TestExecutionListener listener = createListener(channel); Launcher launcher = LauncherFactory.create(); launcher.registerTestExecutionListeners(listener); ObjectInputStream inputStream = openInput(); Map<String, List<String>> config = (Map<String, List<String>>) inputStream.readObject(); Set<File> roots = config.get("classpathRoots").stream() .map(File::new) .collect(Collectors.toSet()); LauncherDiscoveryRequest request = LauncherDiscoveryRequestBuilder.request() .selectors(selectClasspathRoots(roots)) .build(); launcher.execute(request); } }
private static TestExecutionListener createListener(SocketChannel channel) { try { OutputStream baseStream = Channels.newOutputStream(channel); ObjectOutputStream stream = new ObjectOutputStream(baseStream); return new SerializingListener(stream); } catch (IOException e) { throw new UncheckedIOException("Failed to open stream to socket client.", e); } }