ProcessTestCoverage always throws NullPointerException

Running junit and after that testing using the ProcessCoverage.calculate(processEngine)
Please let me know why it thows NullPointerException. Is that a version or dependency issue?
Thanks in advance

image

pom.xml is below

<dependencies>
		<dependency>
			<groupId>org.camunda.bpm.springboot</groupId>
			<artifactId>camunda-bpm-spring-boot-starter-rest</artifactId>
			<version>7.13.0-ee</version>
		</dependency>
		
	<!-- 	<dependency>
			<groupId>org.camunda.bpm.springboot</groupId>
			<artifactId>camunda-bpm-spring-boot-starter-test</artifactId>
			<version>7.13.0-ee</version>
		</dependency>  -->
		<dependency>
			<groupId>org.camunda.bpm.springboot</groupId>
			<artifactId>camunda-bpm-spring-boot-starter-webapp-ee</artifactId>
			<version>7.13.0-ee</version>
		</dependency>
		<dependency>
			<groupId>com.h2database</groupId>
			<artifactId>h2</artifactId>
		</dependency>
		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-jdbc</artifactId>
		</dependency>
		<dependency>
			<groupId>org.camunda.bpm</groupId>
			<artifactId>camunda-bom</artifactId>
			<version>7.13.0-ee</version>
			<type>pom</type>
		</dependency>
		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-web</artifactId>
		</dependency>
		<dependency>
			<groupId>org.camunda.spin</groupId>
			<artifactId>camunda-spin-core</artifactId>
			<version>1.9.0</version>
		</dependency>
		<dependency>
			<groupId>org.projectlombok</groupId>
			<artifactId>lombok</artifactId>
			<version>1.18.12</version>
			<scope>provided</scope>
		</dependency>
		<dependency>
			<groupId>org.camunda.spin</groupId>
			<artifactId>camunda-spin-dataformat-json-jackson</artifactId>
			<version>1.9.0</version>
		</dependency>
		<dependency>
			<groupId>org.camunda.bpm</groupId>
			<artifactId>camunda-engine-plugin-spin</artifactId>
			<version>7.13.0-ee</version>
		</dependency>
		<dependency>
			<groupId>org.camunda.bpm</groupId>
			<artifactId>camunda-engine-plugin-connect</artifactId>
			<version>7.13.0</version>
		</dependency>
		<dependency>
			<groupId>org.camunda.bpm.dmn</groupId>
			<artifactId>camunda-engine-dmn</artifactId>
			<version>7.13.0-ee</version>
		</dependency>
		<dependency>
			<groupId>junit</groupId>
			<artifactId>junit</artifactId>
		</dependency>
		<dependency>
			<groupId>org.mockito</groupId>
			<artifactId>mockito-core</artifactId>
			<scope>test</scope>
		</dependency>
		<!-- https://mvnrepository.com/artifact/org.camunda.bpm.extension/camunda-bpm-assert -->
<dependency>
    <groupId>org.camunda.bpm.extension</groupId>
    <artifactId>camunda-bpm-assert</artifactId>
    <version>1.1</version>
    <scope>test</scope>
</dependency>
		
		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-test</artifactId>
			<scope>test</scope>
		</dependency>

<!-- <dependency>
 <groupId> org.camunda.consulting.snippets </groupId>
 <artifactId>process-test-coverage</artifactId>
 <version>0.2.3</version>
 <scope>test</scope>
</dependency> -->

<!-- https://mvnrepository.com/artifact/org.camunda.consulting.snippets/process-test-coverage -->
<dependency>
    <groupId>org.camunda.consulting.snippets</groupId>
    <artifactId>process-test-coverage</artifactId>
    <version>0.2.3</version>
</dependency>



<!-- https://mvnrepository.com/artifact/org.camunda.bpm.assert/camunda-bpm-assert -->
<dependency>
    <groupId>org.camunda.bpm.assert</groupId>
    <artifactId>camunda-bpm-assert</artifactId>
    <version>5.0.0</version>
