Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 9 years ago.
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
接受
或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
发布评论
评论(5)
我发现您正在使用 Eclipse,但是您是否还使用其他一些外部构建/测试工具,例如 Ant 或 Maven?有时,当同时使用其他外部工具时,Eclipse 可能会不同步。
如果您使用外部工具,请采取一切必要措施来清理生成的工件(例如 mvn clean)。然后刷新 Eclipse 项目并按照之前的建议进行全新构建。然后尝试使用 Eclipse 再次运行单元测试。
祝你好运,希望这会有所帮助。
I see that you are using Eclipse, but are you also using some other external build/test tool like Ant or Maven? Sometimes Eclipse can get out of sync when also using other external tools.
If you are using external tools, do whatever is necessary to clean up generated artifacts (e.g. mvn clean). Then refresh the Eclipse project and do a clean build as suggested previously. Then try running your unit test again using Eclipse.
Good luck and hope this helps.
JVM 无法找到类测试。类名是否正确。我的意思是它不是 com.example.Test 吗?
JVM is not able to find the class test. is the class name correct. I mean is it not com.example.Test?
检查 JUnit 测试的运行配置。在类路径选项卡中,恢复默认条目一次,以防情况并非如此。
在项目属性中,检查 junit 包和类源文件夹是否都在源包中,并且在预期的目标文件夹中存在被测试类的实际类编译。
Check run config of the JUnit test. In the classpath tab, resotre default entries once in case that is not the case already.
In project properties check if both junit package and classes source folder is in the source package and there is an actual class compilation existring for the class under test in your expected target folder.
我有类似的问题,问题是由于外部库(例如 Selenium 服务器)的构建路径损坏。
因此,首先请打开构建路径(右键单击项目 -> 构建路径 -> 配置构建路径)并验证所有外部库是否可以成功加载(有“无法加载”之类的消息)。最有可能的是,在优化或添加 Ant 等外部工具时,库被重命名/移动。
希望这会有所帮助,并且会节省您四处寻找的时间:)
WBR,
安德烈
I had similar issue and problem was because of broken build paths to external libraries (e.g. Selenium server).
So first of all please open Build path (right click project -> Build Path -> Configure Build Path) and verify that all external libraries can be loaded successfully (there are messages like 'cannot load'). Most likely a library was renamed/moved while optimization or adding external tools like Ant.
Hope this helps and it will save your time goggling around :)
WBR,
Andrey
如果你使用maven来构建你的项目,那么它会将所有编译的java类放在目标/类下的文件夹中,并将测试类放在目标/测试类下。所以我猜 Eclipse 将无法从目标/测试类中找到类。如果您想从 Eclipse 运行 JUnit 类,请使用 Eclipse->Project->clean,然后您将在 Eclipse 中配置同一目标下的所有类。
If you use maven to build your project then it puts all compiled java classes in folder like target/classes and Test classes under target/test-classes. So I guess eclipse won't able to find classes from target/test-classes. If you want to run JUnit classes from Eclipse, use Eclipse->Project->clean and then you will have all classes under same target configured in eclipse.