如何忽略CheckStyle警告缺少测试方法的@throws? [英] How to ignore CheckStyle warning for missing @throws for test method?

查看:287
本文介绍了如何忽略CheckStyle警告缺少测试方法的@throws?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我为CheckStyle警告所困扰,因为它警告测试方法的JavaDoc中缺少@throws.

I'm being plagued by CheckStyle warnings about missing @throws in the JavaDoc of test methods.

我正在使用这样的测试方法:

I'm using writing a test method like this:

/**
 * Check that something works. <== CheckStyle wants @throws here
 */
@Test
public void testSomething() throws Exception {
  ...
}

是否可以通过一种可配置的方式告诉CheckStyle忽略它?

Is there a configurable way to tell CheckStyle to ignore this ?

"throws"子句在那里(尤其是),因为它是一种测试方法;通常会忽略异常处理.

The "throws" clause is there especially because it is a test method; where typically exception handling is ignored.

推荐答案

是.您可以为特定文件的检查样式错误指定抑制过滤器.请参见 Checkstyle 5.5的SuppressionFilter部分.从那里

Yes. You can specify a suppression filter for checkstyle errors for particular files. See Checkstyle 5.5, section SuppressionFilter. From there,

Filter SuppressionFilter根据文件中的禁止XML文档拒绝检查错误的审核事件.如果没有配置的禁止文件,则过滤器将接受所有审核事件.

Filter SuppressionFilter rejects audit events for Check errors according to a suppressions XML document in a file. If there is no configured suppressions file, the Filter accepts all audit events.

<module name="SuppressionFilter">
    <property name="file" value="docs/suppressions.xml"/>
</module>

抑制文件XML文档包含一组抑制元素,其中 每个抑制元素可以具有以下属性:

A suppressions XML document contains a set of suppress elements, where each suppress element can have the following attributes:

  • files-与文件名匹配的正则表达式 与审核事件相关联.这是强制性的.
  • 检查-a 正则表达式与关联的支票名称匹配 与审核事件.如果指定了id,则为可选.
  • id-字符串 与与审核事件相关联的支票的ID相匹配. 如果指定了检查,则为可选.
  • 行-逗号分隔的列表 值,其中每个值是一个整数或一个整数范围,表示为 通过整数整数.这是可选的.
  • 列-逗号分隔 值列表,其中每个值都是整数或整数范围 用整数整数表示.它是可选的.
  • files - a regular expression matched against the file name associated with an audit event. It is mandatory.
  • checks - a regular expression matched against the name of the check associated with an audit event. Optional if id is specified.
  • id - a string matched against the id of the check associated with an audit event. Optional if checks is specified.
  • lines - a comma-separated list of values, where each value is an integer or a range of integers denoted by integer-integer. It is optional.
  • columns - a comma-separated list of values, where each value is an integer or a range of integers denoted by integer-integer. It is optional.

针对每个抑制元素检查每个审核事件.它是 如果所有指定的属性都与审核事件匹配,则取消显示.

Each audit event is checked against each suppress element. It is suppressed if all specified attributes match against the audit event.

因此,在您的情况下,您可以执行以下操作:

So in your case, you could do something like:

<suppressions>
   <suppress checks="JavadocStyleCheck" files="*Test.java"/>
</suppressions>

我不确定JavadocStyleCheck是否真的是您要删除的支票,但请查看文档以了解更多信息.

I'm not sure if JavadocStyleCheck is really the check you want to remove, but look in the documentation for more.

这篇关于如何忽略CheckStyle警告缺少测试方法的@throws?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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