Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot access class in test package from main package (Eclipse)

I have a maven project in eclipse with a folder structure are follows -

   - Project

    > src/main/java ..

    > src/test/java ..

I found that when I try to initialize any class in the test package from my code in the main package I get a classNotFoundException.

I want to know why this happens and what is the reason for not allowing access to test classes from the main package ?

like image 728
Hari Reddy Avatar asked Jun 14 '12 05:06

Hari Reddy


1 Answers

If your main code needs code in the test folder, then the code in the test folder is not a "test", it is main code. The point of test is that it is independent from your main code and not an integral part.

Otherwise, if you really want to do it, look at the Run Configuration you are using to launch your program and set the classpath to include the test stuff.

like image 78
Steve H. Avatar answered Nov 14 '22 18:11

Steve H.