且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

运行JUnit测试时找不到类异常

更新时间:2022-04-17 15:06:18

出现这种情况是因为使用 mvn clean compile 时只有源代码在编译(我使用的是 maven 3.1.0所以我不确定它是否总是这样).

This appears to occur because only the source code is compiling when you use mvn clean compile (I'm using maven 3.1.0 so I'm not sure if it always behaved like this).

如果您运行 mvn test,测试代码也会编译,但随后它会运行测试(如果您尝试通过 Eclipse 运行它们,这可能不是立即可取的.)解决这个问题的方法是在执行 mvn clean 时将 test-compile 添加到您的 Maven 命令序列中.例如,您将运行 mvn clean compile test-compile.

If you run mvn test, the test code will compile as well, but then it runs the tests (which may not be immediately desirable if you're trying to run them through Eclipse.) The way around this is to add test-compile to your Maven command sequence whenever you do a mvn clean. For example, you would run mvn clean compile test-compile.