JUnit:@Before只针对一些测试方法? [英] JUnit: @Before only for some test methods?

查看:224
本文介绍了JUnit:@Before只针对一些测试方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些常见的设置代码,我已经考虑了一个标有 @Before 的方法。但是,并非所有这些代码都必须针对每个测试运行。有没有办法标记它,所以 @Before 方法只在某些测试之前运行?

I have some common set up code that I've factored out to a method marked with @Before. However, it is not necessary for all this code to run for every single test. Is there a way to mark it so the @Before method only runs before certain tests?

推荐答案

将不需要设置代码的测试移出到单独的测试类中。如果你有一些常见的测试常用的代码,那就把它移到一个帮助类中。

Just move out the tests that don't need the setup code into a separate test class. If you have some other code common to the tests that would be helpful to keep, move that out into a helper class.

这篇关于JUnit:@Before只针对一些测试方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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