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

Tutorial Set Up JUnit Tests

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)
13 views9 pages

Tutorial Set Up JUnit Tests

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
You are on page 1/ 9

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

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy