JUnit Unit Test

Source: Internet
Author: User

1) What junit? JUnit is a professional tool for writing test code.   2) Steps to build a JUnit test class 2.1 New-"Junit Test case" 2.2 Write the test class name (recommended test+ target class name), select the target class, next 2.3 Select the method you want to test-finish 2.4 Generate a JUnit test class and import the JUnit jar package 3) JUnit test method rules 3.1 Add @test annotations to the method 3.2 Method modifier must be public, return must void, no formal argument, can throw exception 3.3 The name of the method name is not mandatory, but the Test+ method name is recommended   4) How JUnit works 4.1 Click Method, right-"Junit Test (Run a method) 4.2 Click Class, right-"JUnit test (all methods in running Class) 4.3 Click Project, right-"Junit test (method of running all classes in project) 5) View test results look at JUnit's navigation bar. Green: Test passed Red: Test does not pass   6) Decision result target method with return value: Using Assertions assert class: An assertion class used to determine the result Assertequals (expected, actual value); compare by using the Equals method Asserttrue (Boolean); Assertfalse (Boolean); Assertsame (expectation, actual value) using = = Comparison No need to do anything if there is no target method to return the value 7) A few notes commonly used annotations for @Test test methods @Before Call this before method before calling each method of the current class @After calls this after method after each method of the current class is called @BeforeClass Call 1 times @beforeclass method before calling all methods of the current class, you need to take the method with the static @AfterClass Call the @ @AfterClass Method 1 times after calling all methods of the current class, you need to take the method with the static

JUnit Unit Test

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.