not able to run testng test from ant.

1,193 views
Skip to first unread message

ajay mehra

unread,
Sep 12, 2009, 2:34:42 AM9/12/09
to testng-users
I have a testng test called Introduction50.java,an xml file for it
(Introduction50.xml) and an ant script(Introduction50_ant).
when i run this test through the command line using ant:

i get some error like this:


C:\apache-ant-1.7.1\lib>java -classpath ant.jar;ant-launcher.jar -
Dant.home=apac
he-ant-1.7.1 org.apache.tools.ant.launch.Launcher -buildfile
Introduction50_ant.
xml
Buildfile: Introduction50_ant.xml

launch tests:
[testng] [Parser] Running:
[testng] C:\apache-ant-1.7.1\lib\Introduction50.xml
[testng]
[testng] [ClassHelper] Could not instantiate
org.testng.tutorial.test.Introdu
ction50: org.testng.tutorial.test.Introduction50
[testng] [ClassHelper] Could not instantiate
org.testng.tutorial.test.Introdu
ction50: org.testng.tutorial.test.Introduction50
[testng]
[testng] ===============================================
[testng] org.testng.tutorial.test.Introduction50
[testng] Total tests run: 0, Failures: 0, Skips: 0
[testng] ===============================================
[testng]
[testng] org.testng.TestNGException:
[testng] Cannot find class in classpath:
org.testng.tutorial.test.Introductio
n50
[testng] at org.testng.xml.XmlClass.getSupportClass
(XmlClass.java:55)
[testng] at org.testng.internal.Utils.xmlClassesToClasses
(Utils.java:79)
[testng] at org.testng.TestRunner.initMethods(TestRunner.java:
289)
[testng] at org.testng.TestRunner.init(TestRunner.java:235)
[testng] at org.testng.TestRunner.init(TestRunner.java:197)
[testng] at org.testng.TestRunner.<init>(TestRunner.java:141)
[testng] at org.testng.SuiteRunner
$DefaultTestRunnerFactory.newTestRunner
(SuiteRunner.java:488)
[testng] at org.testng.SuiteRunner.privateRun(SuiteRunner.java:
250)
[testng] at org.testng.SuiteRunner.run(SuiteRunner.java:204)
[testng] at org.testng.TestNG.createAndRunSuiteRunners
(TestNG.java:877)
[testng] at org.testng.TestNG.runSuitesLocally(TestNG.java:842)
[testng] at org.testng.TestNG.run(TestNG.java:751)
[testng] at org.testng.TestNG.privateMain(TestNG.java:914)
[testng] at org.testng.TestNG.main(TestNG.java:887)

BUILD SUCCESSFUL
Total time: 0 seconds

So could you plz tell me wht could be the pblm and i would really
appreciate if u can provide me the solution.

Karthik Krishnan

unread,
Sep 12, 2009, 4:14:39 PM9/12/09
to testng...@googlegroups.com
Can you run your failed unit test from any IDE using TESTNG plugin ?


If it runs successfully, can you post the test class and ant script? The problem may lie in the way you define data providers or something like that. This is just speculation not knowing your code

Cédric Beust ♔

unread,
Sep 12, 2009, 4:58:04 PM9/12/09
to testng...@googlegroups.com
No, I think it's just a classpath problem, based on the error.  Just make sure your classpath is configured correctly.

--
Cedric
--
Cédric


ajay mehra

unread,
Sep 14, 2009, 2:19:22 AM9/14/09
to testng...@googlegroups.com
When i ran my testng script in eclipse,it worked.but i am facing difficulty in ant.so could you plz rectify wht i hv done wrong here.

This is my testclass with ant script.

M
y testclass  as folows:(SimpleTest.java)
package example1;
import org.testng.TestNG.*;

import org.testng.annotations.*;

public class SimpleTest {

 @BeforeClass
 public void setUp() {
   // code that will be invoked when this test is

instantiated
 }

