ReportPortal是否支持JUnit 3上的遗留测试?

chy5wohz  于 9个月前  发布在  其他
关注(0)|答案(1)|浏览(125)

我有一个旧项目,其中包含从3到5的所有主要代的JUnit测试。
原来,JUnit的ReportPortal代理不提供框架版本之间的向后兼容性(尽管JUnit Vintage引擎提供),所以我必须为JUnit 5和JUnit 4分别设置它们。然而,JUnit 3没有这样的代理。因此,ReportPortal看不到相应的测试类(只有较新的)。
有没有一种方法可以让ReportPortal显示遗留测试,而不需要升级它们或编写自己的自定义集成?

dced5bon

dced5bon1#

虽然在没有专用代理的情况下找到将JUnit 3测试集成到ReportPortal中的现成解决方案可能具有挑战性,但您可以考虑一种变通方法来使其工作。以下是您可以尝试的几个步骤:

**1. JUnit 3测试适配器:**由于JUnit 5支持使用junit-vintage-engine运行JUnit 3测试,因此您可以使用允许在JUnit 4和JUnit 5平台上运行JUnit 3测试的JUnit 3测试适配器。这样,您可以在JUnit 5中执行JUnit 3测试,然后ReportPortal应该能够获取结果。**2. JUnit 5 Vintage Engine:**确保您使用JUnit 5 Vintage Engine运行JUnit 3测试以及JUnit 4和JUnit 5测试。此引擎提供向后兼容性,并允许从JUnit 3运行测试。

在JUnit 5配置中,请确保包含Vintage Engine依赖项并在测试执行中使用它。以下是Gradle配置示例:

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.自定义测试执行模板:**编写一个自定义的JUnit测试执行模板,将JUnit 3测试结果转换为ReportPortal能够理解的格式。这包括在执行过程中监听测试事件,并将结果发送给ReportPortal。

下面是一个简单的Java示例:

import org.junit.platform.launcher.TestExecutionListener;


import org.junit.platform.launcher.TestIdentifier; import org.junit.platform.launcher.TestExecutionSummary;
public class TestExecution {

@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
}


}在JUnit 5配置中注册此侦听器。

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
}


}
请注意,编写自定义侦听器可能需要一些努力,并且您需要使用ReportPortal API来发送测试结果。
这些都是解决方法,有效性可能取决于JUnit 3测试的复杂性和老式引擎的兼容性。如果可能,请考虑将JUnit 3测试升级到更高版本,以获得更好的集成和支持。

相关问题