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

问题描述 投票:0回答:1

我有一个旧项目,涵盖了从 3 到 5 代所有主要代的 JUnit 测试。 现在我想将测试结果导出到本地部署的ReportPortal中。

事实证明,JUnit 的 ReportPortal 代理不提供框架版本之间的向后兼容性(尽管 JUnit Vintage 引擎提供),因此我必须为 JUnit 5 和 Junit 4 单独设置它们。但是,JUnit 没有这样的代理3. 结果,ReportPortal看不到相应的测试类(只有较新的测试类)。

有没有办法让 ReportPortal 也显示旧版测试,而无需升级它们或编写我自己的自定义集成?

junit legacy reportportal
1个回答
0
投票

虽然在没有专用代理的情况下找到将 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 老式引擎: 确保您使用 JUnit 5 Vintage 引擎来运行 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;

导入 org.junit.platform.launcher.TestIdentifier; 导入 org.junit.platform.launcher.TestExecutionSummary;

公共类 ReportPortalListener 实现 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
}

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

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

公共类 MyTest {

@RegisterExtension
static TestExecutionSummaryFailureListener failureListener = new TestExecutionSummaryFailureListener();

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

}

请注意,编写自定义侦听器可能需要一些努力,并且您需要使用 ReportPortal API 发送测试结果。

这些是解决方法,其有效性可能取决于 JUnit 3 测试的复杂性和老式引擎的兼容性。如果可能,请考虑将 JUnit 3 测试升级到更高版本,以获得更好的集成和支持。

© www.soinside.com 2019 - 2024. All rights reserved.