JUnit @忽略有用性吗? [英] JUnit @Ignore usefulness?

查看:78
本文介绍了JUnit @忽略有用性吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在JUnit中,您可以在方法之前使用@Ignore来告诉测试运行器自动跳过那些测试.据我所知,这实际上只是记录/标记不完整/不再需要的功能测试的一种便捷方法.

In JUnit you can use @Ignore before methods to tell the test runner to automatically skip those tests. From what I can gather, this is really only a convenient way to document/mark off incomplete/no longer functional tests that you want to get back to later.

那么我是否正确地说,在运行时@Ignore测试,没有注释的方法和注释掉的方法之间没有区别? (假设这些测试都是自包含的.)是否有某种方法可以在Netbeans的JUnit中获取被忽略的测试用例的列表?如果不是,@Ignore标签实际上有多少用处,因为通过测试可能会更有用,这样它就不会被忽略?

Am I correct in saying then, that at runtime there is no difference between an @Ignore test, a method with no annotation, and a commented out method? (Assuming these tests are all self contained.) Is there some way to obtain a list of the ignored test cases in JUnit on Netbeans? If not, how much usefulness does the @Ignore tag really have, since it might be more useful to fail the test so it's not overlooked?

推荐答案

我是否正确地说,在运行时@Ignore测试,无注释的方法和注释掉的方法之间没有区别?

Am I correct in saying then, that at runtime there is no difference between an @Ignore test, a method with no annotation, and a commented out method?

可以通过反射找到@Ignore d方法.没有注释的方法不能(或者,确切地说,不能确定地将其识别为被忽略的测试方法),注释掉的方法甚至都不会进入字节码.

An @Ignored method can be found via reflection. A method with no annotation can't (or, to be precise, it can't be identified with certainty as an ignored test method), and a commented out method does not even get into the bytecode.

尽管我认为寻找@Ignore d方法运行时并没有太大的实用价值,但生成统计信息/报告可能会很有用.

Albeit I don't think there would be much practical value in finding @Ignored methods runtime, it may be useful to generate statistics / reports.

@Ignore标记实际上有多少用处

how much usefulness does the @Ignore tag really have

我能想到的一件事就是可搜索性.您可以轻松地识别源代码中的所有@Ignore批注,而未注释或注释掉的测试却不那么容易找到.

One thing I can think of is searchability. You can easily identify all @Ignore annotations in the source code, while unannotated or commented out tests are not so simple to find.

通过测试可能会更有用,因此它不会被忽略吗?

it might be more useful to fail the test so it's not overlooked?

如果您想(并且可以)立即修复它,则可以使其失败.在某些情况下,您可能无法做到,但您仍然希望方法始终存在,以确保不会被遗忘.然后@Ignore才有意义.

If you want (and can) fix it right away, it is fine to have it fail. There are cases when you can't, but you still want to method to be around, precisely so that it does not get forgotten. Then @Ignore makes sense.

这篇关于JUnit @忽略有用性吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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