Search in sources :

Example 11 with TestAbortedException

use of org.opentest4j.TestAbortedException in project junit5 by junit-team.

the class SingleTestExecutorTests method executeSafelyAborted.

@Test
void executeSafelyAborted() {
    TestAbortedException testAbortedException = new TestAbortedException("assumption violated");
    TestExecutionResult result = new SingleTestExecutor().executeSafely(() -> {
        throw testAbortedException;
    });
    assertEquals(ABORTED, result.getStatus());
    assertSame(testAbortedException, result.getThrowable().get());
}
Also used : TestAbortedException(org.opentest4j.TestAbortedException) TestExecutionResult(org.junit.platform.engine.TestExecutionResult) Test(org.junit.jupiter.api.Test)

Example 12 with TestAbortedException

use of org.opentest4j.TestAbortedException in project janusgraph by JanusGraph.

the class RetryingTestExecutionExtension method handleTestExecutionException.

@Override
public void handleTestExecutionException(ExtensionContext context, Throwable throwable) throws Throwable {
    RetryingTestFailure testFailure = new RetryingTestFailure(invocation, throwable);
    List<RetryingTestFailure> failures = getFailures(context);
    failures.add(testFailure);
    int failureCount = failures.size();
    int successCount = invocation - failureCount;
    if ((maxInvocations - failureCount) < minSuccess) {
        throw testFailure;
    } else if (successCount < minSuccess) {
        // Case when we have still have retries left
        throw new TestAbortedException("Aborting test #" + minSuccess + " of " + maxInvocations + "- still have retries left", testFailure);
    }
}
Also used : TestAbortedException(org.opentest4j.TestAbortedException)

Example 13 with TestAbortedException

use of org.opentest4j.TestAbortedException in project logging-log4j2 by apache.

the class CassandraExtension method beforeEach.

@Override
public void beforeEach(final ExtensionContext context) throws Exception {
    final var cassandraFixture = context.getRequiredTestMethod().getAnnotation(CassandraFixture.class);
    if (cassandraFixture != null) {
        final var latch = new CountDownLatch(1);
        final var errorRef = new AtomicReference<Throwable>();
        final var embeddedCassandra = new EmbeddedCassandra(latch, errorRef);
        final Path root = Files.createTempDirectory("cassandra");
        Files.createDirectories(root.resolve("data"));
        final Path config = root.resolve("cassandra.yml");
        Files.copy(getClass().getResourceAsStream("/cassandra.yaml"), config);
        System.setProperty("cassandra.config", "file:" + config.toString());
        System.setProperty("cassandra.storagedir", root.toString());
        // prevents Cassandra from closing stdout/stderr
        System.setProperty("cassandra-foreground", "true");
        THREAD_FACTORY.newThread(embeddedCassandra).start();
        latch.await();
        final Throwable error = errorRef.get();
        if (error instanceof NoClassDefFoundError) {
            throw new TestAbortedException("Unsupported platform", error);
        } else {
            fail(error);
        }
        final var cluster = Cluster.builder().addContactPoints(InetAddress.getLoopbackAddress()).build();
        final var store = context.getStore(ExtensionContext.Namespace.create(CassandraFixture.class, context.getRequiredTestInstance()));
        store.put(Cluster.class, cluster);
        store.put(EmbeddedCassandra.class, embeddedCassandra);
        try (final Session session = cluster.connect()) {
            session.execute("CREATE KEYSPACE " + cassandraFixture.keyspace() + " WITH REPLICATION = " + "{ 'class': 'SimpleStrategy', 'replication_factor': 2 };");
        }
        try (final Session session = cluster.connect(cassandraFixture.keyspace())) {
            for (final String ddl : cassandraFixture.setup()) {
                session.execute(ddl);
            }
        }
    }
}
Also used : Path(java.nio.file.Path) TestAbortedException(org.opentest4j.TestAbortedException) AtomicReference(java.util.concurrent.atomic.AtomicReference) CountDownLatch(java.util.concurrent.CountDownLatch) Session(com.datastax.driver.core.Session)

Example 14 with TestAbortedException

use of org.opentest4j.TestAbortedException in project cucumber-jvm by cucumber.

the class TestCaseResultObserverTest method skippedByUser.