</dependency>


	</dependencies>
	<build>
		<plugins>
			<plugin>
				<groupId>org.springframework.boot</groupId>
				<artifactId>spring-boot-maven-plugin</artifactId>
			</plugin>
		</plugins>
	</build>
	<repositories>
		<repository>
			<id>camunda-bpm-nexus-ee</id>
			<name>camunda-bpm-nexus</name>
			<url>https://app.camunda.com/nexus/content/repositories/camunda-bpm-ee</url>
		</repository>
		<repository>
			<id>camunda-bpm-ee</id>
			<name>camunda-bpm-nexus</name>
			<url>https://app.camunda.com/nexus/repositories</url>
		</repository>
	</repositories>
</project>

Hi @ravii,

you should change your dependency to Camunda BPM Test Coverage.

Take this dependency:

<dependency>
  <groupId>org.camunda.bpm.extension</groupId>
  <artifactId>camunda-bpm-process-test-coverage</artifactId>
  <version>0.3.2</version>
  <scope>test</scope>
</dependency>

You can refer to the docs here: https://github.com/camunda/camunda-bpm-process-test-coverage

Hope this helps, Ingo

@Ingo_Richtsmeier- Thanks for the reply. I have included the dependency and followed the github URL from mobile(As github is blocked from DNS in the Laptop). could see this snippet

@Rule
	@ClassRule
	public static ProcessEngineRule rule=TestCoverageProcessEngineRuleBuilder.create().build(); 

Then started to run the JUNIT but it gets terminated after displaying the console everytime.

16:47:58.447 [main] DEBUG org.springframework.test.annotation.ProfileValueUtils - Retrieved ProfileValueSource type [class org.springframework.test.annotation.SystemProfileValueSource] for class [com.vodafone.iot.gdsp.changecsp.controller.FlowTest_3]
16:47:58.507 [main] DEBUG org.camunda.bpm.engine.test - ==== BUILDING PROCESS ENGINE ========================================================================
16:47:58.601 [main] DEBUG org.camunda.bpm.engine.test - ==== BUILDING PROCESS ENGINE ========================================================================

@Ingo_Richtsmeier- It says it is expecting activiti.cfg.xml and FileNotFoundException. please let me know the importance of file and what should be included here. Is there a way to avoid XML as it is a spring-boot project.

Hi @ravii,

you have to provide a camunda.cfg.xml file in the src/test/resources folder.

It’s mentioned in the docs in the second step: https://github.com/camunda/camunda-bpm-process-test-coverage#get-started-with-3-simple-steps

You can find a complete example here: https://docs.camunda.org/manual/7.13/user-guide/process-engine/process-engine-bootstrapping/#configure-process-engine-using-camunda-cfg-xml

But use the processEngineConfiguration from the process test coverage docs.

Hope this helps, Ingo

@Ingo_Richtsmeier- Thanks for the reply. I have included the xml file and now it says
ENGINE-00005 Exception while initializing process engine ENGINE-03017 Could not perform operation 'create' on database schema

org.h2.jdbc.JdbcSQLSyntaxErrorException: Table "ACT_HI_PROCINST" already exists; SQL statement:
After adding the below XML with bean id-processEngineConfiguration.It says DBException.please let us know the exat issue.
camunda.cfg.xml:

<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">

  <bean id="processEngineConfiguration" class="org.camunda.bpm.extension.process_test_coverage.junit.rules.ProcessCoverageInMemProcessEngineConfiguration">

    
  </bean>

Exception Stack trace:

Caused by: org.h2.jdbc.JdbcSQLSyntaxErrorException: Table "ACT_HI_PROCINST" already exists; SQL statement:
-- 
-- 
-- 
-- 
create table ACT_HI_PROCINST ( 
ID_ varchar(64) not null, 
PROC_INST_ID_ varchar(64) not null, 
BUSINESS_KEY_ varchar(255), 
PROC_DEF_KEY_ varchar(255), 
PROC_DEF_ID_ varchar(64) not null, 
START_TIME_ timestamp not null, 
END_TIME_ timestamp, 
REMOVAL_TIME_ timestamp, 
DURATION_ bigint, 
START_USER_ID_ varchar(255), 
START_ACT_ID_ varchar(255), 
END_ACT_ID_ varchar(255), 
SUPER_PROCESS_INSTANCE_ID_ varchar(64), 
ROOT_PROC_INST_ID_ varchar(64), 
SUPER_CASE_INSTANCE_ID_ varchar(64), 
CASE_INST_ID_ varchar(64), 
DELETE_REASON_ varchar(4000), 
TENANT_ID_ varchar(64), 
STATE_ varchar(255), 
primary key (ID_), 
unique (PROC_INST_ID_) 
) [42101-200]

