Mainly learn Test Driven Development (TDD) and Continuous Integration (CI). So create test classes first, instead of writing source code. Get used to this gradually.
Step 2: Create and set up the test folder test
Click the project name tictactoeapp
, right-click to create a new package, name it test
, and use it as a test.
Click the small gear in the upper right corner and enter project structure.
Then go to modules
, select sources
, mark the test
folder as a test
The result marked as a test is shown below, click apply
and exit.
Then we weill find that the test folder in the directory structure turned green.
Corresponding project structure
Note: The packages in the src
and test
folders must be the same. Here the test class TicTacToeTest
is created in test/game/
Canary Test
: This test is mainly used when creating a new test project to test whether the machine environment you are working on is configured correctly.Canary Test
is arguably the simplest test, testing things like true is true directly.If an error is reported using the annotation @Test
, there are two ways to deal with it.
classpath
, which is to be downloaded. Specifically as shown in the figure belowAs above, click the gear in the upper right corner, go to project structure -> modules -> dependencies
, select the plus sign, and add the local test jar
package
The location of the local jar package
After the import is complete, the local jar package will appear
Then we found that the @Test
annotation did not report an error, but the new problem occurred that assertTrue could not be resolved, just alt + enter import static xxx
test code
package game;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertTrue;
public class TicTacToeTest {
@Test
public void Canary() {
assertTrue(true);
}
}
The test shown above in green is successful.