Does ReportPortal support legacy tests on JUnit 3?

30 Views Asked by At

I have an old project covered with JUnit tests of all the major generations from 3 to 5. Now I'd like to export the test results into locally deployed ReportPortal.

It turned out that ReportPortal agents for JUnit do not provide backward compatibility between the framework versions (despite JUnit Vintage engine does), so I have to set them up separately for JUnit 5 and Junit 4. However, there is no such agent for JUnit 3. As a result, ReportPortal doesn't see corresponding test classes (only the newer ones).

Is there a way to make ReportPortal display the legacy tests as well without upgrading them or writing my own custom integration?

1

There are 1 best solutions below

1
Sambhu Dayal Sharma On

While it might be challenging to find a ready-made solution for integrating JUnit 3 tests into ReportPortal without a dedicated agent, you can consider a workaround to make it work. Here are a few steps you can try:

1. JUnit 3 Test Adapter: Since JUnit 5 provides support for running JUnit 3 tests using the junit-vintage-engine, you might be able to use a JUnit 3 Test Adapter that allows running JUnit 3 tests on JUnit 4 and JUnit 5 platforms. This way, you can execute your JUnit 3 tests within JUnit 5, and then ReportPortal should be able to pick up the results. 2. JUnit 5 Vintage Engine: Ensure that you are using the JUnit 5 Vintage Engine to run your JUnit 3 tests alongside JUnit 4 and JUnit 5 tests. This engine provides backward compatibility and allows running tests from JUnit 3.

In your JUnit 5 configuration, make sure to include the Vintage Engine dependency and use it in your test execution. Here's an example Gradle configuration:

dependencies {
testImplementation 'junit:junit:3.8.2' // JUnit 3
testImplementation 'junit:junit:4.13.2' // JUnit 4
testImplementation 'org.junit.vintage:junit-vintage-engine:5.8.2' // JUnit 5 Vintage Engine

}

3. Custom Test Execution Listener: Write a custom JUnit Test Execution Listener that converts JUnit 3 test results into a format that ReportPortal understands. This involves listening to the test events during execution and sending the results to ReportPortal.

Here's a simplified example in Java:

import org.junit.platform.launcher.TestExecutionListener;

import org.junit.platform.launcher.TestIdentifier; import org.junit.platform.launcher.TestExecutionSummary;

public class ReportPortalListener implements TestExecutionListener {

@Override
public void executionFinished(TestIdentifier testIdentifier, TestExecutionSummary testExecutionSummary) {
    // Convert JUnit 3 test results to ReportPortal format and send them to ReportPortal
    // You may need to use ReportPortal API for this
}

} Register this listener in your JUnit 5 configuration.

import org.junit.platform.launcher.listeners.TestExecutionSummaryFailureListener;

public class MyTest {

@RegisterExtension
static TestExecutionSummaryFailureListener failureListener = new TestExecutionSummaryFailureListener();

@Test
void myTest() {
    // Your JUnit 3 test code here
}

}

Please note that writing a custom listener may require some effort, and you'll need to use the ReportPortal API to send test results.

These are workarounds, and the effectiveness may depend on the complexity of your JUnit 3 tests and the compatibility of the vintage engine. If possible, consider upgrading your JUnit 3 tests to a later version for better integration and support.