Java 类org.junit.platform.engine.TestDescriptor 实例源码

项目:junit-extensions    文件:ExtensionTester.java   
/**
 * 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;
}
项目:webtester2-core    文件:TestClassExecutor.java   
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;
        }
    }
}
项目:jovial    文件:ClojureTestEngineTest.java   
@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);
}
项目:jovial    文件:ClojureTestEngineTest.java   
@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);
}
项目:jovial    文件:ClojureTestEngineTest.java   
@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);
}
项目:jovial    文件:ClojureTestEngineTest.java   
@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);
}
项目:mastering-junit5    文件:MyCustomEngine.java   
@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;
}
项目:mastering-junit5    文件:MyCustomEngine.java   
@Override
public void execute(ExecutionRequest request) {
    // Use ExecutionRequest to execute TestDescriptor
    TestDescriptor rootTestDescriptor = request.getRootTestDescriptor();
    request.getEngineExecutionListener()
            .executionStarted(rootTestDescriptor);
}
项目:Mastering-Software-Testing-with-JUnit-5    文件:MyCustomEngine.java   
@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;
}
项目:Mastering-Software-Testing-with-JUnit-5    文件:MyCustomEngine.java   
@Override
public void execute(ExecutionRequest request) {
    // Use ExecutionRequest to execute TestDescriptor
    TestDescriptor rootTestDescriptor = request.getRootTestDescriptor();
    request.getEngineExecutionListener()
            .executionStarted(rootTestDescriptor);
}
项目:junit5-docker    文件:TestDescriptorForCucumber.java   
private TestDescriptor wrapDescriptorForCucumber() {
    TestDescriptor usedDescriptor = this.testDescriptor;
    if (testDescriptor instanceof TestMethodTestDescriptor) {
        usedDescriptor =
            new MethodTestDescriptorForCucumber((TestMethodTestDescriptor) testDescriptor, containers);
    }
    if (testDescriptor instanceof ClassTestDescriptor) {
        usedDescriptor =
            new ClassTestDescriptorForCucumber((ClassTestDescriptor) testDescriptor, containers);
    }
    return usedDescriptor;
}
项目:junit5-docker    文件:JupiterTestEngineForTests.java   
private JupiterExecutionListener executeTests(LauncherDiscoveryRequest request) throws Exception {
    TestDescriptor testDescriptor = createTestDescriptorForCucumber(
        engine.discover(request, forEngine(engine.getId())), containers);
    eventRecorder.reset();
    engine.execute(new ExecutionRequest(testDescriptor, eventRecorder, request.getConfigurationParameters()));
    return eventRecorder;
}
项目:webtester2-core    文件:TestClassExecutor.java   
@Override
public void executionFinished(TestDescriptor testDescriptor, TestExecutionResult testExecutionResult) {
    Optional<Throwable> throwable = testExecutionResult.getThrowable();
    if (throwable.isPresent()) {
        throw new UndeclaredThrowableException(throwable.get());
    }
}
项目:jovial    文件:ClojureTestEngineTest.java   
@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);
}
项目:junit-pioneer    文件:TestEngineSpy.java   
@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;
}
项目:junit-pioneer    文件:ExecutionEventRecorder.java   
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();
}
项目:junit5-samples    文件:Machine.java   
@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;
}
项目:junit5-samples    文件:Machine.java   
@Override
public void execute(ExecutionRequest request) {
    TestDescriptor engine = request.getRootTestDescriptor();
    EngineExecutionListener listener = request.getEngineExecutionListener();
    listener.executionStarted(engine);
    for (TestDescriptor child : engine.getChildren()) {
        listener.executionStarted(child);
        listener.executionFinished(child, TestExecutionResult.successful());
    }
    listener.executionFinished(engine, TestExecutionResult.successful());
}
项目:junit-extensions    文件:RecordingExecutionListener.java   
@Override
public void dynamicTestRegistered(TestDescriptor testDescriptor) {
  addEvent(ExecutionEvent.dynamicTestRegistered(testDescriptor));
}
项目:junit-extensions    文件:RecordingExecutionListener.java   
@Override
public void executionSkipped(TestDescriptor testDescriptor, String reason) {
  addEvent(ExecutionEvent.executionSkipped(testDescriptor, reason));
}
项目:junit-extensions    文件:RecordingExecutionListener.java   
@Override
public void executionStarted(TestDescriptor testDescriptor) {
  addEvent(ExecutionEvent.executionStarted(testDescriptor));
}
项目:junit-extensions    文件:RecordingExecutionListener.java   
@Override
public void executionFinished(TestDescriptor testDescriptor, TestExecutionResult result) {
  addEvent(ExecutionEvent.executionFinished(testDescriptor, result));
}
项目:junit-extensions    文件:RecordingExecutionListener.java   
@Override
public void reportingEntryPublished(TestDescriptor testDescriptor, ReportEntry entry) {
  addEvent(ExecutionEvent.reportingEntryPublished(testDescriptor, entry));
}
项目:junit-extensions    文件:RecordingExecutionListener.java   
public Stream<ExecutionEvent> getTestEventsByType(Type type) {
  return getEventsByTypeAndTestDescriptor(type, TestDescriptor::isTest);
}
项目:junit-extensions    文件:RecordingExecutionListener.java   
public Stream<ExecutionEvent> getEventsByTypeAndTestDescriptor(
    Type type, Predicate<? super TestDescriptor> predicate) {
  return eventStream().filter(byType(type).and(byTestDescriptor(predicate)));
}
项目:junit-extensions    文件:ExecutionEvent.java   
private ExecutionEvent(ExecutionEvent.Type type, TestDescriptor testDescriptor, Object payload) {
  this.type = type;
  this.testDescriptor = testDescriptor;
  this.payload = payload;
}
项目:junit-extensions    文件:ExecutionEvent.java   
public static ExecutionEvent reportingEntryPublished(
    TestDescriptor testDescriptor, ReportEntry entry) {
  return new ExecutionEvent(REPORTING_ENTRY_PUBLISHED, testDescriptor, entry);
}
项目:junit-extensions    文件:ExecutionEvent.java   
public static ExecutionEvent dynamicTestRegistered(TestDescriptor testDescriptor) {
  return new ExecutionEvent(DYNAMIC_TEST_REGISTERED, testDescriptor, null);
}
项目:junit-extensions    文件:ExecutionEvent.java   
public static ExecutionEvent executionSkipped(TestDescriptor testDescriptor, String reason) {
  return new ExecutionEvent(SKIPPED, testDescriptor, reason);
}
项目:junit-extensions    文件:ExecutionEvent.java   
public static ExecutionEvent executionStarted(TestDescriptor testDescriptor) {
  return new ExecutionEvent(STARTED, testDescriptor, null);
}
项目:junit-extensions    文件:ExecutionEvent.java   
public static ExecutionEvent executionFinished(
    TestDescriptor testDescriptor, TestExecutionResult result) {
  return new ExecutionEvent(FINISHED, testDescriptor, result);
}
项目:junit-extensions    文件:ExecutionEvent.java   
public static Predicate<ExecutionEvent> byTestDescriptor(
    Predicate<? super TestDescriptor> predicate) {
  return where(ExecutionEvent::getTestDescriptor, predicate);
}
项目:junit-extensions    文件:ExecutionEvent.java   
public TestDescriptor getTestDescriptor() {
  return testDescriptor;
}
项目:junit5-docker    文件:JupiterExecutionListener.java   
@Override
public void executionSkipped(TestDescriptor testDescriptor, String s) {
    allTestsPassed = false;
}
项目:junit5-docker    文件:JupiterExecutionListener.java   
@Override
public void executionStarted(TestDescriptor testDescriptor) {
}
项目:junit5-docker    文件:JupiterExecutionListener.java   
@Override
public void executionFinished(TestDescriptor testDescriptor, TestExecutionResult testExecutionResult) {
    allTestsPassed = allTestsPassed && testExecutionResult.getStatus() == SUCCESSFUL;
}
项目:junit5-docker    文件:TestDescriptorForCucumber.java   
private TestDescriptorForCucumber(TestDescriptor testDescriptor, Containers containers) {
    this.testDescriptor = testDescriptor;
    this.containers = containers;
}
项目:junit5-docker    文件:TestDescriptorForCucumber.java   
public Set<? extends TestDescriptor> getChildren() {
    return testDescriptor.getChildren().stream()
        .map((discover1) -> (TestDescriptor) createTestDescriptorForCucumber(discover1, containers))
        .collect(Collectors.toSet());
}
项目:junit5-docker    文件:TestDescriptorForCucumber.java   
static TestDescriptor createTestDescriptorForCucumber(TestDescriptor testDescriptor, Containers containers) {
    return (TestDescriptor) Proxy.newProxyInstance(Thread.currentThread().getContextClassLoader(),
        new Class[]{TestDescriptor.class, Node.class}, new TestDescriptorForCucumber(testDescriptor, containers));

}
项目:jovial    文件:BaseClojureEngine.java   
@Override
public TestDescriptor discover(EngineDiscoveryRequest request, UniqueId uniqueId) {
    Object engine = getEngine(request.getConfigurationParameters());
    return (TestDescriptor) SimpleClojure.invoke(ENGINE_NS, "discover", engine, request, uniqueId);
}