The JUnit rules of the PMD rule

Source: Internet
Author: User

· Junitstaticsuite:the Suite () method in a JUnit test needs to is both public and static.

Translation JUnit Static Suite: The Suite () method needs to be public and static in JUnit testing

· Junitspelling:some JUnit Framework methods are easy to misspell.

JUnit spelling: Some JUnit framework methods are easy to spell incorrectly.

· Junitassertionsshouldincludemessage:junit assertions should include a message-i.e., use the three argument version of a Ssertequals (), not the two argument version.

The JUnit assertion should contain a hint: the JUnit assertion should contain a hint-for example, you should use the three-parameter Assertequals () method instead of using two parameters.

· Junittestsshouldincludeassert:junit tests should include at least one assertion. This is makes the tests more robust, and using Assert with messages provide the developer a clearer idea of what the test doe S.

The JUnit test should contain assertions that JUnit tests should contain at least one assertion. This makes testing more robust, and using an assertion with accompanying hints can give developers a clear idea of what the test is doing.

· Testclasswithouttestcases:test classes end with the suffix Test. Has a non-test class with this name is not a good practice, since most people'll assume it is a test case. Test classes have test methods named Testxxx.

There are no use cases for translation Test classes: Test classes are appended with test. The name of the non-test class contains test as a suffix is not a good way, because most people would think it is a test case. The test method in the test class is named Testxxx.

· Unnecessarybooleanassertion:a JUnit Test Assertion with A Boolean literal is unnecessary since it always'll eval to the Same thing. Consider using Asserttrue (false) or similar) or simply removing statements like asserttrue (true) and Assertfalse (false). If you are just want a test to halt, use the Fail method.

Translation of unnecessary Boolean assertions: A test assertion that contains a Boolean literal is unnecessary because it always computes the same value. Consider Process Control (if Asserttrue (false) or similar words appear) or simply remove expressions such as asserttrue (true) and Assertfalse (false). If you are just going to test the suspend, you can use the Fail method.

· Useassertequalsinsteadofasserttrue:this rule detects the JUnit assertions in object equality. These assertions should are made by the more specific methods, like assertequals.

Translation uses assertequals instead of asserttrue: This rule examines the equality of junit assertions over object values. These assertions should be made up of more specific methods, such as Assertequals.

· Useassertsameinsteadofasserttrue:this rule detects the JUnit assertions in object references equality. These assertions should are made by the more specific methods, like Assertsame, Assertnotsame.

Translation uses Assertsame instead of asserttrue: This rule examines the equality of JUnit assertions over object references. Such assertions should be made up of more specific methods, such as: Assertsame,assertnotsame

· Useassertnullinsteadofasserttrue:this rule detects the JUnit assertions in object references equality. These assertions should are made by the more specific methods, like Assertnull, Assertnotnull.

Translation uses Assertnull instead of asserttrue: This rule examines junit assertions about equality of object references, and such assertions should be made up of more specific methods, such as: Assertnull,assertnotnull

· Simplifybooleanassertion:avoid negation in a asserttrue or Assertfalse test. For example, Rephrase:asserttrue (!expr); As:assertfalse (expr);

Simplified Boolean assertion: Avoid using reverse expression when asserttrue or Assertfalse method tests, for example: Replace Asserttrue (!expr) with assertfalse (expr) to express

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.