DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Related

  • Effective Engineering Feedback: Software Testing
  • The LLM Selection War Story: Part 2 - The Six LLM Failure Archetypes That Will Wreck Your Production System
  • Agentic Development: My Invisible Dev Team
  • Clean Code in the Age of Copilot: Why Semantics Matter More Than Ever

Trending

  • Building a DevOps-Ready Internal Developer Platform: A Hands-On Guide to Golden Paths, Self-Service, and Automated Delivery Pipelines
  • Slopsquatting: Building a Scanner That Catches AI-Hallucinated Packages Before They Reach Production
  • Building a High-Throughput Distributed Sequence Generator Using the Hi-Lo Algorithm
  • Optimizing High-Volume REST APIs Using Redis Caching and Spring Boot (With Load Testing Code)
  1. DZone
  2. Testing, Deployment, and Maintenance
  3. Testing, Tools, and Frameworks
  4. Unit Testing of jBPM Process Flows

Unit Testing of jBPM Process Flows

Learn more about how to run unit tests with jBPM process flows.

By 
Prasanth Nair user avatar
Prasanth Nair
·
Mar. 01, 19 · Tutorial
Likes (3)
Comment
Save
Tweet
Share
8.1K Views

Join the DZone community and get the full member experience.

Join For Free

Unit testing is an important step in the software development life cycle to ensure that your product works the way it is intended to work. Back in the day, it used to be just a step that developers had to perform to evaluate their work. In today’s world, it has become an essential part of the CI/CD pipeline as it is not just used to determine quality based on functionality but also to determine code promotion eligibility based on various numbers (pass/fail ratio or code coverage percentage).

jBPM, being one of the most modern, open-source bpm products, provides rich capabilities for unit testing BPM processes. This allows jBPM processes to be treated just like any other Java-based artifact. The jBPM tool kit provides an extension of JUnit test classes that allow one to easily unit test business processes defined in BPMN2.

We will look at a sample implementation where we use out-of-the-box unit testing capabilities provided by jBPM. jBPM provides a test module (jbpm-test.jar) that includes all of the classes needed for creating jBPM unit tests. It is easy to include the jbpm-test module to your jBPM project. You just need to add the dependency to your pom.xml.

<dependency>
   <groupId>org.jbpm</groupId>
   <artifactId>jbpm-test</artifactId>
   <version>7.17.0.Final</version>
</dependency>


The jBPM test module provides the JbpmJUnitBaseTestCase class, which provides various method implementations to support BPMN2 process unit testing .

JbpmJUnitBaseTestCase class provides support in four major areas. Some of the most important ones in those areas are listed below:

JUnit Life Cycle Methods

  •  setup(): This is an @Before annotated method to create EntityManagerFactory and cleans up the Singleton's sessionID

  •  teardown(): This is an @After annotated method, which clears out history, closes EntityManagerFactoryand the data source, and disposes of the RuntimeEngines and RuntimeManager.

KIE Session Management Methods

  • createRuntimeManager()

  • disposeRuntimeManager() 

  • getRuntimeEngine() 

Assertions

  •  assertProcessInstanceCompleted 

  •  assertProcessInstanceActive 

  •  assertNodeTriggered 

  •  assertProcessVarExists 

Helper Methods

  •  getTestWorkItemHandler() — returns test work item handler that might be registered in addition to what is registered by default

  •  setupPoolingDataSource() — sets up the data source

Below is a sample implementation using the JbpmJUnitBaseTestCase.

public class HelloWorldTest extends JbpmJUnitBaseTestCase  {

public HelloWorldTest() {
    // This helps to setup data source and session persistence
        super(true, true);
}

    @Test
    public void testHelloWorld() {
      createRuntimeManager("com/sample/HelloWorld.bpmn2");
      RuntimeEngine runtimeEngine = getRuntimeEngine();
      KieSession ksession = runtimeEngine.getKieSession();
      ProcessInstance processInstance = ksession.startProcess("com.sample.HelloWorld");
      assertProcessInstanceCompleted(processInstance.getId());
      disposeRuntimeManager();
    }
}


This approach allows us to test basic process status and its life cycle. This is with the assumption that a process is high level and doesn’t have too many implementation logic embedded in the process. Currently, there is no way to measure the code coverage and branch in BPM processes. Hopefully it will come in future versions.

unit test

Opinions expressed by DZone contributors are their own.

Related

  • Effective Engineering Feedback: Software Testing
  • The LLM Selection War Story: Part 2 - The Six LLM Failure Archetypes That Will Wreck Your Production System
  • Agentic Development: My Invisible Dev Team
  • Clean Code in the Age of Copilot: Why Semantics Matter More Than Ever

Partner Resources

×

Comments

The likes didn't load as expected. Please refresh the page and try again.

  • RSS
  • X
  • Facebook

ABOUT US

  • About DZone
  • Support and feedback
  • Community research

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 215
  • Nashville, TN 37211
  • [email protected]

Let's be friends:

  • RSS
  • X
  • Facebook