Skip to content

droolsassert/droolsassert

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Goal

Relieve Drools JUnit testing

Audience

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.

Approach

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.

Usage

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("**/project/rules/ruleUnderTest.drl")

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());
}

Examples

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

Maven dependency

<dependency>
    <groupId>org.droolsassert</groupId>
    <artifactId>droolsassert</artifactId>
    <version>x.x.x</version>
    <scope>test</scope>
</dependency>

Compatibility matrix

DroolsJunit5Junit4Java
9.x.x3.2.42.7.411+
8.x.x3.1.62.6.611+
7.x.x3.0.152.5.151.8+
6.4+2.4.122.3.131.8+

Support

Buy me a coffee