/** * Set a callback executed after each test and before the suite <code>after</code> callback. * @param callback the callback * @return a reference to this, so the API can be used fluently */ public io.vertx.rxjava.ext.unit.TestSuite afterEach(Handler<io.vertx.rxjava.ext.unit.TestContext> callback) { delegate.afterEach(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; }
/** * Set a callback executed after each test and before the suite <code>after</code> callback. * @param callback the callback * @return a reference to this, so the API can be used fluently */ public io.vertx.rxjava.ext.unit.TestSuite afterEach(Handler<io.vertx.rxjava.ext.unit.TestContext> callback) { delegate.afterEach(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; }
@Test public void testRepeatBeforeAfterEach() throws Exception { List<String> events = Collections.synchronizedList(new ArrayList<String>()); TestSuite suite = TestSuite.create("my_suite").beforeEach(ctx -> { events.add("before"); }).test("my_test", 3, ctx -> { events.add("test"); }).afterEach(ctx -> { events.add("after"); }); TestReporter reporter = new TestReporter(); run(suite, reporter); reporter.await(); assertEquals(1, reporter.results.size()); assertEquals(0, reporter.exceptions.size()); assertEquals(1, reporter.results.size()); assertEquals(Arrays.asList("before", "test", "after", "before", "test", "after", "before", "test", "after"), events); assertEquals("my_test", reporter.results.get(0).name()); assertFalse(reporter.results.get(0).failed()); }
}); } else { suite = suite.afterEach(context -> { count.compareAndSet(1, 2); queue.add(context.async());
}); } else { suite = suite.afterEach(context -> { sameContext.set(checkTest(context)); count.incrementAndGet();
@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()); } }
test1.set(context.get("value")); context.put("value", value * 2); }).afterEach(context -> { int value = context.get("value"); afterEach.add(value);
} else { AtomicBoolean failed = new AtomicBoolean(); suite = suite.afterEach(context -> { count.incrementAndGet(); if (failed.compareAndSet(false, true)) {