junit-drools

library for unit-testing drools rules

License

License

Categories

Categories

JUnit Unit Testing
GroupId

GroupId

com.github.jeichler
ArtifactId

ArtifactId

junit-drools
Last Version

Last Version

1.0
Release Date

Release Date

Type

Type

jar
Description

Description

junit-drools
library for unit-testing drools rules
Project URL

Project URL

http://github.com/jeichler/junit-drools
Source Code Management

Source Code Management

http://github.com/jeichler/junit-drools

Download junit-drools

How to add to project

<!-- https://jarcasting.com/artifacts/com.github.jeichler/junit-drools/ -->
<dependency>
    <groupId>com.github.jeichler</groupId>
    <artifactId>junit-drools</artifactId>
    <version>1.0</version>
</dependency>
// https://jarcasting.com/artifacts/com.github.jeichler/junit-drools/
implementation 'com.github.jeichler:junit-drools:1.0'
// https://jarcasting.com/artifacts/com.github.jeichler/junit-drools/
implementation ("com.github.jeichler:junit-drools:1.0")
'com.github.jeichler:junit-drools:jar:1.0'
<dependency org="com.github.jeichler" name="junit-drools" rev="1.0">
  <artifact name="junit-drools" type="jar" />
</dependency>
@Grapes(
@Grab(group='com.github.jeichler', module='junit-drools', version='1.0')
)
libraryDependencies += "com.github.jeichler" % "junit-drools" % "1.0"
[com.github.jeichler/junit-drools "1.0"]

Dependencies

compile (5)

Group / Artifact Type Version
org.kie : kie-api jar
org.drools : drools-core jar
org.drools : drools-compiler jar
org.jbpm : jbpm-bpmn2 jar 6.2.0.Final
junit : junit jar 4.11

Project Modules

There are no modules declared in this project.

Build Status

Usage

The library is available on maven central. Simply include it in your pom:

<dependency>
	<groupId>com.github.jeichler</groupId>
	<artifactId>junit-drools</artifactId>
	<version>1.0</version>
	<scope>test</scope>
</dependency>

Then you can start right away unit-testing your rules:

@DroolsFiles(ruleFiles = {"some/folder/in/resources/YourRuleFile.drl", "some/folder/in/resources/YourRuleFlow.bpmn"})
@RunWith(DroolsJUnitRunner.class)
public class TestClass {

  //@StatelessDroolsSession
  @StatefulDroolsSession
  private DroolsSession session;
  
  //...
  
  @Test
  public void testMethod() {
    session.insert(yourObject);
    session.fireAllRules();
    Assert.assertTrue(session.getNumberOfFiredRules() == expectedNumberOfFiredRules);
  }

}

Some thoughts

Though I added support for rule flows (a pretty basic one, and yes, on purpose, i skipped adding whole folders at once because I'm not convinced that it helps testing your application.) I'm not a big fan of seeing them in unit tests). They should be part of integration tests and hence be run in the respective application context and the flows should be started by the respective components in your application. However for a quick peek you might use this runner for flows as well.

Versions

Version
1.0