JUnit4 comparison components
- ../assert Comparing models against systems
This module integrates the capabilities of assert-core
into the junit4 testing framework.
It provides the Flocessor
the FlowRule
classes, which should be combined in a Parameterised test that will exercise your system.
After importing the bom
:
<dependency>
<!-- system assertion -->
<groupId>com.mastercard.test.flow</groupId>
<artifactId>assert-junit4</artifactId>
<scope>test</scope>
</dependency>
There is a certain amount of unavoidable boilerplate required to hook the Flocessor
and FlowRule
into junit 4:
@RunWith(Parameterized.class)
public class MyTest {
private static final Flocessor flows = new Flocessor( "my flow test", mySystemModel )
.system( /* The actors that are being exercised */ )
.behaviour( asrt -> {
// implement this to push data from asrt into your system
// and then put the system outputs back into asrt
} );
// Boilerplate from here on
/** @return The {@link Flow} parameters */
@Parameters(name = "{0}")
public static Collection<Object[]> flows() {
return flows.parameters();
}
/** Human-readable name for the current test case */
@Parameter(0)
public String name;
/** The current {@link Flow} */
@Parameter(1)
public Flow flow;
/** Captures test outcome */
@Rule
public FlowRule flowRule = flows.rule( () -> flow );
/** Exercises the current {@link Flow} */
@Test
public void test() {
flows.process( flow );
}
}