While there is no only right way, the usual approach is to keep unit tests in the same project.
You can create a second source folder (like test
), where you put your test classes into the same packages as the classes under test. This also allows you to test package-private classes while not flooding your main source packages with test classes.
Your source folder/package structure would then look like this:
-sources
-main
-my.package
-MyClass.java
-test
-my.package
-MyClassTest.java
You can then configure your build to not include the test
source folder when packing the JAR.
manpreet
Best Answer
2 years ago
This is a relatively open question. If I have built an application in a project in Eclipse and I then want to test this project, should I create the JUnit code within the same project or create a separate project. For instance...
ShopSystem
maybe the name of my main project - should I create a project called say,ShopSystemTest
?In general - how far "away" should the testing">testing code be stored from the main project folder? If I store the testing">testing code within the main project and then export the main project as a runnable jar it will take the testing">testing code with it, which isn't ideal...
Suggestions?