如何预先定义junit测试用例的运行顺序? [英] How to pre-define the running sequences of junit test cases?

查看:133
本文介绍了如何预先定义junit测试用例的运行顺序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在java中有一个测试类,有几个@Test注释的方法,不知何故,我想在方法B之前运行方法A,当我运行整个测试时。是可能还是必要?

I have a test class in java and there are several methods annotated by @Test in it, somehow, i want to Junit run method A before method B when i run the whole tests. Is it possible or necessary?

推荐答案

这种对测试方法的依赖是糟糕的设计,应该避免。如果在一个测试方法中存在需要为下一个测试方法完成的初始化代码,则应将其考虑在setUp方法中。

This sort of dependency on test methods is bad design and should be avoided. If there is initialization code in one test method that needs to be done for the next, it should be factored out into a setUp method.

这篇关于如何预先定义junit测试用例的运行顺序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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