简体   繁体   English

无法从主包(Eclipse)访问测试包中的类

[英]Cannot access class in test package from main package (Eclipse)

I have a maven project in eclipse with a folder structure are follows - 我在eclipse中有一个maven项目,文件夹结构如下 -

   - 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. 我发现当我尝试从主包中的代码初始化测试包中的任何类时,我得到一个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. 否则,如果您真的想这样做,请查看用于启动程序的运行配置,并设置类路径以包含测试内容。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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