 @Test(groups = { "fast" })
 public void aFastTest() {
   System.out.println("Fast test");
 }

 @Test(groups = { "slow" })
 public void aSlowTest() {
    System.out.println("Slow test");
 }

}

-----------------------------------------------------------------------------
Itz xml file:(SimpleTest.xml)
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd"

>
<suite name="xy suite" verbose="2">



  <test name="example1">

  
<classes>

      <class name="SimpleTest"/>

 </classes>


  </test>

</suite>

-----------------------------------------------------------------------------------------------------------------
Ant Script:(SimpleTest_ant.xml)
<?xml version="1.0" encoding="UTF-8"?>

<project name="testng tutorial" default="launch tests"

basedir=".">

  <description>testng tutorial</description>

  <taskdef resource="testngtasks"

classpath="testng-5.9-jdk15.jar"/>

  <target name="launch tests" description="launches

tests">

    <testng outputdir="SimpleTest">

<classpath>
        <pathelement path="SimpleTest"/>

       
</classpath>

    <xmlfileset dir="." includes="SimpleTest.xml"/>

    </testng>

  </target>

</project>
---------------------------------------------------------------------------------------
when i run this using command:
C:\testng-5.9\apache-ant-1.7.1\lib>java -classpath ant.jar;ant-launcher.jar -Dan
t.home=apache-ant-1.7.1 org.apache.tools.ant.launch.Launcher -buildfile SimpleTe
st_ant.xml

i get errors like:
C:\testng-5.9\apache-ant-1.7.1\lib>java -classpath ant.jar;ant-launcher.jar -Dan
t.home=apache-ant-1.7.1 org.apache.tools.ant.launch.Launcher -buildfile SimpleTe
st_ant.xml
Buildfile: SimpleTest_ant.xml


launch tests:
   [testng] [Parser] Running:
   [testng]   C:\testng-5.9\apache-ant-1.7.1\lib\SimpleTest.xml
   [testng]
   [testng] [ClassHelper] Could not instantiate SimpleTest: SimpleTest
   [testng] [ClassHelper] Could not instantiate SimpleTest: SimpleTest
   [testng]
   [testng] ===============================================
   [testng] xy suite

   [testng] Total tests run: 0, Failures: 0, Skips: 0
   [testng] ===============================================
   [testng]
   [testng] org.testng.TestNGException:
   [testng] Cannot find class in classpath: SimpleTest
   [testng]     at org.testng.xml.XmlClass.getSupportClass(XmlClass.java:55)
   [testng]     at org.testng.internal.Utils.xmlClassesToClasses(Utils.java:79)

   [testng]     at org.testng.TestRunner.initMethods(TestRunner.java:289)
   [testng]     at org.testng.TestRunner.init(TestRunner.java:235)
   [testng]     at org.testng.TestRunner.init(TestRunner.java:197)
   [testng]     at org.testng.TestRunner.<init>(TestRunner.java:141)
   [testng]     at org.testng.SuiteRunner$DefaultTestRunnerFactory.newTestRunner
(SuiteRunner.java:488)
   [testng]     at org.testng.SuiteRunner.privateRun(SuiteRunner.java:250)
   [testng]     at org.testng.SuiteRunner.run(SuiteRunner.java:204)
   [testng]     at org.testng.TestNG.createAndRunSuiteRunners(TestNG.java:877)

   [testng]     at org.testng.TestNG.runSuitesLocally(TestNG.java:842)
   [testng]     at org.testng.TestNG.run(TestNG.java:751)
   [testng]     at org.testng.TestNG.privateMain(TestNG.java:914)
   [testng]     at org.testng.TestNG.main(TestNG.java:887)

BUILD SUCCESSFUL
Total time: 0 seconds



Karthik Krishnan

unread,
Sep 14, 2009, 2:46:45 AM9/14/09
to testng...@googlegroups.com
You need to check your classpath.... What happens if you try to compile SimpleTest with your classpath reference?

ajay mehra

