简体   繁体   English

如何使用 Junit5 在 junit 4 中创建测试套件

[英]how to create test suite as in junit 4 using Junit5

as we are upgrading to junit5 from junit4 for unit testing purpose, i couldn't able to find solution to creating a test suite in junit5 like in junit4: below is the our junit4 suite class:由于我们出于单元测试目的从junit4升级到junit5,我无法找到在junit5中创建测试套件的解决方案,就像在junit4中一样:下面是我们的junit4套件class:

@RunWith(Suite.class)
@SuiteClasses({ 
    ClassA.class, 
    ClassB.class, 
    ClassC.class 
    } )
public class TestSuite {

}

The Code i tried after searching around is below:我搜索后尝试的代码如下:

@RunWith(JUnitPlatform.class)

@SelectClasses( { 
    OrderAnnotationAlphanumericExperiment.class, 
    orderAnnotationExperiment.class, 
    ParameterizedAnnotation.class 
    } )
public class TestSuite {
    

}

on searching for the solution, most of them were providing a solution of using the same test suite to run it using vintage api, but what am looking for is to create test suite in junit 5.在寻找解决方案时,他们中的大多数都提供了使用相同的测试套件使用老式 api 运行它的解决方案,但我正在寻找的是在 junit 5 中创建测试套件。

Few suggesting @ExtendsWith(SpringExtension.class) , but there is also less documentation for it, couldn't able to find a solution to create a suite in junit 5很少有人建议@ExtendsWith(SpringExtension.class) ,但它的文档也较少,无法找到在 junit 5 中创建套件的解决方案

few blogs/question/sites i referred:我提到的几个博客/问题/网站:

Create TestSuite in JUnit5 (Eclipse) Are test suites considered deprecated in JUnit5? 在 JUnit5 (Eclipse) 中创建 TestSuite 测试套件在 JUnit5 中是否被视为已弃用? https://howtodoinjava.com/junit5/junit5-test-suites-examples/ https://howtodoinjava.com/junit5/junit5-test-suites-examples/

some one help me out to solve this problem.有人帮我解决这个问题。

It's actually pretty easy.这实际上很容易。 The following will find all JUnit tests in directory foo.bar.tests as well as it's subdirectories:以下将在目录foo.bar.tests及其子目录中找到所有 JUnit 测试:

import org.junit.platform.runner.JUnitPlatform;
import org.junit.platform.suite.api.SelectPackages;
import org.junit.platform.suite.api.SuiteDisplayName;
import org.junit.runner.RunWith;

@RunWith(JUnitPlatform.class)
@SuiteDisplayName("JUnit Platform Suite Demo")
@SelectPackages("foo.bar.test")
public class FullTestSuite 

} }

See Sec 4.4.4 of the User's Guide .请参阅用户指南的第 4.4.4 节

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM