Use JUnit in IDEA 2017.2.2 environment, 2017.2.2junit

Source: Internet
Author: User
Tags grails

Use JUnit in IDEA 2017.2.2 environment, 2017.2.2junit

JUnit: unit test framework. The test object is a method in a class.

JUnit is not part of Javase. To use the jar package that needs to be imported, you must use the JUnit plug-in IntelliJ IDEA.

JUnit version 3.X 4.X

I. JUnit environment Configuration:

1. Plug-in loading Selection

2. Search for the plug-in JUnit and download Grails, JUnit, and JUnitGenrator V2.0. skip this step if you have downloaded the plug-in.

3. Select the loading plug-ins Grails, JUnit, and JUnitGenrator V2.0.

4. Click OK in the lower-right corner of the screen and restart IDEA to load the plug-in.

Ii. Simple unit test example

1. Create a package named testjunit under src and create a class in the package.

2. Create a folder named test in the src directory at the same level, right-click and select Test Sources Root,

Create a package with the same name as the testjunit package in the folder and create a test class.

3. Create a test method in TestDemo. class:

① Method naming rules for unit test methods: public void method name (){}

Note that the method name cannot have parameters.

② Run the Test method in Annotation mode. On the Method: @ Test; if there is no annotation, a running exception occurs.

③ Select a method name, right-click debugging, and press ctrl + shift + D.

④ If a green bar appears, the method test is successful.

If a red bar appears, the test method fails.

Iii. Automatic Unit Testing

1. automatically generate a unit test. The shortcut key is Command + Shift + T.

2. Select related configurations

3. automatically generate the following template

4. Run the test

Iv. Annotations

@ Test: indicates the unit Test of the method.

@ Ignore: indicates that no unit test is performed for the method.

@ Before: run the command Before each method.

@ After: Run After each method

 

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.