How to test bpm process in java codes

Hi
how we test bpm process with java codes ?

HI @rezza72,

could you be more specific on what you want to test?

Do you want to write unit tests? If yes, maybe Camunda BPM Assert is of interest to you.

Please let us know if this is what you want to achieve or what you try to test in detail.
Cheers,
Miklas

2 Likes

when i create a process with Camunda modeler , i have to deploy it and test it in camunda and follow diagram and when process arrives to (e.g userTask which a form and input number ) i have to put number in the form …
i want to know is it possible instead of i deploy bpm and test that in camunda area , i put entries in java codes and test the process ??

Hi @rezza72,

yes, it is possible. Have a look at the docs for an example: https://docs.camunda.org/manual/7.10/user-guide/testing/

I always write a Junit test before I deploy to the process into the engine.

And have a look on the latest news about camunda-bpm-assert: https://blog.camunda.com/post/2019/03/camunda-bpm-assert-300-alpha1-released/

Cheers, Ingo

2 Likes

Hi
Thanks for your guide .
But actually i’m very amateur .
I don’t know how to use Junit in my project .
I will thank you if you guide me more or suggest me a tutorial to learn that from zero to hundred .

Hi @rezza72,

there are many tutorials and How-Tos out in the internet. I suggest you pick one and play around with simple examples before integrating camunda.
One tutorial that, I think, covers quite a lot is this one:
https://www.vogella.com/tutorials/JUnit/article.html

Cheers,
Miklas

1 Like

@rezza72 here is a Spock example that gives you a bit more business friendly testing. https://github.com/DigitalState/Camunda-Spock-Testing/blob/master/BasicExample/src/test/groovy/2_Basic/CamundaHelloWorld2Spec.groovy See the repo for lots of examples from simple to complex.

1 Like

Hi again
I read these link and considered a few of unit testing .
To the extent that , now i can write an example like this :

src/main/java :

public class PrintGrade {
public String print(int grade) {
	if (grade > 93)
		return "you got A";
	else if (grade > 83)
		return "you got B";
	else if (grade > 73)
		return "you got C";
	else
		return "you got D";
}

}

src/test/java :

import static org.junit.jupiter.api.Assertions.*;

import org.junit.jupiter.api.Test;

import Main.Java.PrintGrade;

class PrintGradeTest {

@Test
void test() {
	PrintGrade pg = new PrintGrade();
	String result = pg.print(95);
	assertEquals("you got A", result);
}

}

But i can’t test any bpm files yet .
May you guide me how to test a simple bpm ??

Hi @rezza72,

have a look at the link @Ingo_Richtsmeier posted earlier. (https://docs.camunda.org/manual/7.10/user-guide/testing/) You will find examples of test cases and instructions on how to deploy your test resources. (i.e. your BPMN files)
Hope this helps!

Cheers,
Miklas

1 Like

@Miklas Unfortunately as i said i’m very newby in java .
May you give me an example of a simple project with bpmn unit testing?
My problem is I’m not familiar with the structure of the bpmn unit testing project.

Hi @rezza72,

the provided link shows very simple examples of unit testing Camunda BPM with JUnit3 and 4.
I suggest you try to get the JUnit4 example working with your project. https://docs.camunda.org/manual/7.10/user-guide/testing/#junit-4

You can access the process engine and many services through the processEngineRule. To test your bpmn file you need to deploy it for the test using the @Deployment annotatoin. https://docs.camunda.org/manual/7.10/user-guide/testing/#deploy-test-resources

Try starting an instance of your process via the runtimeService. You can use all of the Camunda Java API to manipulate your instance. (e.g. start process instances, complete tasks, etc.) Test your process with JUnit similar to what is done in the example test.

    TaskService taskService = processEngineRule.getTaskService();
    Task task = taskService.createTaskQuery().singleResult();
    assertEquals("My Task", task.getName());

Also have a look at some of our tests if you like. https://github.com/camunda/camunda-bpm-platform/tree/master/engine/src/test/java/org/camunda/bpm/engine/test

Cheers,
Miklas