Create a Java project for IDEA
Write a class with an Add method
To Generate the test class, right-click on the class name and select Generate
Select the Test Test class
Prompt to create the root of the test class
The junit5 jar package was not found. Click Fix to Fix the problem
Prompt to download in the warehouse
Download complete, no more problems with this package. You can choose either the add method or the setUp/ @before method
If a message is displayed indicating that the class is not found and you need to import the class, press Alt +Enter on the red class name to import the specified package.
Select the 5.3 package.
The code for the test class is as follows:
import static org.junit.jupiter.api.Assertions.*;
class MainTest {
@org.junit.jupiter.api.BeforeEach
void setUp(a) {}@org.junit.jupiter.api.Test
void add(a) {
assertEquals(2.new Main().add(1.1)); }}Copy the code
The successful running