<project name="JunitSuite" basedir="." default="clean">
<property name="${src}" value="./src/JunitSuiteProject" />
<property name="${build}" value="./build" />
<property name="package" value="JunitSuiteProject"/>
<property name= "jar" value="./build/jar"/>
<target name="clean">
<delete dir="./build"/>
<mkdir dir="./build"/>
<mkdir dir="./build/jar"/>
</target>
<target name="run">
<junit printsummary="yes" haltonfailure="yes" showoutput="yes">
<classpath location="C:\Program Files\Java\apache-ant-1.9.2\lib\selenium-server-standalone-2.35.0.jar"/>
<classpath location="E:\Swaroop Don't Touch\Selenium\eclipse-jee-juno-SR2-win32\eclipse\plugins\org.junit_3.8.2.v3_8_2_v20100427-1100\junit.jar"/>
<classpath location="C:\Program Files\Java\apache-ant-1.9.2\lib\*.jar"/>
<classpath location="E:\Swaroop Don't Touch\Selenium\eclipse-jee-juno-SR2-win32\eclipse\plugins\"/>
<formatter type="brief" usefile="false"/>
<batchtest fork="yes">
<fileset dir="C:\Program Files\Java\apache-ant-1.9.2\lib" includes="selenium-server-standalone-2.35.0.jar"/>
<fileset dir="E:\Swaroop Don't Touch\Selenium\eclipse-jee-juno-SR2-win32\eclipse\plugins\org.junit_3.8.2.v3_8_2_v20100427-1100" includes="junit.jar"/>
<fileset dir="C:\Program Files\Java\apache-ant-1.9.2\lib" includes="*.jar"/>
<fileset dir="./build" includes="**/AllTests.*"/>
</batchtest>
</junit>
</target>
<target name="compile">
<javac srcdir="./src/JunitSuiteProject" destdir="./build" includeantruntime="true">
<classpath location="C:\Program Files\Java\apache-ant-1.9.2\lib\selenium-server-standalone-2.35.0.jar" />
</javac>
</target>
<target name="jar">
<jar destfile="./build/jar/JunitSuite.jar" basedir="./build">
</jar>
</target>
</project>
**************************************************************
package JunitSuiteProject;
import junit.framework.TestSuite;
import junit.framework.Test;
import org.junit.runners.Suite;
import org.junit.runner.RunWith;
import org.junit.runners.Suite.SuiteClasses;
@RunWith(Suite.class)
@SuiteClasses({JunitTest1.class})
public class AllTests extends TestSuite{
public static Test Suite(){
TestSuite g = new TestSuite();
g.addTest(new JunitTest1("testprintTest"));
return g;
}
public static void main(String[]args){
junit.textui.TestRunner.run(Suite());
}
}
Could anyone let me know what is the issue here when i have specified the location of Jars inside Junit why am i getting ClassNotFoundException Error when i trigger the Ant file.
The output says:
[junit] Running AllTests
[junit] Testsuite: AllTests
[junit] Tests run: 1, Failures: 0, Errors: 1, Time elapsed: 0 sec
[junit] Tests run: 1, Failures: 0, Errors: 1, Time elapsed: 0 sec
[junit] Null Test: Caused an ERROR
[junit] AllTests
[junit] java.lang.ClassNotFoundException: AllTests
The junit used is 3.8 version and it is executing fine as a junit test but giving error when started from build.xml file.
It is an open-source testing framework for java programmers. The java programmer can create test cases and test his/her own code. It is one of the unit testing framework. Current version is junit 4.
It supports the test to run by writing and testing along. JUnit framework was initially based on the SUnit framework which is used for Unit testing but then later it was updated with Java using Selenium WebDriver. JUnit is now is used as a standard when we need to perform testing in Java.
JUnit is a simple framework to write repeatable tests. It is an instance of the xUnit architecture for unit testing frameworks.
The org. junit package provides several classes and packages, which helps us to ensure whether our code provides the expected output or not. These packages and classes are Assert, After, Before, and Test, etc. We will use the eclipse tool to test the java code.
The junit.framework.Test
package is the legacy namespace used by older projects that used JUnit v3 which was for versions of Java that did not support annotations.
The org.junit.Test
package is the new namespace used by JUnit v4 which requires Java v1.5 or later for its annotations. Use JUnit 4 and the latest Java if possible because the new annotations are vastly superior.
The current distributions of JUnit 4 include a copy of the old namespace to allow easy migration; however you should avoid using JUnit3 form for new tests and convert old tests to JUnit 4 as you can.
In JUnit 4 both packages are included in the library jar for migrations purposes but you should use org.junit.Test for new code and those test do not need to extend TestCase.
You can see a basic example of Junit4 test case.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With