unread,
Sep 15, 2009, 12:56:48 AM9/15/09
to testng...@googlegroups.com
could u plz tell me hw to set a classpath for a class because i am getting confused with this.

Cédric Beust ♔

unread,
Sep 15, 2009, 1:06:31 AM9/15/09
to testng...@googlegroups.com
On Mon, Sep 14, 2009 at 9:56 PM, ajay mehra <ajaym...@gmail.com> wrote:
could u plz tell me hw to set a classpath for a class because i am getting confused with this.


This is a beginner Java question, please do a Google search on it, there is plenty of material available.

--
Cédric


ajay mehra

unread,
Sep 15, 2009, 1:12:11 AM9/15/09
to testng...@googlegroups.com
i did that and i knw hw to set a class path by adding the path in environment varialbles but m still getting the same error that i hv mentioned above in my tests.

2009/9/15 Cédric Beust ♔ <cbe...@google.com>

Karthik Krishnan

unread,
Sep 15, 2009, 2:27:16 AM9/15/09
to testng...@googlegroups.com
I am not talking about setting classpath with your environment variables. In Ant, we can compile using javac where you can set up classpath reference id.

ajay mehra

unread,
Sep 15, 2009, 7:40:32 AM9/15/09
to testng...@googlegroups.com
sir can u plz send me a simple testng test with itz ant script and the way we run this testng script using ant so that i can know  where am i goin wrong. and it would be of gr8 help to me.

Tarun K

unread,
Sep 15, 2009, 8:36:06 AM9/15/09
to testng-users
See the place where u have class name in testng xml file -

**************************
<classes>
<class name="SimpleTest"/>
</classes>
**************************

Provide full qualified name for class. To know qualified name for
class, just right click on class in Eclipse and select "Copy Qualified
Name". It might be some thing like - "com.test.SimpleTest.java".
REMEMBER to remove ".java" extension
hence class name would be like - "com.test.SimpleTest"

Now try. Any ways this should not have worked in Eclipse as well (what
u claimed earlier)

HTH

~ T


ajay mehra

unread,
Sep 16, 2009, 12:11:09 AM9/16/09
to testng...@googlegroups.com
my testng class i.e(SimpleTest.java),xml file(SimpleTest.xml) and the ant script are at the same place i.e (c:\testng-5.9\apache-ant-1.7.1\lib). but still i get the error: could not instantiate SimpleTest.
                                                                                             cannot find class in clsspath:SimpleTest

Tarun Kumar Bhadauria

unread,
Sep 16, 2009, 12:27:24 AM9/16/09
to testng...@googlegroups.com

Did you try what I suggested….

 

Thanks,

Tarun K


ajay mehra

unread,
Sep 16, 2009, 12:37:43 AM9/16/09
to testng...@googlegroups.com
yes i did tat but let me tell you one thing that i am not using eclipse.itz through ant on command prompt

ajay mehra

unread,
Sep 16, 2009, 12:40:10 AM9/16/09
to testng...@googlegroups.com
 the command that i am using to run this test is:java -classpath ant.jar;ant-launcher.jar -Dant.home=apache-ant-1.7.1 org.apache.tools.ant.launch.Launcher -buildfile SimpleTest_ant.xml


On Wed, Sep 16, 2009 at 10:07 AM, ajay mehra <ajaym...@gmail.com> wrote:
yes i did tat but let me tell you one thing that i am not using eclipse.itz through ant on command prompt.

Tarun Kumar Bhadauria

unread,
Sep 16, 2009, 12:52:05 AM9/16/09
to testng...@googlegroups.com

Even then u must know “hierarchy of class”… I hope u understand what “full qualified name” of class mean….

ajay mehra

unread,
Sep 16, 2009, 12:57:44 AM9/16/09
to testng...@googlegroups.com
My class SimpleTest is inside c:\testng-5.9\apache-ant-1.7.1\lib\SimpleTest.java and i must say this is the hierachy of my class so do i need to give the full path of class inside the xml file.

