选择执行JUnit测试的顺序 [英] Choose order to execute JUnit tests

查看:67
本文介绍了选择执行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测试的顺序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