Java Learning Chapter (IV)---on JUnit 3.8

Source: Internet
Author: User

1. Best practices for using JUnit:

1)

Create a new source folder named Test that holds the source code for the testing class

2)

The target class should be under the same package as the test class, so you don't have to import the source code in the test class

In the package, because they are located under the same package

3)

Test class naming rules: If the target class is Calculator, then the test class should be named

Testcalculator, or Calculatortest.

2.Junit slogan: Keep the bar green to keep the code clean.

3.Junit: Unit tests are not meant to prove that you are right, but to prove that you have no errors.

4. Test Cases (TestCase) are a very important aspect of unit testing.

5. Unit testing is primarily used to determine whether the execution of the program is consistent with the results you expect.

6. The test class must inherit from the TestCase parent class

7. in junit 3.8 , the test method needs to meet the following principles:

1 ) . Public of the

2 ) . void of the

3 ) . No method parameters

4 ) . the method name must be Test Start

The 8.Test case must remain completely independent and not allow any dependencies.

9. We cannot rely on the order in which the test methods are executed.

10.DRY (Don ' t Repeat yourself).

The order of execution of the setUp and tearDown methods:

1 )

SetUp

2 )

Testadd

3 )

Teardown

12. Test Runner

Junit.awtui.TestRunner.run (Calculatortest.class);

Junit.textui.TestRunner.run (Calculatortest.class);

Junit.awtui.TestRunner.run ( class name of the test . Class)

graphical Test interface appears .


Junit.textui.TestRunner.run ( class name of the test . Class)

The console interface appears ... ..


Java Learning Chapter (IV)---on JUnit 3.8

Related Article

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.