JUnit @Ignore usefulness?

后端 未结 6 1512
没有蜡笔的小新
没有蜡笔的小新 2021-02-05 11:47

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

6条回答
  •  无人及你
    2021-02-05 12:28

    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?

    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.

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

    how much usefulness does the @Ignore tag really have

    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?

    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.

提交回复
热议问题