junit testSuite:ClassNotFoundException
我在 ant 中运行 junit 目标时收到以下错误代码。 EshopCoreTestSuite 是一个框架,如下所示:
public class EshopCoreTestSuite extends TestSuite {
public static Test suite() {
TestSuite suite = new TestSuite();
suite.addTestSuite(CustomerContextTest.class);
return suite;
}
public static void main(String[] args) {
TestRunner.run(EshopCoreTestSuite.class);} }
error:
<error message="com.bgc.EshopCoreTestSuite" type="java.lang.ClassNotFoundException">java.lang.ClassNotFoundException: com.bgc.EshopCoreTestSuite ....
</error>
junit target:
<property name="COMP_TEST_SRC_DIR" location="test/java"/>
<property name="TEST_BUILD_DIR" location="build/test"/>
<property name="COMP_JAVA_SRC" location="src/java" />
<property name="COMP_BUILD" location="build" />
我只是在这里与路径感到困惑。我有 src 文件夹,在这个 java 和 test 文件夹下有 java 和测试文件。我希望我给出了更多/错误的路径。 ....
<junit printsummary="on" fork="on">
<classpath>
<path refid="CLASSPATH_JUNIT"/>
<dirset dir="${TEST_SRC_DIR}"/>
</classpath>
<env key="app.module" path="ESW"/>
<env key="app.env" path="DEV"/>
<test name="com.bgc.EshopCoreTestSuite" todir="../../../BUILD/ESW/ESWBUILD/CI/REPORT" outfile="junit_report">
<formatter type="xml"/>
</test>
</junit>
I am getting follwing error code for running junit target in ant. EshopCoreTestSuite is a framework as:
public class EshopCoreTestSuite extends TestSuite {
public static Test suite() {
TestSuite suite = new TestSuite();
suite.addTestSuite(CustomerContextTest.class);
return suite;
}
public static void main(String[] args) {
TestRunner.run(EshopCoreTestSuite.class);} }
error:
<error message="com.bgc.EshopCoreTestSuite" type="java.lang.ClassNotFoundException">java.lang.ClassNotFoundException: com.bgc.EshopCoreTestSuite ....
</error>
junit target:
<property name="COMP_TEST_SRC_DIR" location="test/java"/>
<property name="TEST_BUILD_DIR" location="build/test"/>
<property name="COMP_JAVA_SRC" location="src/java" />
<property name="COMP_BUILD" location="build" />
I am just confused here with path. I have src folder and under this java and test folder for java and test files. I hope I have given more/wrong path.
....
<junit printsummary="on" fork="on">
<classpath>
<path refid="CLASSPATH_JUNIT"/>
<dirset dir="${TEST_SRC_DIR}"/>
</classpath>
<env key="app.module" path="ESW"/>
<env key="app.env" path="DEV"/>
<test name="com.bgc.EshopCoreTestSuite" todir="../../../BUILD/ESW/ESWBUILD/CI/REPORT" outfile="junit_report">
<formatter type="xml"/>
</test>
</junit>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试
更改为:
将
部分中的: 。类路径必须包含构建的类,而不是源文件。如果您的类生成到.../src/java
,则使用${COMP_JAVA_SRC}
代替。 (但这有点不标准。)关键是这个 dirset 变量必须指向 .class 文件所在的根目录。
Try changing:
to:
in that
<junit>
section. The classpath must contain built classes, not source files. If your classes are being generated to.../src/java
, then use${COMP_JAVA_SRC}
instead. (But that's a bit non-standard.)The point is that this
dirset
variable must point to the root of where your.class
files are located.