aspose file tools*
The moose likes Ant, Maven and Other Build Tools and the fly likes I'm not able to run Junit suites in ant Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » Ant, Maven and Other Build Tools
Bookmark "I Watch "I New topic
Author

I'm not able to run Junit suites in ant

gow tham
Greenhorn

Joined: Sep 29, 2013
Posts: 29
Hi professionals,

I have created suites using Junit framework and I want to run them using ant. I don't know how to integrate Junit suites inside of ant.

I have tried the following ways to run junit suites in ant:

Steps:

1. I have copied the junit.jar file, and dropped into ANTHOME/lib directory.
2. I restarted my system to replicate the changes in run time(During execution).
3. Unfortunately still all the test cases are getting failed in the suite.

This is my build.xml structure:

<?xml version="1.0" encoding="UTF-8"?>
<project name="junit" default="main" basedir=".">
<property name="src.dir" location="src"/>
<property name="build.dir" location="lib"/>
<property name="class.dir" location="class"/>
<property name="result.dir" location="Result"/>
<path id="build.class.path">
<!--<pathelement location="{$build.dir}\junit-4.10.jar">-->
<fileset dir="${build.dir}">
<include name="**/*.jar"/>
</fileset>
</pathelement>
</path>
<path id="test.class.path">
<pathelement location="${class.dir}"/>
</path>
<target name="clean">
<delete dir="${result.dir}"/>
<delete dir="${class.dir}"/>
</target>
<target name="init">
<mkdir dir="${result.dir}"/>
<mkdir dir="${class.dir}"/>
</target>
<target name="compile" depends="clean,init">
<javac srcdir="${src.dir}" destdir="${class.dir}"
includeantruntime="false" fork=
"true">
<classpath refid="build.class.path"/>
</javac>
</target>
<target name="run" depends="compile"/>
<target name="main" depends="compile">
<junit>
<classpath refid="build.class.path"/>
<classpath refid="test.class.path"/>
<format type="brief" usefile="false"/>
<test name="junitrunner"/>
</junit>
</target>
</project>


The following errors were observed in command line:

F:\folders\sasi\junit_ant>ant
Buildfile: F:\folders\sasi\junit_ant\build.xml

clean:
[delete] Deleting directory F:\folders\sasi\junit_ant\Result
[delete] Deleting directory F:\folders\sasi\junit_ant\class

init:
[mkdir] Created dir: F:\folders\sasi\junit_ant\Result
[mkdir] Created dir: F:\folders\sasi\junit_ant\class

compile:
[javac] Compiling 5 source files to F:\folders\sasi\junit_ant\class
[javac] error: error reading F:\folders\sasi\junit_ant\lib\junit-4.10.jar; c
annot read zip file
[javac] F:\folders\sasi\junit_ant\src\junitrunner.java:2: error: package org
.junit.runner does not exist
[javac] import org.junit.runner.JUnitCore;
[javac] ^
[javac] F:\folders\sasi\junit_ant\src\junitrunner.java:3: error: package org
.junit.runner does not exist
[javac] import org.junit.runner.Result;
[javac] ^
[javac] F:\folders\sasi\junit_ant\src\junitrunner.java:4: error: package org
.junit.runner.notification does not exist
[javac] import org.junit.runner.notification.Failure;
[javac] ^
[javac] F:\folders\sasi\junit_ant\src\junitsuite.java:2: error: package org.
junit.runner does not exist
[javac] import org.junit.runner.RunWith;
[javac] ^
[javac] F:\folders\sasi\junit_ant\src\junitsuite.java:3: error: package org.
junit.runners does not exist
[javac] import org.junit.runners.Suite;
[javac] ^
[javac] F:\folders\sasi\junit_ant\src\junitsuite.java:6: error: cannot find
symbol
[javac] @RunWith(Suite.class)
[javac] ^
[javac] symbol: class RunWith
[javac] F:\folders\sasi\junit_ant\src\junitsuite.java:7: error: package Suit
e does not exist
[javac] @Suite.SuiteClasses({
[javac] ^
[javac] F:\folders\sasi\junit_ant\src\launch.java:8: error: package org.juni
t does not exist
[javac] import org.junit.Test;
[javac] ^
[javac] F:\folders\sasi\junit_ant\src\test1.java:5: error: package org.junit
does not exist
[javac] import org.junit.Test;
[javac] ^
[javac] F:\folders\sasi\junit_ant\src\test1.java:6: error: package org.junit
does not exist
[javac] import static org.junit.Assert.assertEquals;
[javac] ^
[javac] F:\folders\sasi\junit_ant\src\test1.java:6: error: static import onl
y from classes and interfaces
[javac] import static org.junit.Assert.assertEquals;
[javac] ^
[javac] F:\folders\sasi\junit_ant\src\test2.java:3: error: package org.junit
does not exist
[javac] import org.junit.Test;
[javac] ^
[javac] F:\folders\sasi\junit_ant\src\launch.java:11: error: cannot find sym
bol
[javac] @Test
[javac] ^
[javac] symbol: class Test
[javac] location: class launch
[javac] F:\folders\sasi\junit_ant\src\test1.java:13: error: cannot find symb
ol
[javac] @Test
[javac] ^
[javac] symbol: class Test
[javac] location: class test1
[javac] F:\folders\sasi\junit_ant\src\test2.java:8: error: cannot find symbo
l
[javac] @Test
[javac] ^
[javac] symbol: class Test
[javac] location: class test2
[javac] F:\folders\sasi\junit_ant\src\junitrunner.java:8: error: cannot find
symbol
[javac] Result result=JUnitCore.runClasses(junitsuite.class);
[javac] ^
[javac] symbol: class Result
[javac] location: class junitrunner
[javac] F:\folders\sasi\junit_ant\src\junitrunner.java:8: error: cannot find
symbol
[javac] Result result=JUnitCore.runClasses(junitsuite.class);
[javac] ^
[javac] symbol: variable JUnitCore
[javac] location: class junitrunner
[javac] F:\folders\sasi\junit_ant\src\junitrunner.java:9: error: cannot find
symbol
[javac] for(Failure failure:result.getFailures())
[javac] ^
[javac] symbol: class Failure
[javac] location: class junitrunner
[javac] 19 errors

BUILD FAILED
F:\folders\sasi\junit_ant\build.xml:26: Compile failed; see the compiler error o
utput for details.

Total time: 1 second



Please guide me, how to overcome this issue?. How to execute the juint suites inside and outside of Eclipse IDE ?.

Thanks in advance.

Regards,
Santhosh.
gow tham
Greenhorn

Joined: Sep 29, 2013
Posts: 29
Any updates???
gow tham
Greenhorn

Joined: Sep 29, 2013
Posts: 29
Hi friends,

Anyone has any ideas regarding on my query?
Maneesh Godbole
Saloon Keeper

Joined: Jul 26, 2007
Posts: 10535
    
    9

san thosh wrote:

Like I had requested earlier, you need to check your Purple Mooseages for an important administrative matter. Please note, this is not optional.


[How to ask questions] [Donate a pint, save a life!] [Onff-turn it on!]
gow tham
Greenhorn

Joined: Sep 29, 2013
Posts: 29
Thanks maneesh. I will read the line.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: I'm not able to run Junit suites in ant