pagalpanda
pagalpanda

Reputation: 150

JUnit in ANT giving ClassNotFoundException

I am trying to run a simple junit in a package. But it keeps on failing with ClassNotFound Exception. My build file looks like this:

<project name="JunitTest" default="test" basedir=".">
<property name="testdir" location="bin" />
<property name="full-compile" value="true" />
<path id="classpath.base"/>
<path id="classpath.test">
  <pathelement location="lib/junit-4.10.jar" />
  <pathelement location="${testdir}" />
  <path refid="classpath.base" />
</path>
<target name="test">
  <junit  fork="no">
     <classpath refid="classpath.test" />
     <formatter type="brief" usefile="false" />
     <test name="Test" />
  </junit>
</target>
</project>

And my Test.java looks like this:

package com.org.test.data.mine.board;

import org.junit.Test;

public class Test {

@Test
public void testDummy() {

    System.out.println("Hello");
}

}

And this keeps on failing with:

test:
[junit] Testsuite: Test
[junit] Tests run: 1, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 0 sec
[junit]
[junit] Null Test:  Caused an ERROR
[junit] Test
[junit] java.lang.ClassNotFoundException: Test
[junit]     at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
[junit]     at java.lang.Class.forName0(Native Method)
[junit]     at java.lang.Class.forName(Class.java:274)
[junit]
[junit]
[junit] Test Test FAILED

I looked through other SO posts but couldn't recognize the issue. Help!!

Upvotes: 0

Views: 173

Answers (1)

Sanjeev
Sanjeev

Reputation: 9946

There is a problem in the way you have written name of your Test class. You need to modify your jUnit task to include FQCN like this:

  <junit  fork="no">
     <classpath refid="classpath.test" />
     <formatter type="brief" usefile="false" />
     <test name="com.org.test.data.mine.board.Test" />
  </junit>

Upvotes: 1

Related Questions