在 mvn 安装之前使用 Eclipse 运行 Junit 时,无法看到 .java 文件中的更改
我有多模块 Maven 项目。我使用的技术是Spring和Struts。我创建了测试用例并运行它:
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = { "classpath:applicationContextSimpleTest.xml" })
public class CurrencySpeakerTest
一切都很好...直到我对源代码进行了一些更改...直到我在父项目上运行 mvn install
之前我看不到它们。怎么了?我试图查看调试配置,但找不到据说要查看编译源而不是 .java
文件的地方...我认为这就是 junit 运行 的原因>.class
文件而不是真正的文件...有人对此有任何想法吗?
我有 3 个模块应用程序...它们是使用父模块构建的。父模块也是 eclipse 中导入的项目。我在 test 文件夹中的三个模块之一中进行了更改。我点击刷新并手动清理/构建 Eclipse 项目(如果我启用自动构建,它不会改变任何内容)。我使用 Eclipse 对话框作为 JUnit 运行测试。 Eclipse 似乎没有看到编辑的测试文件(.java)中的更改。
也许这与包含其他模块的一个主要项目有关? 奇怪的是...如果我编辑不在测试文件夹中的任何其他类并使用 tomcat 插件运行 Web 应用程序,Eclipse 会看到那里的更改吗?
我使用 mvn clean 和 mvn install 但这不是问题。 我使用 Eclipse 来运行测试,但 Eclipse 调试器无法看到代码中的更改...例如,如果我在某处添加 System.out.println() 并将断点放在那里,我会运行测试,并且 Eclipse 不会在那里停止,因为它以某种方式看起来在旧代码上(我假设是 .class 文件)...或者如果我删除该行,编辑一些字符串...什么都没有...它似乎指向 .class...为什么会这样?刷新并清理/构建 Eclipse 项目不起作用。
I have multi module maven project. The technologies I use is Spring and Struts. I created test case and run it as :
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = { "classpath:applicationContextSimpleTest.xml" })
public class CurrencySpeakerTest
Everything is fine... until I make some changes in source... I cant see them until i run mvn install
on the parent project. Whats wrong? I tried to look into the debug configuration but I cant find the place where its said to look on compile source instead of .java
files... I think this is the reason that junit is running the .class
files instead of real one... anybody has any idea about that?
I have 3 module app ... they are build with parent module. Parent module is also the imported project in eclipse.I do the changes in one of three module in the test folder. I hit refresh and I do clean/build eclipse project manually ( if i enable automatically build it wont change anything). I run the test as JUnit with eclipse dialog. Eclipse seems not to see the changes in edited test file (.java).
Maybe this has something to do with the one main project which includes the other modules?
What is strange is that... if I edit any other classes not in the test folder and run web app with tomcat plugin, Eclipse sees the changes there?
I use mvn clean and mvn install but this is not the issue.
I use Eclipse to run the test but the Eclipse debugger cant see the changes in the code... for eg if I add System.out.println() somewhere and put the breakpoint there I run the test and Eclipse doesnt stop there because it looks somehow on the old code (I assume the .class file)...or if I delete the line,edit some String...nothing... it seems to point on the .class...why is that? Refresh and clean/build eclipse project doesnt work.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
当我从编写测试的模块中删除目标时,出现以下异常。这使得我的理论是正确的,即 Eclipse 正在研究编译后的代码并且看不到源代码...为什么会这样?
找不到类 pl.erif.utils.CurrencySpeakerTest
java.lang.ClassNotFoundException: pl.erif.utils.CurrencySpeakerTest
在 java.net.URLClassLoader$1.run(URLClassLoader.java:202)
在 java.security.AccessController.doPrivileged(本机方法)
在 java.net.URLClassLoader.findClass(URLClassLoader.java:190)
在 java.lang.ClassLoader.loadClass(ClassLoader.java:307)
在 sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
在 java.lang.ClassLoader.loadClass(ClassLoader.java:248)
在 org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.loadClass(RemoteTestRunner.java:693)
在 org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.loadClasses(RemoteTestRunner.java:429)
在 org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:452)
在 org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
在 org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
在 org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
When I delete the target from my module where i write the test I got exception below. Which makes my theory true that eclipse is looking into compiled code and cant see the source... Why is that?
Class not found pl.erif.utils.CurrencySpeakerTest
java.lang.ClassNotFoundException: pl.erif.utils.CurrencySpeakerTest
at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.loadClass(RemoteTestRunner.java:693)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.loadClasses(RemoteTestRunner.java:429)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:452)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
您可能需要先运行一个干净的程序
您是否在 eclipse 之外编辑 java 文件?如果是,您可能需要按 f5 来刷新它。 (它通常应该检测到更改)
如果没有,您是否在 Eclipse 中使用自动构建选项?
you may need to run a clean first
Are you editing java files outside of eclipse? If yes, you may need to hit f5 to refresh it. (It normally should detect changes)
If not, are you using the build automatically option in eclipse?
我有同样的问题。这是由于 .classpath 有缺陷造成的。删除此 .classpath 并重新导入项目,生成正确的 .classpath 并修复环境。
要查找更多详细信息,请确保 eclipse 没有在错误的目录中生成测试用例的类文件。
Ref: 单元测试类在 eclipse 中运行旧版本
I had the same issue. It was due to a defective .classpath. Removing this .classpath and re-importing the project, generates a correct .classpath and fixed the environment.
To find more details make sure that eclipse is not generating the class files of your testcase in a wrong directory.
Ref: Unit test class runs old version in eclipse