Tarun Kumar Bhadauria

unread,
Sep 16, 2009, 1:17:45 AM9/16/09
to testng...@googlegroups.com

You have java class in “lib” folder… It should be in “src” folder…

ajay mehra

unread,
Sep 16, 2009, 1:42:34 AM9/16/09
to testng...@googlegroups.com
i ran even from src but it still shows me the same error.

Tarun Kumar Bhadauria

unread,
Sep 16, 2009, 1:44:45 AM9/16/09
to testng...@googlegroups.com

I give up… please consult a dev in your team…

ajay mehra

unread,
Sep 16, 2009, 1:49:53 AM9/16/09
to testng...@googlegroups.com
sir can u give me ur gtalk id so that i can clearly explain wht i hv done.and i think i might hv done some mistake whick could be resolved by you.

Tarun Kumar Bhadauria

unread,
Sep 16, 2009, 1:52:30 AM9/16/09
to testng...@googlegroups.com

You cam mail me at id mentioned in this mail…

ajay mehra

unread,
Sep 16, 2009, 1:55:54 AM9/16/09
to testng...@googlegroups.com
thank you sir for trying to help me....i wil mail u to ur mail:TBhad...@ciber.com.

ajay mehra

unread,
Sep 22, 2009, 2:45:20 AM9/22/09
to testng...@googlegroups.com
Hi,
    how can we pass different kinds of parameters with dataproviders to a test method.can anyone post a good example of parameters with dataprovider.

Zaphod

unread,
Sep 22, 2009, 12:58:30 PM9/22/09
to testng-users


On Sep 22, 7:45 am, ajay mehra <ajaymehr...@gmail.com> wrote:
> Hi,
>     how can we pass different kinds of parameters with dataproviders to a
> test method.can anyone post a good example of parameters with dataprovider.

Here is a sample test incorporating a DataProvider
Regards
Ed


import org.testng.annotations.DataProvider ;
import org.testng.annotations.Test ;
import org.testng.Assert;

/**
* Test using DataProvider
*/
public class TestDataProvider {

@DataProvider(name="dataForTest")
public Object[][] dataForTest() {
Object[][] data = new Object[3][2];
for (int i=0; i<data.length; i++) {
String name = "data-"+String.valueOf(i+1);
data[i][0] = name;
data[i][1] = "2";
}
return data;
}

@Test(dataProvider="dataForTest")
public void dataTest(String data, String data2) {
Assert.assertNotNull("data is null", data);
}

}

ajay mehra

unread,
Sep 23, 2009, 2:14:02 AM9/23/09
to testng...@googlegroups.com
Hi sir,
 i have two test methods and i made one test method dependent on other method by giving annotation dependsOnMethods,so wen i run it executes the main method and skips the dependent method.why itz happening like this.

ajay mehra

unread,
Sep 23, 2009, 5:12:53 AM9/23/09
to testng...@googlegroups.com
Hi All,
how can we do parameterization for python tests??

ajay mehra

unread,
Sep 23, 2009, 7:00:06 AM9/23/09
to testng...@googlegroups.com
can anyone help me how we can launch our testNG test using ant.till now i was executing my testcases in the commandline and it was succesfull.and i dont have any idea about how to make a ant script for my testng tests to launch it with ant.so if possible please provide me a sample ant buildfile so that i can implement it in my testNG test.
the version of ant i am using is apache-ant-1.7.1 and my testNG version is testNG-5.9.

Zaphod

unread,
Sep 23, 2009, 6:31:22 PM9/23/09
to testng-users


ajay mehra wrote:
> can anyone help me how we can launch our testNG test using ant.till now i
> was executing my testcases in the commandline and it was succesfull.and i
> dont have any idea about how to make a ant script for my testng tests to
> launch it with ant.so if possible please provide me a sample ant buildfile
> so that i can implement it in my testNG test.
> the version of ant i am using is apache-ant-1.7.1 and my testNG version is
> testNG-5.9.
>


