Skip to content

Drools unit and integration testing with JUnit and jbehave

License

Notifications You must be signed in to change notification settings

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

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

Latest maven build (JUnit5)

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

JUnit4

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

About

Drools unit and integration testing with JUnit and jbehave

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Java 94.8%
  • Gherkin 3.7%
  • ASL 1.5%