Welcome to the CSC Q&A, on our server named in honor of Ada Lovelace. Write great code! Get help and give help!
It is our choices... that show what we truly are, far more than our abilities.

Categories

+14 votes

At least one person was having real trouble adding the JUnit library to their team project.

They tried adding it to the build path in Eclipse, and then we tried adding it to the pom.xml for maven, and had issues that way too. We eventually got it to work by removing the
"test" part of the dependency in the pom.xml, but I don't think that was the proper way to fix it.

So... what's the best/easiest way to get JUnit testing set up for your (maven-based) team projects in Eclipse?

asked in CSC305 Fall 2022 by (8 points)

1 Answer

+6 votes

Here are the steps I tested that I think should work for most teams:

  1. Add the following two dependencies to your pom.xml

    <dependency>
         <groupId>org.junit.jupiter</groupId>
         <artifactId>junit-jupiter-api</artifactId>
         <version>5.9.1</version>
         <scope>test</scope>
     </dependency>
     <dependency>
         <groupId>org.junit.jupiter</groupId>
         <artifactId>junit-jupiter-engine</artifactId>
         <version>5.9.1</version>
         <scope>test</scope>
     </dependency>
    
  2. Create a "test" folder inside the "src" folder in your Eclipse project. Then create a "java" folder inside of the test folder. After this, a new little

  3. Right click on the class (probably in your data model, since JavaFX stuff isn't easy to test with JUnit), such as TerrainMap.java or GameBoard.java , and choose "New -> JUnit Test Case". The wizard it brings up should now (hopefully) default to creating the new java test file using JUnit Jupiter in the "src/test/java" source folder, instead of "src/main/java", and it should put it in the same package as your data model (which is useful for testing non-public package-level methods).

I think this is the best/easiest way to do it, but if anyone knows of other ways that worked for their team, please post them as additional answers in case they can help people who have trouble!

answered by (8 points)
...