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());
}
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);
}
}
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);
}
}
}
}
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));
}
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", " 	").replaceAll("\r", " ") + "\"><![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);
}
Aggregations