如何使Junit 4忽略基础测试类? [英] How to get Junit 4 to ignore a Base Test Class?

查看:109
本文介绍了如何使Junit 4忽略基础测试类?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有很多测试的基类,这些基类都有他们都需要的一些辅助方法.

I have a base class for many tests that has some helper methods they all need.

它本身没有任何测试,但是JUnit(在eclipse中)正在调用它的测试运行器,并抱怨没有测试方法.

It does not by itself have any tests on it, but JUnit (in eclipse) is invoking the test runner on it and complaining that there are no methods to test.

如何让它忽略此类?

我知道我可以添加一个dummyTest方法来解决该问题,但对于所有子类也将出现该方法.

I know I could add a dummyTest method that would solve the problem, but it would also appear for all the children classes.

建议?

推荐答案

用于@Ignore批注.它也适用于类. 看到这个:

Use to @Ignore annotation. It also works on classes. See this one:

@Ignore public class IgnoreMe {
                        @Test public void test1() { ... }
                        @Test public void test2() { ... }
                }

此外,您可以注释课程 包含带有@Ignore的测试方法 并且所有包含的测试都不会 被执行.

Also, you can annotate a class containing test methods with @Ignore and none of the containing tests will be executed.

来源: JUnit JavaDoc

这篇关于如何使Junit 4忽略基础测试类?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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