Error while executing Junit tests using Ant

Hi,

I am trying to integrate Team City with a testing framework based on JUnit through ant runner. But every time, I execute test cases it gives me following error...

: junit (<1s)
: java.lang.NoClassDefFoundError: org/apache/tools/ant/taskdefs/optional/junit/JUnitTestRunner
: Caused by: java.lang.ClassNotFoundException: org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner
: at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
: at java.security.AccessController.doPrivileged(Native Method)
: at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
: at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
: at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:276)
: at java.lang.ClassLoader.loadClass(ClassLoader.java:251)
: at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:319)
: Exception in thread "main"
: delete (<1s)
: xml.suite.unforked (<1s)

I am using Team City Version 3.1.1 (build 6828) and am able to successfully execute the test cases on the same machine which is build agent without Team City ... even I am able to run test cases using Command Line runner only when I try to use Ant runner execution fails .. giving me error above ...
I have already included required ant and junit jar files in CLASSPATH variable both on the build agent ,environment variable, as additional Ant and java command line parameters but still I receive following error..
My build.xml also includes all the required lib jars .

I would appreciate if you guys can come to my rescue...

Thanks,
Abhi

7 comments

Do you use your own Ant? For example there can be ANT_HOME variable set on the agent or in the build configuration or path to Ant specified on the build runner form? If so try to run your tests with help of this Ant. If they fail with same error then verify that junit.jar is in the lib folder of this Ant.

--
Pavel Sher

0

Hey Pavel,

I have tried executing test cases using my own ant and team city's ant version but it gives same error . It seems that at the time of launcing the command team city sets the classpath argument...
-classpath' 'C:\TeamCity\buildAgent\lib\buildServerRuntimeUtil.jar;C:\TeamCity\buildAgent\plugins\antPlugin\lib\buildServerAntRuntime.jar

Please see the logs below ... I have highlighted the setting of classpath ..

+ Execute:Java13CommandLauncher: Executing 'C:\Program Files\Java\jdk1.6.0_06\jre\bin\java.exe' with arguments: '-Da=b' '-Da=b' '-Da=b' '-Didea.build.server.build.id=142' '-Dteamcity.buildType.id=bt4' '-Didea.build.agent.port=9091' '-Dagent.classpath=C:/TeamCity/buildAgent/lib/utils.jar;C:/TeamCity/buildAgent/plugins/antPlugin/lib/buildServerAntServerLogging.jar;C:/TeamCity/buildAgent/plugins/coveragePlugin/lib/emma.jar;C:/TeamCity/buildAgent/lib/buildServerServerLogging.jar;C:/TeamCity/buildAgent/lib/xmlrpc-2.0.1.jar;C:/TeamCity/buildAgent/lib/xpp3_min-1.1.3.4.M.jar;C:/TeamCity/buildAgent/lib/buildServerXmlRpcWrapper.jar;C:/TeamCity/buildAgent/plugins/testNGPlugin/lib/testNGAntExtension.jar;C:/TeamCity/buildAgent/lib/nanocontainer-1.0-RC-1.jar;C:/TeamCity/buildAgent/lib/buildServerCommonRuntime.jar;C:/TeamCity/buildAgent/lib/commons-codec-1.3.jar;C:/TeamCity/buildAgent/lib/xstream-1.2.1.jar;C:/TeamCity/buildAgent/lib/buildServerMessages.jar;C:/TeamCity/buildAgent/plugins/coveragePlugin/lib/coverageAgentRuntime.jar' '-Dteamcity.build.checkoutDir=C:\TeamCity\buildAgent\work\ea33ff1eb0f13662' '-Dteamcity.build.workingDir=C:\TeamCity\buildAgent\work\ea33ff1eb0f13662' '-Dagent.work.dir=C:\TeamCity\buildAgent\work' '-Dant.task.extensions=jetbrains.buildServer.agent.ant.CompilerAntExtension,jetbrains.buildServer.agent.ant.EchoAntExtension,jetbrains.buildServer.coverage.AntCoverageAdapter,jetbrains.buildServer.testng.TestNGTaskExtension,' '-Dagent.name=abhinavs' '-Dagent.home.dir=C:\TeamCity\buildAgent' '-Dagent.flow=6632120319202' '-Xmx64m' '-DAUTO_HOME=C:\setup\QTF\home\rel\Automation\LATEST\Automation' '-Dwatchaction=$' '-Dlog4j.console.levels=CALL' '-Ddelay=$' '-Dwatchweb=$' '-Dwatchwebfile=C:\workspace\qtf_eclipse\ProvUITestAutomation/temp.html' '-Dxml.method.exclude=${xml.method.exclude}' '-Dxml.method=${xml.method}' '-Dxml.package=${xml.package}' '-Dxml.suite.setup.filename=${xml.suite.setup.filename}' '-Dxml.suite.setup.method=${xml.suite.setup.method}' '-Dmethod=$' '-Dmethods=$' '-Dpackage=$' '-Dcfgfile=C:\workspace\qtf_eclipse\ProvUITestAutomation/cfg/configuration.xml' '-Druntime=07/03/2008 10:34 AM' '-Dhtml.failure.output.dir.name=htmlfailure' '-Dhtml.failure.output.dir=C:\workspace\qtf_eclipse\ProvUITestAutomation/logs/htmlfailure' '-Dxmlfilesfile=C:\workspace\qtf_eclipse\ProvUITestAutomation\null775711339.txt' '-Dlogs.dir=C:\workspace\qtf_eclipse\ProvUITestAutomation/logs' '-Dquery=$' '-Dinfo=$' '-Dbasedir=C:\workspace\qtf_eclipse\ProvUITestAutomation' '-Dmethod.level.recording=true' '-Dant.version=Apache Ant version 1.6.2 compiled on July 16 2004' '-Dmethod.counter.default.url=http://qbuilder.company.com/fast/release/QTF/current/xsd/method.html' '-Dlog.password=false' '-Dxml.suite.no.validation=false' '-Dqtf.xml.class.path=./' '-Dhttp.init.url=http://qbuilder.company.com/fast' '-Dlog4j.console.pattern=[%p] %m%n' '-Dlog4j.text.max.backup=2' '-Dlog4j.failure.levels=FAILURE,CALL,XMLLOG,CALLSETUPTEARDOWN,ERROR' '-Dlog4j.text.threshold=DEBUG' '-Dlogs.dir=C:\workspace\qtf_eclipse\ProvUITestAutomation/logs' '-Dlog4j.html.levels=INFO,FAILURE,DEPRECATED,CALL,ASSERTION,CALLSETUPTEARDOWN,XMLLOG,DEPRECATED,VERSION' '-Dlog.password=false' '-Dlog4j.html.max.backup=2' '-Dlog4j.html.append=true' '-Dlog4j.text.pattern=[%p] %d{dd MMM yyyy HH:mm:ss} (%F:%L) - %m%n' '-Dlog4j.max.filesize=10000KB' '-Dlog4j.html.max.filesize=10000KB' '-Denv.AUTO_HOME=C:\setup\QTF\home\rel\Automation\LATEST\Automation' '-Dlog4j.console.levels=DEPRECATED' '-Dlog4j.text.append=true' '-Dlog4j.text.max.filesize=10000KB' '-Dlog4j.trace.levels=FAILURE,CALL,ASSERTION,CALLSETUPTEARDOWN,XMLLOG,DEPRECATED,ERROR'

