MPI-JUnit
MPI-JUnit [1] is a JUnit 4 Runner which allows you to write and configure tests for MPI programs. By simply adding Java annotations, your test classes will be executed as an MPI program.
@RunWith(MpiRunner.class) // Use the MpiRunner to run the test
@MpiConfig(ranks=4) // Specify how many ranks you want your test to run with
public class MyTestClass {
@Test
public void testMultipleHosts() {
assertTrue(MPI.COMM_WORLD.Size() > 1);
}
}
Custom Junit4 runner - the general idea
Using a custom Junit runner, instead of calling the Test methods “directly”, you can launch your custom command using a ProcessLauncher
. In my implementation, I made every MPI process use the normal Junit4 runtime to run the test methods. However, instead of using the normal RunNotifier
of the Junit runtime, the MPI processes use my custom ToFileRunNotifier
which writes the calls it receives to a file. A file with the calls received from each rank is saved before the MPI process that ran the test class completes.
Back in my custom runner, I aggregate the results of each test method of each MPI process and transmit those to the normal RunNotifier.
Benefits
With this system, you are staying within the “normal” Junit4 framework. In my case I was trying to run Junit tests from Maven. I can also integrate the test results with the Eclipse Junit view successfully. Here is a capture of my Eclipse environment after running the tests.

Acknowledgment
This project was made possible with the help of some StackOverflow users who took the time to respond to my questions and or had posted related questions:
References
- Experience in testing MPI-Java parallel and distributed programs with JUnitJul 2021SWoPP 2021 第135回Pro研究発表会
Enjoy Reading This Article?
Here are some more articles you might like to read next: