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

霸气de小男生 提交于 2019-12-12 11:14:00

问题


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 ?


回答1:


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.



来源:https://stackoverflow.com/questions/11027100/cannot-access-class-in-test-package-from-main-package-eclipse

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!