'-classpath' 'C:\TeamCity\buildAgent\lib\buildServerRuntimeUtil.jar;C:\TeamCity\buildAgent\plugins\antPlugin\lib\buildServerAntRuntime.jar'

'org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner' 'com.company.qtf.xml.XMLTestExecutor' 'filtertrace=true' 'haltOnError=false' 'haltOnFailure=false' 'formatter=org.apache.tools.ant.taskdefs.optional.junit.SummaryJUnitResultFormatter' 'showoutput=false' 'formatter=jetbrains.buildServer.agent.ant.AgentJUnitFormatter' 'formatter=com.company.qtf.xml.XMLResultFormatter,C:\workspace\qtf_eclipse\ProvUITestAutomation\output\TEST-com.company.qtf.xml.XMLTestExecutor.xml' 'propsfile=C:\workspace\qtf_eclipse\ProvUITestAutomation\junit1980303005.properties' The ' characters around the executable and arguments are not part of the command.+
: java.lang.NoClassDefFoundError: org/apache/tools/ant/taskdefs/optional/junit/JUnitTestRunner
: Caused by: java.lang.ClassNotFoundException: org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner
: at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
: at java.security.AccessController.doPrivileged(Native Method)
: at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
: at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
: at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:276)
: at java.lang.ClassLoader.loadClass(ClassLoader.java:251)
: at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:319)

I have tried to put all the reqired jar in agents lib directories and plugin lib directories ... but it does not pick up those jars ...
Is there any way to override setting of this classpath argument..

Thanks ,
-Abhinav

0

Hello,

Did you specify any value in "Ant home:" in Build Runner settings in TeamCity interface? If yes, try removing these settings.
Could you please take a look at buildAgent/logs/teamcity-agent.log and attach log lines which correspond to your build?
There should be some debug information about used ant home.

Kind regards,
KIR

0

Hey KIR,

I did not specify any value in Ant Home in build runner setup. Please find attached build agent logs for my build.

Thanks,
Abhinav



Attachment(s):
teamcity-agent.log
0

Hello,

Looks like your build agent has ANT_HOME environment variable with value C:\setup\QTF\home\rel\Automation\LATEST\Automation\common\3rdParty\ant\current
I suppose that this ant installation doesn't have corresponding jar files for junit task. That's why your tests cannot run.

Hope this helps,

KIR

0

Hey KIR,

Thanks for your prompt reply.
ANT_HOME environment points to the ant version recommended by the framework and I have verified that the lib dir contains all the necessary junit jars. Version of the ant used is 1.6.2

I modified the ANT_HOME env variable and it is now pointing to the one that comes with Team City (Ant Version 1.7.0) and I have copied junit jar files to it... I am able to run test cases locally on the build agent using Team City's ant but I still receive same error when I try using Team City.

Also previously , I used to get build status as success and now it comes to be failed.

I am attaching the build agent log file.

Regards,
Abhinav



Attachment(s):
teamcity-agent.log
0

Hello,

It looks like Junit task cannot be started because of the following:
java.lang.ClassNotFoundException: com.company.qtf.xml.XMLResultFormatter

Please try removing the custom formatter. Please let me know if it helps. What is the classpath
for the formatter?

Kind regards,
KIR

0

Please sign in to leave a comment.