Skip to content
View droolsassert's full-sized avatar

Block or report droolsassert

Block user

Prevent this user from interacting with your repositories and sending you notifications. Learn more about blocking users.

You must be logged in to block users.

Please don't include any personal information such as legal names or email addresses. Maximum 100 characters, markdown supported. This note will be visible to only you.
Report abuse

Contact GitHub support about this user’s behavior. Learn more about reporting abuse.

Report abuse
droolsassert/README.md

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.3.12.7.511+
8.x.x3.1.72.6.711+
7.x.x3.0.162.5.161.8+
6.4+2.4.122.3.131.8+

Support

Buy me a coffee

Popular repositories Loading

  1. droolsassert droolsassert Public

    Drools unit and integration testing with JUnit and jbehave

    Java 18 8