/** * Instance an engine and execute the test resources identified by the given {@code selectors} and * wrap the response in a listener so that we can make sense of what happened. The listener * exposes information about the test execution flow which the extension tests can assert against. * * @param selectors {@link DiscoverySelector} instances which will isolate test class or test * methods * @return a {@link RecordingExecutionListener} which encapsulates what the engine did */ public static RecordingExecutionListener execute(DiscoverySelector... selectors) { // instance an engine JupiterTestEngine testEngine = new JupiterTestEngine(); // discover the requested test resources LauncherDiscoveryRequest discoveryRequest = request().selectors(selectors).build(); RecordingExecutionListener listener = new RecordingExecutionListener(); // execute the discovered test resources TestDescriptor testDescriptor = testEngine.discover(discoveryRequest, UniqueId.forEngine(testEngine.getId())); testEngine.execute( new ExecutionRequest( testDescriptor, listener, discoveryRequest.getConfigurationParameters())); return listener; }
public ExitStatus execute(SummaryGeneratingListener listener, DiscoverySelector selector, ApplicationConfiguration applicationConfiguration, FilesLocator filesLocator) { ApplicationConfigurationResolver.setConfiguration(applicationConfiguration); FilesLocatorResolver.setFilesLocator(filesLocator); LauncherDiscoveryRequest request = LauncherDiscoveryRequestBuilder.request() .selectors(selector) .build(); Launcher launcher = LauncherFactory.create(); launcher.registerTestExecutionListeners(listener); launcher.execute(request); return listener.getSummary().getFailures().isEmpty() ? ExitStatus.SUCCESS : ExitStatus.FAILURE; }
@Override @SuppressWarnings("unchecked") public <T extends DiscoverySelector> List<T> getSelectorsByType(Class<T> selectorType) { if (ClassSelector.class.equals(selectorType)) { List<T> list = new ArrayList<>(); list.add(( T ) DiscoverySelectors.selectClass(testClass)); return list; } return Collections.emptyList(); }
private ExecutionEventRecorder executeTestMethods(Class<?> type, String[] methodNames) { //@formatter:off DiscoverySelector[] selectors = stream(methodNames) .map(methodName -> selectMethod(type, methodName)) .toArray(DiscoverySelector[]::new); //@formatter:on LauncherDiscoveryRequest request = request().selectors(selectors).build(); return executeTests(request); }