PMD规则之Junit Rules

·  JUnitStaticSuite: The suite() method in a JUnit test needs to be both public and static.

翻译   Junit静态套件:在Junit测试中suite()方法需要是公共的和静态的

 

·  JUnitSpelling: Some JUnit framework methods are easy to misspell.

翻译   Junit拼写:一些Junit框架方法容易拼写错误。

·  JUnitAssertionsShouldIncludeMessage: JUnit assertions should include a message - i.e., use the three argument version of assertEquals(), not the two argument version.

翻译   Junit断言应该包含提示信息:Junit断言应该包含提示信息-比如你应该使用三个参数的assertEquals()方法,而不使用两个参数的。

·  JUnitTestsShouldIncludeAssert: JUnit tests should include at least one assertion. This makes the tests more robust, and using assert with messages provide the developer a clearer idea of what the test does.

翻译   Junit测试应该包含断言:Junit测试应该至少包含一个断言。这能让测试更健壮,而且使用附带提示信息的断言能让开发者清楚的了解测试到底做了什么。

·  TestClassWithoutTestCases: Test classes end with the suffix Test. Having a non-test class with that name is not a good practice, since most people will assume it is a test case. Test classes have test methods named testXXX.

翻译   测试类没有用例:测试类以Test作为后缀。非测试类的命名含有test作为后缀不是好的方式,因为大多数人会以为它是一个测试用例。测试类中的测试方法命名方式是testXXX

·  UnnecessaryBooleanAssertion: A JUnit test assertion with a boolean literal is unnecessary since it always will eval to the same thing. Consider using flow control (in case of assertTrue(false) or similar) or simply removing statements like assertTrue(true) and assertFalse(false). If you just want a test to halt, use the fail method.

翻译   不必要的布尔断言:包含一个布尔字面量的测试断言是不必要的,因为它总是计算同样的值。如果考虑流程控制(一旦出现assertTrue(false)或类似字眼)或仅仅移除类似assertTrue(true)assertFalse(false)等表达式。如果你只是打算测试挂起,可以使用fail方法。

·  UseAssertEqualsInsteadOfAssertTrue: This rule detects JUnit assertions in object equality. These assertions should be made by more specific methods, like assertEquals.

翻译   使用assertEquals替代assertTrue:本规则检查Junit断言在对象值上的相等性。这些断言应该由更多特定的方法组成,例如assertEquals

·  UseAssertSameInsteadOfAssertTrue: This rule detects JUnit assertions in object references equality. These assertions should be made by more specific methods, like assertSame, assertNotSame.

翻译   使用assertSame替代assertTrue:本规则检查Junit断言在对象引用上的相等性。此类断言应该由更多特定方法组成,比如:assertSameassertNotSame

·  UseAssertNullInsteadOfAssertTrue: This rule detects JUnit assertions in object references equality. These assertions should be made by more specific methods, like assertNull, assertNotNull.

翻译   使用assertNull替代assertTrue:本规则检查Junit断言对象引用的相等性,此类断言应该由更多特定方法组成,比如:assertNullassertNotNull

 

·  SimplifyBooleanAssertion: Avoid negation in an assertTrue or assertFalse test. For example, rephrase: assertTrue(!expr); as: assertFalse(expr);

翻译   简化布尔断言:避免在assertTrueassertFalse方法测试时使用反向表达,比如:将assertTrue(!expr)换成assertFalse(expr)来表达

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值