0% found this document useful (0 votes)
3 views9 pages

JUnit Tutorial for IntelliJ Users

This tutorial provides a step-by-step guide for using JUnit in IntelliJ, covering both the use of existing unit test classes and the creation of new unit tests. It details the process of setting up a test directory, adding JUnit to the classpath, and generating test methods. The tutorial emphasizes the importance of maintaining a clean separation between test and source files.

Uploaded by

bzb0z6c5m
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views9 pages

JUnit Tutorial for IntelliJ Users

This tutorial provides a step-by-step guide for using JUnit in IntelliJ, covering both the use of existing unit test classes and the creation of new unit tests. It details the process of setting up a test directory, adding JUnit to the classpath, and generating test methods. The tutorial emphasizes the importance of maintaining a clean separation between test and source files.

Uploaded by

bzb0z6c5m
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Tutorial: Working with JUnit in IntelliJ

This step-by-step-tutorial demonstrates using exiting unit test classes (first


section) as well as creating new unit tests for your code (second section).

Using existing JUnit tests


1. Create a new, empty IntelliJ project.
2. Open your project’s module settings:

3. Select Modules, then Sources and Right-Click in the empty area to create
a new folder:

1
4. Name your folder test:

5. Click on your newly created folder and mark it as test directory as seen
below:

6. You can now copy the existing test files into the test folder:

2
7. Open the test classes and write an appropriate package name in the first
line. Use Alt+Enter to automatically move it:

8. Next click on the JUnit error below and use Alt+Enter for hints. Select
Add JUnit ‘5.7.0’ to classpath:

9. Select OK in the Download Library. . . dialog:

3
10. You can now start coding! Click on one of the missing classes and hit
Alt+Enter to create it:

11. Make sure to select src as destination directory for the classes - we want a
clean separation between test and source files!

4
12. Your structure should now look something like this:

Creating new JUnit tests for your code


1. Open your project’s module settings:

5
2. Select Modules, then Sources and Right-Click in the empty area to create
a new folder:

6
3. Name your folder test:

4. Click on your newly created folder and mark it as test directory as seen
below:

5. Get back to your code, click anywhere and hit Alt+Enter to open the
Generate-menu. Select Test. . . .

7
6. Select the following settings - and make sure to hit the Fix button.

7. Select OK in the Download Library. . . dialog:

8
8. Now that your test class is created, you can click anywhere in it and use
Alt+Enter to generate test methods:

You might also like