本文介绍了选择执行 JUnit 测试的顺序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想选择执行 JUnit 测试的顺序.我有 4 个类,其中有几个测试方法,我的目标是执行,例如,A 类的方法 Y,然后是 B 类的方法 X,最后是 A 类的方法 Z.

I wanted to choose the order to execute the JUnit tests.I have 4 classes with several test methods in it, my goal is to execute, for instance, method Y of class A, then method X from class B, and finally method Z from class A.

你能帮忙吗?

推荐答案

通常,您不能指定单独的单元测试运行的顺序(尽管您可以在 TestNG 中指定优先级并为每个测试指定不同的优先级).但是,单元测试应该能够独立运行,所以测试的顺序应该无关紧要.这是一个不好的做法.如果您需要按特定顺序进行测试,则应该重新考虑您的设计.如果您详细说明为什么需要订单,我相信我们可以提供建议.

In general, you can't specify the order that separate unit tests run in (though you could specify priorities in TestNG and have a different priority for each test). However, unit tests should be able to be run in isolation, so the order of the tests should not matter. This is a bad practice. If you need the tests to be in a specific order, you should be rethinking your design. If you post specifics as to why you need the order, I'm sure we can offer suggestions.

这篇关于选择执行 JUnit 测试的顺序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-03 19:44
查看更多