@Documented @Retention(value=RUNTIME) @Target(value=METHOD) public @interface Test
This method must be public, non static, 0-arg, void return.
public abstract String name
If not used, the test name will be based on the method name. In case of
parameterized test, the name will be formatted in the same way that the
@Parameters annotation will be.
For the exact syntax of the name model.,
The formatter used
for parameterized test. For version before 0.4.0.,
The formatter used for
parameterized test, since version 0.4.0.public abstract boolean fastFail
The goal is here to change the fail assertion and failure work ; When set
to false. Assertion/failure will not stop the test, but
return false. It is up to the test itself to define what to be done based
on this return value (continue, return, etc). At the end of the test, if
any failure happened, a general failure will be produced, with detail
regarding all failures.
For example, a test may look like :
public class LaterFailureTest implements TestSuite {
@Test(fastFail = false)
public void test() {
assertThat(true).is(false);
assertWhen((p) -> {
}).throwException(any(Throwable.class));
fail("demo");
}
}
And the result like:
Multiple failures :
Error : expecting <false> but was <true>
Error : An exception was expected, but none was thrown
Error : demo
Original Stack Traces
expecting <false> but was <true>
ch.powerunit.impl.AssertThatObjectImpl.is(AssertThatObjectImpl.java:63)
...
An exception was expected, but none was thrown
ch.powerunit.impl.AssertThatExceptionImpl.throwException(AssertThatExceptionImpl.java:64)
...
demo
ch.powerunit.Assert.fail(Assert.java:578)
...
ch.powerunit.impl.TestContextImpl.fail(TestContextImpl.java:115)
ch.powerunit.impl.DefaultPowerUnitRunnerImpl.lambda$null$104(DefaultPowerUnitRunnerImpl.java:505)
ch.powerunit.impl.DefaultPowerUnitRunnerImpl$$Lambda$38/665188480.run(Unknown Source)
ch.powerunit.impl.DefaultPowerUnitRunnerImpl.lambda$runOne$73(DefaultPowerUnitRunnerImpl.java:226)
ch.powerunit.impl.DefaultPowerUnitRunnerImpl$$Lambda$42/520022247.accept(Unknown Source)
java.util.HashMap$EntrySet.forEach(HashMap.java:1035)
ch.powerunit.impl.DefaultPowerUnitRunnerImpl.runOne(DefaultPowerUnitRunnerImpl.java:210)
ch.powerunit.impl.DefaultPowerUnitRunnerImpl.run(DefaultPowerUnitRunnerImpl.java:144)
ch.powerunit.PowerUnitMainRunner.main(PowerUnitMainRunner.java:82)
ch.powerunit.suite.Suites.main(Suites.java:73)
TestSuite.
import ch.powerunit.Rule;
import ch.powerunit.Test;
import ch.powerunit.TestRule;
import ch.powerunit.TestSuite;
public class MyBean4Test implements TestSuite {
@Rule
public final TestRule rule = before(this::prepare);
private MyBean bean;
private void prepare() {
bean = new MyBean();
}
@Test()
public void testSimple() throws Exception {
Thread t = new Thread(() -> {
bean.setField1("y");
assertThat(bean.getField1()).is("x");
});
t.start();
t.join();
}
}
This test will not fail!. Why ? because simply the assertion
failure happend in another thread, so this thread receive an assertion
failure, not the once supporting the test.
import ch.powerunit.Rule;
import ch.powerunit.Test;
import ch.powerunit.TestRule;
import ch.powerunit.TestSuite;
public class MyBean3Test implements TestSuite {
@Rule
public final TestRule rule = before(this::prepare);
private MyBean bean;
private void prepare() {
bean = new MyBean();
}
@Test(fastFail = false)
public void testSimple() throws Exception {
Thread t = new Thread(() -> {
bean.setField1("y");
assertThat(bean.getField1()).is("x");
});
t.start();
t.join();
}
}
This test will fail!. Why ? because the fastFail mode will make
the assertThat method only register the failure, and produce
an error in the test thread. the link between the two threads is found
because the assertThat method used is the one from the test
class itself.Copyright © 2018 Powerunit. All rights reserved.