Relieve Drools JUnit testing
The goal of unit testing is to isolate each part of the program and show that the individual parts are correct. You can achieve this easier when working with drools using this library. Be certain about the rules being activated and the facts retained in your session for a scenario you need.
Unit test is about taking minimum piece of code and test all possible usecases defining specification. With integration tests your goal is not all possible usecases but integration of several units that work together. Do the same with rules. Segregate rules by business meaning and purpose. Simplest 'unit under the test' could be file with single or high cohesion set of rules and what is required for it to work (if any), like common DSL definition file or decision table. For integration test you could take meaningful subset or all rules of the system.
Specify any combination of rules you want to test in single session using @DroolsSession
, logResources
to see what was actually included.
Spring ant-like PathMatchingResourcePatternResolver gives you robust tool to include functionality you want to test together or segregate.
@DroolsSession(resources = {
"classpath*:/org/droolsassert/rules.drl",
"classpath*:/com/company/project/*/{regex:.*.(drl|dsl|xlsx|gdst)}",
"classpath*:/com/company/project/*/ruleUnderTest.rdslr" },
builderProperties = "drools.dump.dir = target/dump",
logResources = true)
Declare JUnit5 extension for the test (rule for JUnit4)
@RegisterExtension
public DroolsAssert drools = new DroolsAssert();
Specify list of rules expected to be activated for a scenario with @TestRules
annotation in addition to assertions inside test method and use other useful utilities to deal with the session.
@Test
@TestRules(expected = "atomic int rule")
public void testInt() {
drools.insertAndFire(new AtomicInteger());
assertEquals(1, drools.getObject(AtomicInteger.class).get());
}
Dummy assertions
Complex event processing
Spring integration test
Extend it with your application specific utilities
Gather performance statistic
Activation report
State transition report
Run tests in parallel
Jbehave integration
Jbehave Spring example
Jbehave extention
JUnit vs jbehave
<dependency>
<groupId>org.droolsassert</groupId>
<artifactId>droolsassert</artifactId>
<version>3.0.10</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.droolsassert</groupId>
<artifactId>droolsassert</artifactId>
<version>2.5.10</version>
<scope>test</scope>
</dependency>