Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a multi-process unit testing framework / junit addon?

Imagine two servers (each within an own jvm process) which communicate using some form of messages (e.g. simple producer/consumer)

I'd like to write unit tests that will test the behaviour of these two servers.
My questions are:

  1. Are there some frameworks (or a junit addon) for this problem?
    I'd like to run a junit test class (or even a single test) in a different process? It would be cool if one unit test can easily access the variables of the other test (in a different process) using some sort of inter-process communication.
    E.g. I'd like to check if the producer really produced the things i expected, and afterwards, if the consumer consumed them. (and maybe do some fuzzing to detect some race-condition-related problems)

  2. Are there some best practice for this kind of testing?

  3. If there isn't a unit-like testing approach, how would you test such things during continous integration?

Note:
I don't want to use threads, because this may alter the behaviour (if you think of thread-safety issues)

like image 938
MRalwasser Avatar asked Aug 18 '10 14:08

MRalwasser


People also ask

Is Cactus a JUnit extension?

Cactus. Cactus is a simple test framework for unit testing server-side java code (Servlets, EJBs, Tag Libs, Filters). The intent of Cactus is to lower the cost of writing tests for server-side code. It uses JUnit and extends it.

What are JUnit extensions?

JUnit 5 extensions are related to a certain event in the execution of a test, referred to as an extension point. When a certain life cycle phase is reached, the JUnit engine calls registered extensions. Five main types of extension points can be used: test instance post-processing. conditional test execution.

How cucumber is different from JUnit?

Cucumber is in which you can do BDD Behavior Driven Development. Something like you can convert your functional use case into Cucumber story. In that sense you can also take Cucumber to be DSL for Functional Use Case Document. JUnit on other side is for unit testing which would be a method in Java.

Is JUnit included in Eclipse?

In Eclipse, you create a JUnit test case by selecting in the main window menubar File -> New -> JUnit Test Case. Once you clicked on the item, a big dialog should pop out. In the pop up you can choose the JUnit version (4 is the one we use) and the package and class name of your test case.


1 Answers

I would describe what you are looking to do as an integration test, and beyond the scope of JUnit as a framework (JUnit is only now dipping its toe into multi-thread testing, multi-process is certainly not in the feature set).

You could of course use JUnit to run such tests, but they would really be limited to a runner, the rest you have to do yourself.

Others have already pointed to the fact that you would usually mock or otherwise send artificially constructed methods to the consumer, and test what the producer produces independently at the "unit test" level.

In terms of actually testing the interaction between the producer and the consumer, one approach is to forget about the inter-process testing, and test it intra-process on one thread via some sort of Dependency Injection where the producer sends the message via some fake way that just passes it on the the consumer without anything more under the hood than in-thread method calls.

However, it seems that you want to test things that can happen with the actual inter-process stuff on top of it (race conditions and the like), which makes this all-the-more an integration test.

To approach this problem, you need to start the process and wait for it to accept a message, then your test would tell the producer what message to create and it would send it to the consumer. Then your test would ask the consumer what it got (with suitable delay).

The need here would have to be compelling for me to do it. I would go for full blown automated acceptance testing and let that encompass this level of integration.

like image 188
Yishai Avatar answered Sep 20 '22 05:09

Yishai