Can anyone help me understand the issue here please?

Hi @ravii,

it seems that you (accidentially?) create two process engines.

Could you please share the complete Test class here?

Cheers, Ingo

@Ingo_Richtsmeier

  @SpringBootTest(classes=Application.class)
  @ActiveProfiles("test")
  @RunWith(SpringRunner.class)
  public class FlowTest_3 {

	
	@InjectMocks
	HLRAdaptorRequestCreation creation;
	
	@Mock
	RestTemplate template;
	
	@Autowired
	 ProcessEngine engine;

Using @SpringBootTest by default autowires process engines everything for the test class but when i try to use ProcessEngineRule it complains about cfg.xml which is something required for creating process engine bean creation My query here is When ProcessEngine is auto-wired why does it look for cfg.xml ?

Also tried removing auto-wiring and using cfg.xml then when the workflow goes and the developer autowired all the process engine and runtimeservice in the JavaDelegate implementations so Their process engine scope refers to null (As cfg.xml used is only for test purposes).

Hi @ravii,

the ProcessEngineRule starts it’s own process engine with an in-memory database and injects it into the test class.

This is my favorite to write plain Junit tests, testing the expressions and tasks of the process. Here the eingie is configured from camunda.cfg.xml file.

When you start the process engine as a SpringBootTest, you get an integration test scenario. The engine will pickup the configuration from the spring boot environment e.g. application.yml, or propertiers, or whatever spring boot uses.

You can’t mix both approaches as you get the errors you already saw. The two engines confilct each other.

Hope this helps, Ingo

Hi @Ingo_Richtsmeier

Thanks again. I have expected this situation of conflict and tried removing @SpringBootTest to use cfg.xml and ProcessEngineRule. As said getting the ProcessInstance reference from ProcessEngineRule

And cfg.xml is

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

       xsi:schemaLocation="http://www.springframework.org/schema/beans   http://www.springframework.org/schema/beans/spring-beans.xsd">




    <bean id="processEngineConfiguration" class="org.camunda.bpm.extension.process_test_coverage.junit.rules.ProcessCoverageInMemProcessEngineConfiguration">


        <property name="history" value="full" />
        <property name="databaseSchemaUpdate" value="true" />
        <property name="jobExecutorActivate" value="false" />
       
        <property name="idGenerator">
            <bean class="org.camunda.bpm.engine.impl.persistence.StrongUuidGenerator"/>
        </property>
  <property name="processEnginePlugins">
            <list>
             <bean id="spinPlugin" class="org.camunda.spin.plugin.impl.SpinProcessEnginePlugin"/>       
            </list>
        </property>


    </bean>
</beans>

After this i have run the mvn clean package and as per the result it should leave HTML files of the executed flow but it doesn’t create any such files in the target folder. Is that a version conflict ?

Test is successful but it is not able to pickup the test related properties when tried with @TestPropertySource but the main concern here is the HTML files.

Hi @ravii,

your test didn’t interact with the process engine.

And you should create the rule as a @ClassRule as well:

  @Rule
  @ClassRule
  static public ProcessEngineRule rule = TestCoverageProcessEngineRuleBuilder.create().build();

What happens if you call

service.startProcessInstanceByKey("myProcessDefinitionKey", map);

?

Hope this helps, Ingo

@Ingo_Richtsmeier- That was the partial code, starting the process and getting the ProcessInstance reference as well. I have tried using @ClassRule. I’m just trying with all the possiblities as i got struck here.

Thank you @Ingo_Richtsmeier
:slight_smile:

Hi @ravii,

this branch contains an minimal example of a JUnit test with camunda-bpm-assert and proces test coverage: https://github.com/ingorichtsmeier/camunda-engine-unittest/blob/test-coverage/pom.xml

Hope this helps, Ingo