junit testSuite:ClassNotFoundException

时间:2011-05-18 12:55:45

标签: java ant junit

我正在获取在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 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和测试文件的java和test文件夹下。我希望我给出更多/错误的道路。     ....

<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>

1 个答案:

答案 0 :(得分:1)

尝试更改:

 <dirset dir="${TEST_SRC_DIR}"/>

为:

 <dirset dir="${TEST_BUILD_DIR}"/>

<junit>部分。类路径必须包含构建的类,而不是源文件。如果您的类生成为.../src/java,请改用${COMP_JAVA_SRC}。 (但这有点不合标准。)

关键是此dirset变量必须指向.class个文件所在位置的根目录。