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
Please enter at least three characters to search
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Zones

Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

Because the DevOps movement has redefined engineering responsibilities, SREs now have to become stewards of observability strategy.

Apache Cassandra combines the benefits of major NoSQL databases to support data management needs not covered by traditional RDBMS vendors.

The software you build is only as secure as the code that powers it. Learn how malicious code creeps into your software supply chain.

Generative AI has transformed nearly every industry. How can you leverage GenAI to improve your productivity and efficiency?

Related

  • Driving DevOps With Smart, Scalable Testing
  • Unit Testing Large Codebases: Principles, Practices, and C++ Examples
  • Practical Use of Weak Symbols
  • Generate Unit Tests With AI Using Ollama and Spring Boot

Trending

  • How to Introduce a New API Quickly Using Micronaut
  • Useful System Table Queries in Relational Databases
  • How to Use AWS Aurora Database for a Retail Point of Sale (POS) Transaction System
  • Bridging UI, DevOps, and AI: A Full-Stack Engineer’s Approach to Resilient Systems
  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
7.8K 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

  • Driving DevOps With Smart, Scalable Testing
  • Unit Testing Large Codebases: Principles, Practices, and C++ Examples
  • Practical Use of Weak Symbols
  • Generate Unit Tests With AI Using Ollama and Spring Boot

Partner Resources

×

Comments
Oops! Something Went Wrong

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

ABOUT US

  • About DZone
  • Support and feedback
  • Community research
  • Sitemap

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 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends:

Likes
There are no likes...yet! 👀
Be the first to like this post!
It looks like you're not logged in.
Sign in to see who liked this post!