/** * 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 static void execute(Class<?> testClass) throws Exception { try { JupiterTestEngine engine = new JupiterTestEngine(); TestClassEngineDiscoveryRequest discoveryRequest = new TestClassEngineDiscoveryRequest(testClass); TestDescriptor testDescriptor = engine.discover(discoveryRequest, UniqueId.forEngine("foo-bar")); EngineExecutionListener listener = new NoOpEngineExecutionListener(); ConfigurationParameters parameters = new NoConfigurationParameters(); engine.execute(new ExecutionRequest(testDescriptor, listener, parameters)); } catch (UndeclaredThrowableException e) { Throwable cause = getFirstNonUndeclaredThrowableCause(e); if (cause instanceof Error) { throw ( Error ) cause; } else if (cause instanceof RuntimeException) { throw ( RuntimeException ) cause; } else if (cause instanceof Exception) { throw ( Exception ) cause; } else { throw e; } } }
@Test public void selectingByNamespace() { EngineDiscoveryRequest request = LauncherDiscoveryRequestBuilder.request() .selectors(selectNamespace("sample.other-test")) .build(); UniqueId root = UniqueId.root("sample", "test"); List<UniqueId> expectedIds = Stream.of( root.append("namespace", "sample.other-test"), root.append("namespace", "sample.other-test").append("name", "my-other-works"), root.append("namespace", "sample.other-test").append("name", "my-other-fails"), root.append("namespace", "sample.other-test").append("name", "my-other-error") ).collect(Collectors.toList()); TestDescriptor descriptor = new ClojureTestEngine().discover(request, root); List<UniqueId> actualIds = descriptor.getAllDescendants().stream() .map(TestDescriptor::getUniqueId) .collect(Collectors.toList()); assertEquals(expectedIds, actualIds); }
@Test public void selectingByVar() { EngineDiscoveryRequest request = LauncherDiscoveryRequestBuilder.request() .selectors(selectVar("sample.other-test", "my-other-works")) .build(); UniqueId root = UniqueId.root("sample", "test"); List<UniqueId> expectedIds = Stream.of( root.append("namespace", "sample.other-test"), root.append("namespace", "sample.other-test").append("name", "my-other-works") ).collect(Collectors.toList()); TestDescriptor descriptor = new ClojureTestEngine().discover(request, root); List<UniqueId> actualIds = descriptor.getAllDescendants().stream() .map(TestDescriptor::getUniqueId) .collect(Collectors.toList()); assertEquals(expectedIds, actualIds); }
@Test public void filteringByNamespace() { Set<File> roots = Arrays.stream(System.getProperty("classpath.roots").split(File.pathSeparator)) .map(File::new) .collect(Collectors.toSet()); EngineDiscoveryRequest request = LauncherDiscoveryRequestBuilder.request() .selectors(selectClasspathRoots(roots)) .filters(includeNamespacePattern(".*other.*")) .build(); UniqueId root = UniqueId.root("sample", "test"); List<UniqueId> expectedIds = Stream.of( root.append("namespace", "sample.other-test"), root.append("namespace", "sample.other-test").append("name", "my-other-works"), root.append("namespace", "sample.other-test").append("name", "my-other-fails"), root.append("namespace", "sample.other-test").append("name", "my-other-error") ).collect(Collectors.toList()); TestDescriptor descriptor = new ClojureTestEngine().discover(request, root); List<UniqueId> actualIds = descriptor.getAllDescendants().stream() .map(TestDescriptor::getUniqueId) .collect(Collectors.toList()); assertEquals(expectedIds, actualIds); }
@Test public void getsTagsFromMetadata() { Set<File> roots = Arrays.stream(System.getProperty("classpath.roots").split(File.pathSeparator)) .map(File::new) .collect(Collectors.toSet()); EngineDiscoveryRequest request = LauncherDiscoveryRequestBuilder.request() .selectors(selectClasspathRoots(roots)) .build(); UniqueId root = UniqueId.root("sample", "test"); Map<UniqueId, Set<TestTag>> expectedTags = new HashMap<>(); expectedTags.put(root.append("namespace", "sample.core-test"), tags("integration")); expectedTags.put(root.append("namespace", "sample.other-test"), tags()); expectedTags.put(root.append("namespace", "sample.core-test").append("name", "my-sample-works"), tags("integration")); expectedTags.put(root.append("namespace", "sample.core-test").append("name", "my-sample-fails"), tags()); expectedTags.put(root.append("namespace", "sample.other-test").append("name", "my-other-works"), tags("unit")); expectedTags.put(root.append("namespace", "sample.other-test").append("name", "my-other-fails"), tags()); expectedTags.put(root.append("namespace", "sample.other-test").append("name", "my-other-error"), tags("integration")); TestDescriptor descriptor = new ClojureTestEngine().discover(request, root); Map<UniqueId, Set<TestTag>> actualTags = descriptor.getAllDescendants().stream() .collect(Collectors.toMap(TestDescriptor::getUniqueId, TestDescriptor::getTags)); assertEquals(expectedTags, actualTags); }
@Override public TestDescriptor discover(EngineDiscoveryRequest discoveryRequest, UniqueId uniqueId) { // Discover test(s) and return a TestDescriptor object TestDescriptor testDescriptor = new EngineDescriptor(uniqueId, "My test"); return testDescriptor; }
private PropertyMethodDescriptor createDescriptor(String methodName, long seed, int tries, int maxDiscardRatio, ShrinkingMode shrinking) { UniqueId uniqueId = UniqueId.root("test", "i dont care"); Method method = TestHelper.getMethod(PropertyExamples.class, methodName); PropertyConfiguration propertyConfig = new PropertyConfiguration("Property", seed, tries, maxDiscardRatio, shrinking, ReportingMode.MINIMAL); return new PropertyMethodDescriptor(uniqueId, method, PropertyExamples.class, propertyConfig); }
@Test public void selectingByClasspathDir() { Set<File> roots = Arrays.stream(System.getProperty("classpath.roots").split(File.pathSeparator)) .map(File::new) .collect(Collectors.toSet()); EngineDiscoveryRequest request = LauncherDiscoveryRequestBuilder.request() .selectors(selectClasspathRoots(roots)) .build(); UniqueId root = UniqueId.root("sample", "test"); List<UniqueId> expectedIds = Stream.of( root.append("namespace", "sample.core-test"), root.append("namespace", "sample.other-test"), root.append("namespace", "sample.core-test").append("name", "my-sample-works"), root.append("namespace", "sample.core-test").append("name", "my-sample-fails"), root.append("namespace", "sample.other-test").append("name", "my-other-works"), root.append("namespace", "sample.other-test").append("name", "my-other-fails"), root.append("namespace", "sample.other-test").append("name", "my-other-error") ).collect(Collectors.toList()); TestDescriptor descriptor = new ClojureTestEngine().discover(request, root); List<UniqueId> actualIds = descriptor.getAllDescendants().stream() .map(TestDescriptor::getUniqueId) .collect(Collectors.toList()); assertEquals(expectedIds, actualIds); }
@Override public TestDescriptor discover(EngineDiscoveryRequest discoveryRequest, UniqueId uniqueId) { this.discoveryRequestForDiscovery = discoveryRequest; this.uniqueIdForDiscovery = uniqueId; UniqueId engineUniqueId = UniqueId.forEngine(ID); TestDescriptorStub engineDescriptor = new TestDescriptorStub(engineUniqueId, ID); TestDescriptorStub testDescriptor = new TestDescriptorStub(engineUniqueId.append("test", "test"), "test"); engineDescriptor.addChild(testDescriptor); return engineDescriptor; }
public static List<ExecutionEvent> execute(TestEngine testEngine, EngineDiscoveryRequest discoveryRequest) { TestDescriptor engineTestDescriptor = testEngine.discover(discoveryRequest, UniqueId.forEngine(testEngine.getId())); ExecutionEventRecorder listener = new ExecutionEventRecorder(); testEngine.execute( new ExecutionRequest(engineTestDescriptor, listener, discoveryRequest.getConfigurationParameters())); return listener.getExecutionEvents(); }
@Override public TestDescriptor discover(EngineDiscoveryRequest discoveryRequest, UniqueId uniqueId) { TestDescriptor engine = new EngineDescriptor(uniqueId, getCaption()); for (int i = 0; i < getScoops(discoveryRequest, 5); i++) { engine.addChild(new Scoop(engine.getUniqueId(), i, Flavor.random())); } return engine; }
public AbstractMethodDescriptor(UniqueId uniqueId, Method targetMethod, Class containerClass) { super(uniqueId, determineDisplayName(targetMethod), MethodSource.from(targetMethod)); this.containerClass = containerClass; this.targetMethod = targetMethod; }
public PropertyMethodDescriptor(UniqueId uniqueId, Method propertyMethod, Class containerClass, PropertyConfiguration configuration) { super(uniqueId, propertyMethod, containerClass); this.configuration = configuration; }
public ClojureNamespaceDescriptor(UniqueId id, Namespace ns) { super(id, ns.toString()); this.ns = ns; this.tags = SimpleClojure.invoke("org.ajoberstar.jovial.lang.clojure", "tags", ns); setSource(SimpleClojure.invoke("org.ajoberstar.jovial.lang.clojure", "ns-source", ns)); }
public ClojureVarDescriptor(UniqueId id, Var var) { super(id, var.sym.getName()); this.var = var; this.tags = SimpleClojure.invoke("org.ajoberstar.jovial.lang.clojure", "tags", var); setSource(SimpleClojure.invoke("org.ajoberstar.jovial.lang.clojure", "var-source", var)); }
@Override public TestDescriptor discover(EngineDiscoveryRequest request, UniqueId uniqueId) { Object engine = getEngine(request.getConfigurationParameters()); return (TestDescriptor) SimpleClojure.invoke(ENGINE_NS, "discover", engine, request, uniqueId); }
@Override public TestDescriptor discover(EngineDiscoveryRequest discoveryRequest, UniqueId uniqueId) { return new TestDescriptorStub(UniqueId.forEngine(getId()), getId()); }
public TestDescriptorStub(UniqueId uniqueId, String displayName) { super(uniqueId, displayName); }
protected TestDescriptor discoverTests(LauncherDiscoveryRequest request) { return engine.discover(request, UniqueId.forEngine(engine.getId())); }
Scoop(UniqueId uniqueId, int counter, Flavor flavor) { super(uniqueId.append("scoop", "#" + counter), flavor.name()); }