/** * Set a callback executed after the tests. * @param callback the callback * @return a reference to this, so the API can be used fluently */ public io.vertx.rxjava.ext.unit.TestSuite after(Handler<io.vertx.rxjava.ext.unit.TestContext> callback) { delegate.after(new Handler<io.vertx.ext.unit.TestContext>() { public void handle(io.vertx.ext.unit.TestContext event) { callback.handle(io.vertx.rxjava.ext.unit.TestContext.newInstance(event)); } }); return this; }
}); if (i == 0) { suite = suite.after(context -> { count.compareAndSet(1, 2); queue.add(context.async());
@Test public void afterIsRunAfterFailure() throws Exception { for (int i = 0;i < 2;i++) { AtomicInteger count = new AtomicInteger(); TestSuite suite = TestSuite.create("my_suite").test("my_test", context -> { count.compareAndSet(0, 1); context.fail("the_message"); }); if (i == 0) { suite = suite.after(context -> count.compareAndSet(1, 2)); } else { suite = suite.afterEach(context -> count.compareAndSet(1, 2)); } TestReporter reporter = new TestReporter(); run(suite, reporter); reporter.await(); assertEquals(2, count.get()); assertEquals(0, reporter.exceptions.size()); assertEquals(1, reporter.results.size()); assertEquals("my_test", reporter.results.get(0).name()); assertTrue(reporter.results.get(0).failed()); assertEquals("the_message", reporter.results.get(0).failure().message()); } }
/** * Set a callback executed after the tests. * @param callback the callback * @return a reference to this, so the API can be used fluently */ public io.vertx.rxjava.ext.unit.TestSuite after(Handler<io.vertx.rxjava.ext.unit.TestContext> callback) { delegate.after(new Handler<io.vertx.ext.unit.TestContext>() { public void handle(io.vertx.ext.unit.TestContext event) { callback.handle(io.vertx.rxjava.ext.unit.TestContext.newInstance(event)); } }); return this; }
suite = suite.after(context -> { sameContext.set(checkTest(context)); count.incrementAndGet();
test(testCaseName1, context -> { }). after(context -> { context.fail("the_after_failure"); });
int value = context.get("value"); afterEach.add(value); }).after(context -> { int value = context.get("value"); after.add(value);
@org.junit.Test public void testReportToFailureCompletionHandler() { RuntimeException e = new RuntimeException(); Handler<TestContext> fails = context -> { throw e; }; Handler<TestContext> pass = context -> { }; TestSuite[] suites = { TestSuite.create("my_suite").test("first_test", fails), TestSuite.create("my_suite").before(fails).test("first_test", pass), TestSuite.create("my_suite").test("first_test", pass).after(fails) }; AtomicInteger count = new AtomicInteger(); for (TestSuite suite : suites) { suite.run(new TestOptions()).handler(ar -> { assertTrue(ar.failed()); assertSame(e, ar.cause()); if (count.incrementAndGet() == 3) { testComplete(); } }); } await(); } }
suite = suite.after(context -> { count.incrementAndGet(); context.fail("the_message");
} catch (InterruptedException ignore) { }).after(context -> { throw error; });
TestSuite.create(testSuiteName).test(testCaseName, context -> { }).after(context -> { throw new RuntimeException("the_after_failure"); }).run(vertx, new TestOptions().addReporter(new ReportOptions().setTo("bus:" + address)));