Here is a simple Ant build.xml file that might get you going,
but to help yourself with this you must please Read The Fine Manuals
at
http://testng.org/doc/ant.html
and
http://ant.apache.org/manual/index.html

<project name="testng.example" basedir="." default="help">

<property name="src.java" value="src/java"/>
<property name="target.java" value="target/classes"/>
<property name="logdir" value="target/logs"/>

<property name="project.root" location="."/>
<property name="libs" location="${project.root}/libs"/>
<property name="tools.testng.jar" location="${libs}/testng/
testng-5.10-jdk15.jar"/>


<path id="classpath.compile">
<fileset dir="${libs}" includes="*.jar"/>
</path>

<path id="classpath.run.tests">
<pathelement location="${target.java}"/>
<pathelement location="${tools.testng.jar}"/>
<fileset dir="${libs}" includes="*.jar"/>
</path>


<target name="help">
<exec osfamily="windows" executable="cmd">
<arg value="/c"/>
<arg value="ant.bat"/>
<arg value="-projecthelp"/>
<arg value="-buildfile"/>
<arg value="${ant.file}"/>
</exec>
<exec osfamily="unix" executable="ant">
<arg value="-projecthelp"/>
<arg value="-buildfile"/>
<arg value="${ant.file}"/>
</exec>
</target>


<target name="run" depends="taskdef.testng, init">

<pathconvert refid="classpath.run.tests" property="crt" pathsep="$
{line.separator}"/>
<echo>Classpath for running these tests:${line.separator}${crt}</
echo>

<testng classpathref="classpath.run.tests"
useDefaultListeners="true"
outputDir="${logdir}"
verbose="1">

<!--jvmarg value="-
agentlib:jdwp=transport=dt_socket,server=y,address=8000"/-->
<classfileset dir="${target.java}" includes="**/*.class"/>
<reporter classname="reports.TestNameReporter"/>

<sysproperty key="wss.test.formatter.debug" value="true"/>
</testng>
</target>


<target name="taskdef.testng" description="TestNG - see
http://testng.org/doc/ant.html" >
<taskdef resource="testngtasks">
<classpath><pathelement location="${tools.testng.jar}"/></
classpath>
</taskdef>
</target>


<target name="compile" depends="init">
<javac destdir="${target.java}" classpathref="classpath.compile"
source="1.6"
target="1.6"
debug="on"
debuglevel="lines,source,vars"
optimize="on"
memoryMaximumSize="256m"
fork="false">
<src path="${src.java}"/>
</javac>
<copy todir="${target.java}" failonerror="false">
<fileset dir="${src.java}" includes="**/*" excludes="**/*.java" /
>
</copy>
</target>


<target name="clean">
<delete dir="${target.java}"/>
<delete dir="${logdir}"/>
<mkdir dir="${target.java}"/>
<mkdir dir="${logdir}"/>
</target>


<target name="init">
<mkdir dir="${target.java}"/>
<mkdir dir="${logdir}"/>
</target>

</project>

ajay mehra

unread,
Sep 24, 2009, 12:55:31 AM9/24/09
to testng...@googlegroups.com
When i run my testNG test,it shows me an error like this: 

C:\testng-5.9>java -classpath ant.jar;ant-launcher.jar -Dant.home=apache-ant-1.7
.1 org.apache.tools.ant.launch.Launcher -buildfile SimpleTest_ant.xml
Buildfile: SimpleTest_ant.xml

compile:
     [echo] compiling tests

test:
     [echo] running tests

BUILD FAILED
C:\testng-5.9\SimpleTest_ant.xml:51: testng doesn't support the "fork" attribute

what does it mean " testng doesn't support the "fork" attribute"

Zaphod

unread,
Sep 24, 2009, 7:18:56 AM9/24/09
to testng-users


