Home » IntelliJ IDEA Unit Test

IntelliJ IDEA Unit Test

by Online Tutorials Library

IntelliJ IDEA Unit Test

We can run all unit tests inside the IntelliJ IDEA. IntelliJ IDEA has various unit testing frameworks like JUnit, TestNG and many more. In this section, we will understand how unit test work. Here, we are going to use JUnit 4:

Create Unit Test

Follow the steps given below to create Unit Test:

1. Create Projects

2. In src folder, create a Java class file and enter the following code.

3. Create a New Directory with name Test to perform Unit Testing.

IntelliJ IDEA Unit Test

4. Now our Project Structure will look like this.

IntelliJ IDEA Unit Test

5. Go to File->Project Structure->Module. A new window screen will open. Select the Test Directory in the Source menu to perform testing and then click Ok button.

IntelliJ IDEA Unit Test

6. Go to Navigate->Test. A Dialog box will appear.

7. Click Create New Test. A new window will open. Fill the details as given in the window. Click Ok Button.

IntelliJ IDEA Unit Test

8. New HelloWorldTest.java file will open. In this File, we have to type the following code.

9. Now Click Run. We can see the result generated in the bottom of the Editor.

IntelliJ IDEA Unit Test

You may also like