This screen capture demonstration shows how to get unit testing up and running within a JavaFX project using IntelliJ from scratch.
Mac OS 12.6 Monterey
IntelliJ IDEA 2022.2.2 Community Edition
JUnit 5
Instructions on How to Set Up Unit Testing in a JavaFX Project in IntelliJ
-------------------------------------
1. Create a new JavaFX Project.
2. Build the new JavaFX Project.
3. Run the new JavaFX Project.
-----
4. Right-click on the project (top, left)
5. Choose "New" and then "Directory".
6. Enter name "test"
7. Right-click on the test folder, then "Mark Directory As", then choose "Test Sources Root".
8. Add a method to the "HelloApplication" Class.
public int addNumber(int a, int b) {
return a+b;
}
9. Click on the class name "HelloApplication".
10. Press ALT+ENTER.
11. Choose "Create Test".
12. Choose testing library JUNIT 5.
(Click on "Fix" if not JUNIT5 not already found.)
A new testing class is created for unit tests.
13. Add a unit test to the newly created testing class.
@Test.
public void test() {
HelloApplication test = new HelloApplication():
int result = test.addNumber(a:5, b:2);
assertEquals(7, result);
}
14. Click on the play button to the left of the new unit test
15. Choose "Run test()".
16. Try running a test with an unexpected value.