How to debug in TestNG application?

990 views
Skip to first unread message

陈抒

unread,
Jul 11, 2010, 2:23:45 AM7/11/10
to testng...@googlegroups.com
Hi,
   I think every one needs to debug,but I can't find a sample.I don't use any IDE,just edit my build.xml for ant.I hava a project named ExemptionTest.

I have tried to debug ExemptionTest project using jdb command,but failed.
   root@reportingdev3:~/Exemption/trunk/ExemptionTest# jdb -sourcepath ./src freebird.ExemptionWebServiceTest
Initializing jdb ...
> stop at freebird.ExemptionWebServiceTest:48
Deferring breakpoint freebird.ExemptionWebServiceTest:48.
It will be set after the class is loaded.
> run
run freebird.ExemptionWebServiceTest
Set uncaught java.lang.Throwable
Set deferred uncaught java.lang.Throwable
>
VM Started:
Exception occurred: java.lang.ClassNotFoundException (uncaught)"thread=main", java.net.URLClassLoader$1.run(), line=202 bci=73

main[1]

   Maybe it needs to launch JVM first and attach jdb later.But it's very hard to find a simple sample to explain how to do it.I created a TestNG project using NetBeans,and looked into its ant script files.
It seems that the ant debug task should look like so:
<target name="debug-testng">
        <delete dir="${test-output}" quiet="true"/>
        <mkdir dir="${test-output}"/>
        <java classname="org.testng.TestNG" dir="${basedir}" fork="true">
            <jvmarg line="-Xdebug"/>
            <jvmarg value="-Xrunjdwp:transport=dt_socket,address=9999"/>
            <jvmarg line=" "/>
            <arg line="-d test_output"/>
            <arg line="-sourcedir ${src}"/>
            <arg line="suite.xml"/>
            <syspropertyset>
                <propertyref prefix="test-sys-prop."/>
                <mapper from="test-sys-prop.*" to="*" type="glob"/>
            </syspropertyset>
            <jvmarg value="-Dtestng.test.classpath=build/classes"/>
            <classpath>
                <path path="lib"/>
            </classpath>
            <jvmarg value="-ea"/>
            <syspropertyset>
                <propertyref prefix="run-sys-prop."/>
                <mapper from="run-sys-prop.*" to="*" type="glob"/>
            </syspropertyset>
        </java>
    </target>

I also created a suit.xml file for this.
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="Custom suite" parallel="none">
  <test verbose="3" name="ExemptionTest">
    <classes>
      <class name="freebird.ExemptionWebServiceTest"/>
    </classes>
  </test>
</suite>

The above ant task may be converted into the following commands:
java -Xdebug -Xrunjdwp:transport=dt_socket,address=9999 -Dtestng.test.classpath=build/classes -ea -classpath ./build/classes:./lib/log4j-1.2.15.jar:./lib/testng-5.12.1.jar:./build/classes org.testng.TestNG suite.xml

 But I got this message:

ERROR: transport error 202: connect failed: Connection refused
ERROR: JDWP Transport dt_socket failed to initialize, TRANSPORT_INIT(510)
JDWP exit error AGENT_ERROR_TRANSPORT_INIT(197): No transports initialized [../../../src/share/back/debugInit.c:690]
FATAL ERROR in native method: JDWP No transports initialized, jvmtiError=AGENT_ERROR_TRANSPORT_INIT(197)
Aborted

   I get stuck now.Could you help me or give me your ant scripts?


陈抒
Best regards
http://blog.csdn.net/sheismylife

konstanti...@gmail.com

unread,
Jul 12, 2010, 3:34:07 AM7/12/10
to testng...@googlegroups.com
Seems like previous debug process wasn't stop. You should stop it or use another debuging port.
--
You received this message because you are subscribed to the Google Groups "testng-users" group.
To post to this group, send email to testng...@googlegroups.com.
To unsubscribe from this group, send email to testng-users...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/testng-users?hl=en.

Reply all
Reply to author
Forward
0 new messages