On 24 Sep, 05:55, ajay mehra <ajaymehr...@gmail.com> wrote:
> When i run my testNG test,it shows me an error like this:
>
> C:\testng-5.9>java -classpath ant.jar;ant-launcher.jar
> -Dant.home=apache-ant-1.7
> .1 org.apache.tools.ant.launch.Launcher -buildfile SimpleTest_ant.xml
> Buildfile: SimpleTest_ant.xml
>
> compile:
>      [echo] compiling tests
>
> test:
>      [echo] running tests
>
> BUILD FAILED
> C:\testng-5.9\SimpleTest_ant.xml:51: testng doesn't support the "fork"
> attribute

Guessing ...
(because without seeing exactly what your file looks like, it's quite
hard to know.)

I'd guess it means you have added a "fork" attribute to your <testng>
command in your Ant file.
i.e. something like <testng fork="true" ... >

The supported attributes are listed on http://testng.org/doc/ant.html
Please read it. It doesn't mention a fork attribute, it says that
TestNG ALWAYS runs in a forked JVM, so one isn't needed.

Regards

Ed

ajay mehra

unread,
Sep 29, 2009, 1:42:29 AM9/29/09
to testng...@googlegroups.com
thnx zaphod,it worked.

ajay mehra

unread,
Sep 29, 2009, 1:43:26 AM9/29/09
to testng...@googlegroups.com
how can we schedule our testng testcases from ant?

Karthik Krishnan

unread,
Sep 29, 2009, 3:19:15 AM9/29/09
to testng...@googlegroups.com
Schedule test runs as in have them run at a particular time....

Harihara Vinayakaram

unread,
Sep 29, 2009, 3:25:13 AM9/29/09
to testng...@googlegroups.com
We have been using Hudson. You can define a job and have this scheduled

Regards
Hari

ajay mehra

unread,
Sep 29, 2009, 8:24:56 AM9/29/09
to testng...@googlegroups.com
i want my testng testcases from to run from at a particular time like it must run at night 9 pm say.so is there any way where i can configure my ant script to run at that time.i heard about scheduling  but dont have any idea how it is used in the ant buildfile.

Bill Michell

unread,
Sep 29, 2009, 8:51:45 AM9/29/09
to testng...@googlegroups.com

On 29 Sep 2009, at 13:24, ajay mehra wrote:

> i want my testng testcases from to run from at a particular time
> like it must run at night 9 pm say.so is there any way where i can
> configure my ant script to run at that time.i heard about
> scheduling but dont have any idea how it is used in the ant
> buildfile.


You wouldn't normally schedule from within ant. If you do continuous
integration, then the documentation for your CI server will tell you
how to run an ant task on a schedule. It'll also publish the results,
often by email. If you can do continuous integration, I'd strongly
recommend it.

Without a CI server, you probably want to use some kind of scheduling
utility for your operating system. In Linux or Unix, that would be
cron. Other Operating systems use different mechanisms.

The trick with a scheduled ant run is to publish the results - but ant
provides tools that will let you do that...
--
Bill Michell
billm...@gmail.com


ajay mehra

unread,
Oct 4, 2009, 1:31:44 AM10/4/09
to testng...@googlegroups.com
well i have lotz of testcases and i want them to run at different time with the help of ant.so my question is does ant provide any feature like this.

Bill Michell

unread,
Oct 5, 2009, 4:27:17 AM10/5/09
to testng...@googlegroups.com
Ant will help you control *which* test cases run, but not *when* they run. Ant isn't designed to be a general purpose programming language or a scheduling system. I suppose in theory you could write a scheduler task to embed within ant - but why? It would be like using a toothbrush to brush your hair. You might be able to achieve the result, but it is totally the wrong tool for the job.

It sounds like you need a continuous integration server, like Hudson or CruiseControl or any number of other solutions.

Even if you don't do Continuous Integration, the CI servers are good at running ant commands according to a specified schedule, and distributing the results in an appropriate way.
-- 
Bill Michell




Reply all
Reply to author
Forward
0 new messages