我在 JUnit5 上进行了大量测试,并在多个线程中并行运行。
还有有关每次测试时间的信息。
我想在最长的测试开始时运行,并将最快的测试留在最后以优化公共执行时间。
我还没有找到在 JUnit5 中执行此操作的方法。
版本中5.4
有一个org.junit.jupiter.api.MethodOrderer
接口允许您在测试类中编写测试排序器。并通过注解连接到测试类org.junit.jupiter.api.TestMethodOrder
.
对于整个测试套件,我想要类似的东西,但在全球范围内。
现在可以在 JUnit 5 中订购测试类(因为v5.8.0 https://junit.org/junit5/docs/5.8.0/release-notes/).
src/测试/资源/junit-platform.properties:
# ClassOrderer$OrderAnnotation sorts classes based on their @Order annotation
junit.jupiter.testclass.order.default=org.junit.jupiter.api.ClassOrderer$OrderAnnotation
其他 Junit 内置类排序器实现:
org.junit.jupiter.api.ClassOrderer$ClassName
org.junit.jupiter.api.ClassOrderer$DisplayName
org.junit.jupiter.api.ClassOrderer$Random
对于其他方式(除了junit-platform.properties文件)设置配置参数参考here https://junit.org/junit5/docs/current/user-guide/#running-tests-config-params.
您还可以提供自己的订购者。必须落实排序者类界面:
package foo;
public class MyOrderer implements ClassOrderer {
@Override
public void orderClasses(ClassOrdererContext context) {
Collections.shuffle(context.getClassDescriptors());
}
}
junit.jupiter.testclass.order.default=foo.MyOrderer
注意@Nested
测试课程不能由排序者类.
参考JUnit 5文档 https://junit.org/junit5/docs/snapshot/user-guide/index.html#class-order and 排序者类 api docs https://junit.org/junit5/docs/snapshot/api/org.junit.jupiter.api/org/junit/jupiter/api/ClassOrderer.html了解有关订购测试课程的更多信息。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)