@Test
void skippedByUser() {
    bus.send(new TestCaseStarted(Instant.now(), testCase));
    bus.send(new TestStepStarted(Instant.now(), testCase, testStep));
    Result result = new Result(Status.SKIPPED, Duration.ZERO, new TestAbortedException("thrown by user"));
    bus.send(new TestStepFinished(Instant.now(), testCase, testStep, result));
    bus.send(new TestCaseFinished(Instant.now(), testCase, result));
    Exception exception = assertThrows(Exception.class, observer::assertTestCasePassed);
    assertThat(exception.getCause(), instanceOf(TestAbortedException.class));
}
Also used : TestCaseFinished(io.cucumber.plugin.event.TestCaseFinished) TestStepFinished(io.cucumber.plugin.event.TestStepFinished) TestAbortedException(org.opentest4j.TestAbortedException) TestStepStarted(io.cucumber.plugin.event.TestStepStarted) TestCaseStarted(io.cucumber.plugin.event.TestCaseStarted) TestAbortedException(org.opentest4j.TestAbortedException) Result(io.cucumber.plugin.event.Result) Test(org.junit.jupiter.api.Test)

Example 15 with TestAbortedException

use of org.opentest4j.TestAbortedException in project cucumber-jvm by cucumber.

the class JUnitFormatterTest method should_format_skipped_scenario.

@Test
void should_format_skipped_scenario() {
    Feature feature = TestFeatureParser.parse("path/test.feature", "Feature: feature name\n" + "  Scenario: scenario name\n" + "    Given first step\n" + "    When second step\n" + "    Then third step\n");
    RuntimeException exception = new TestAbortedException("message");
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    Runtime.builder().withFeatureSupplier(new StubFeatureSupplier(feature)).withAdditionalPlugins(new JUnitFormatter(out)).withEventBus(new TimeServiceEventBus(fixed(EPOCH, of("UTC")), UUID::randomUUID)).withBackendSupplier(new StubBackendSupplier(new StubStepDefinition("first step", exception), new StubStepDefinition("second step"), new StubStepDefinition("third step"))).build().run();
    String stackTrace = getStackTrace(exception);
    String expected = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>\n" + "<testsuite failures=\"0\" name=\"io.cucumber.core.plugin.JUnitFormatter\" skipped=\"1\" errors=\"0\" tests=\"1\" time=\"0\">\n" + "    <testcase classname=\"feature name\" name=\"scenario name\" time=\"0\">\n" + "        <skipped message=\"" + stackTrace.replace("\n\t", "&#10;&#9;").replaceAll("\r", "&#13;") + "\"><![CDATA[" + "Given first step............................................................skipped\n" + "When second step............................................................skipped\n" + "Then third step.............................................................skipped\n" + "\n" + "StackTrace:\n" + stackTrace + "]]></skipped>\n" + "    </testcase>\n" + "</testsuite>\n";
    assertXmlEqual(expected, out);
}
Also used : TimeServiceEventBus(io.cucumber.core.runtime.TimeServiceEventBus) StubBackendSupplier(io.cucumber.core.runtime.StubBackendSupplier) StubFeatureSupplier(io.cucumber.core.runtime.StubFeatureSupplier) TestAbortedException(org.opentest4j.TestAbortedException) StubStepDefinition(io.cucumber.core.backend.StubStepDefinition) ByteArrayOutputStream(java.io.ByteArrayOutputStream) UUID(java.util.UUID) Feature(io.cucumber.core.gherkin.Feature) Test(org.junit.jupiter.api.Test)

Aggregations

TestAbortedException (org.opentest4j.TestAbortedException)22 Test (org.junit.jupiter.api.Test)16 RepeatedIfExceptionsTest (io.github.artsok.RepeatedIfExceptionsTest)3 TestExecutionResult (org.junit.platform.engine.TestExecutionResult)3 Java (de.sormuras.bartholdy.tool.Java)2 StubStepDefinition (io.cucumber.core.backend.StubStepDefinition)2 Feature (io.cucumber.core.gherkin.Feature)2 StubBackendSupplier (io.cucumber.core.runtime.StubBackendSupplier)2 StubFeatureSupplier (io.cucumber.core.runtime.StubFeatureSupplier)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 IOException (java.io.IOException)2 Properties (java.util.Properties)2 Order (org.junit.jupiter.api.Order)2 TestMethodOrder (org.junit.jupiter.api.TestMethodOrder)2 InOrder (org.mockito.InOrder)2 Session (com.datastax.driver.core.Session)1 TimeServiceEventBus (io.cucumber.core.runtime.TimeServiceEventBus)1 Result (io.cucumber.plugin.event.Result)1 TestCaseFinished (io.cucumber.plugin.event.TestCaseFinished)1 TestCaseStarted (io.cucumber.plugin.event.TestCaseStarted)1