Setting up
Prerequisites
-
JDK 11
-
IntelliJ IDE
Importing the project into IntelliJ
-
Fork this repo, and clone the fork to your computer
-
Open IntelliJ (if you are not in the welcome screen, click
File
>Close Project
to close the existing project dialog first) -
Set up the correct JDK version
-
Click
Configure
>Project Defaults
>Project Structure
-
If JDK 11 is listed in the drop down, select it. If it is not, click
New…
and select the directory where you installed JDK 11 -
Click
OK
-
-
Click
Import Project
-
Locate the project directory and click
OK
-
Select
Create project from existing sources
and clickNext
-
Rename the project if you want. Click
Next
-
Ensure that your
\src
and\test\java
folders are checked. Keep clickingNext
-
Click
Finish
-
Add JUnit 5 to classpath
-
Open any test file in
\test\java
and place your cursor over any@Test
highlighted in red -
Press ALT+ENTER and select
Add 'JUnit5.3' to classpath
(if5.3
is not available, any5.x
will suffice) -
Select
org.junit.jupiter:junit-jupiter-api:5.40
from the dropdown and clickOK
(if5.40
is not available, choose any5.4x
that is later than5.40
)
-
-
Run all the tests (right-click the
test
folder, and clickRun 'All Tests'
) -
Observe how some tests fail. That is because they try to access the test data from the wrong directory (the working directory is expected to be the root directory, but IntelliJ runs the test with
test\
as the working directory by default). To fix this issue:-
Go to
Run
→Edit Configurations…
-
On the list at the left, expand
JUnit
, and remove all the test configurations (e.g.All in test
) by selecting it and clicking on the '-' icon at the top of the list -
Expand
Templates
(orDefaults
if you are using an older version of IntelliJ before 2018.2), and ensure thatJUnit
is selected -
Under
Configuration
, change theWorking directory
to theaddressbook-level2
folder -
Click
OK
-
-
Run the tests again to ensure they all pass now
Testing
I/O tests
Windows
-
Open a DOS window in the
test
folder -
Run the
runtests.bat
script -
If the script reports that there is no difference between
ACTUAL.TXT
andEXPECTED.TXT
, the test has passed
Mac/Unix/Linux
-
Open a terminal window in the
test
folder -
Run the
runtests.sh
script -
If the script reports that there is no difference between
ACTUAL.TXT
andEXPECTED.TXT
, the test has passed
JUnit tests
-
In IntelliJ, right-click on the
test
folder and chooseRun 'All Tests'
Troubleshooting test failures
-
Problem: How do I examine the exact differences between
ACTUAL.TXT
andEXPECTED.TXT
?
Solution: You can use a diff/merge tool with a GUI e.g. WinMerge (on Windows). -
Problem: The two files look exactly the same, but the test script reports they are different.
Solution: This can happen because the line endings used by Windows is different from Unix-based OSes. Convert the ACTUAL.TXT to the format used by your OS using some utility. -
Problem: Test fails during the very first time.
Solution: The output of the very first test run could be slightly different because the program creates a new storage file. Tests should pass from the 2nd run onwards.