AKB
AKB

Reputation: 5938

junit testSuite: ClassNotFoundException

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>

Upvotes: 0

Views: 1343

Answers (1)

Mat
Mat

Reputation: 206679

Try changing:

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

to:

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

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.

Upvotes: 1

Related Questions