简体   繁体   中英

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 ?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM