2015-05-29 105 views
0
<project name="name" default="test" basedir="."> 

    <!-- Define <testng> task --> 

<taskdef resource="testngtasks"> 
     <classpath> 
     <pathelement location="/lib/testng-6.8.5.jar"/> 
     </classpath> 
</taskdef> 

    <property name="testdir" location="test" /> 
    <property name="srcdir" location="src" /> 
    <property name="libdir" location="lib" /> 
    <property name="full-compile" value="true" /> 

    <path id="classpath.base"/> 
    <path id="classpath.test"> 

    <fileset dir="${libdir}"> 
     <include name="**/*.jar" /> 
    </fileset> 

    <pathelement location="${testdir}" /> 
    <pathelement location="${srcdir}" /> 

    <path refid="classpath.base" /> 
    </path> 

    <target name="clean" > 
     <delete verbose="${full-compile}"> 
     <fileset dir="${testdir}" includes="**/*.class" /> 
     </delete> 
    <echo>Cleaned Successfully.</echo> 
    </target> 

    <target name="compile" depends="clean"> 
     <javac srcdir="${srcdir}" destdir="${testdir}" verbose="${full-compile}"> 
     <classpath refid="classpath.test"/> 
     </javac> 
    <echo>Java file compiled Successfully.</echo> 
    </target> 

    <target name="test" depends="compile"> 
     <testng outputdir="${testdir}" classpath="classpath.test"> 
     <xmlfileset dir="${srcdir}" includes="TestNG.xml"/> 
     </testng> 
    </target> 

</project> 

以下錯誤:
構建失敗
問題:無法創建任務或類型TestNG的
原因:這個名字是不確定的。
操作:檢查拼寫。
操作:檢查是否聲明瞭任何自定義任務/類型。
操作:檢查是否發生了任何/聲明。ANT:構建失敗:無法創建任務或類型TestNG的:正在接收

它的工作,但現在我收到另一個錯誤:

test: [testng] java.lang.NoClassDefFoundError: com/beust/jcommander/ParameterExcept 
    ion 
     [testng]  at java.lang.Class.getDeclaredMethods0(Native Method) 
     [testng]  at java.lang.Class.privateGetDeclaredMethods(Unknown Source) 
     [testng]  at java.lang.Class.getMethod0(Unknown Source) 
     [testng]  at java.lang.Class.getMethod(Unknown Source) 
     [testng]  at sun.launcher.LauncherHelper.getMainMethod(Unknown Source) 
     [testng]  at sun.launcher.LauncherHelper.checkAndLoadMain(Unknown Source) 
     [testng] Caused by: java.lang.ClassNotFoundException: com.beust.jcommander.Pa 
    rameterException 
     [testng]  at java.net.URLClassLoader$1.run(Unknown Source) 
     [testng]  at java.net.URLClassLoader$1.run(Unknown Source) 
     [testng]  at java.security.AccessController.doPrivileged(Native Method) 
     [testng]  at java.net.URLClassLoader.findClass(Unknown Source) 
     [testng]  at java.lang.ClassLoader.loadClass(Unknown Source) 
     [testng]  at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source) 
     [testng]  at java.lang.ClassLoader.loadClass(Unknown Source) 
     [testng]  ... 6 more 
     [testng] The tests failed. 

    BUILD SUCCESSFUL 
    Total time: 3 seconds 

以下是classpath.test的輸出,道具:

<path>\lib\apache-mime4j-0.6.jar; 
<path>\lib\bsh-1.3.0.jar; 
<path>\cglib-nodep-2.1_3.jar; 
<path>\commons-codec-1.9.jar; 
<path>\commons-collections-3.2.1.jar; 
<path>\commons-exec-1.1.jar; 
<path>\commons-io-2.4.jar; 
<path>\commons-jxpath-1.3.jar; 
<path>\commons-lang3-3.3.2.jar; 
<path>\commons-logging-1.1.3.jar; 
<path>\cssparser-0.9.14.jar; 
<path>\gson-2.3.1.jar; 
<path>\guava-18.0.jar; 
<path>\hamcrest-core-1.3.jar; 
<path>\hamcrest-library-1.3.jar; 
<path>\lib\htmlunit-2.15.jar; 
<path>\lib\htmlunit-core-js-2.15.jar; 
<path>\lib\httpclient-4.3.6.jar; 
<path>\lib\httpcore-4.3.3.jar; 
<path>\lib\httpmime-4.3.6.jar; 
<path>\lib\ini4j-0.5.2.jar; 
<path>\lib\jcommander-1.29.jar; 
<path>\lib\jetty-websocket-8.1.8.jar; 
<path>\lib\jna-3.4.0.jar; 
<path>\lib\jna-platform-3.4.0.jar; 
<path>\lib\junit-dep-4.11.jar; 
<path>\lib\nekohtml-1.9.21.jar; 
<path>\lib\netty-3.5.7.Final.jar; 
<path>\lib\operadriver-1.5.jar; 
<path>\lib\phantomjsdriver-1.2.1.jar; 
<path>\lib\protobuf-java-2.4.1.jar; 
<path>\lib\sac-1.3.jar; 
<path>\lib\selenium-java-2.45.0-srcs.jar; 
<path>\lib\selenium-java-2.45.0.jar; 
<path>\lib\serializer-2.7.1.jar; 
<path>\lib\testng-6.8.5.jar; 
<path>\lib\xalan-2.7.1.jar; 
<path>\lib\xercesImpl-2.11.0.jar; 
<path>\lib\xml-apis-1.4.01.jar; 

回答

1

,我認爲它無法找到一個罐子。

嘗試

<taskdef resource="testngtasks" classpath="/full/path/to/testng.jar"> 
</taskdef> 

或把testng.jar在ANT_HOME/lib和使用:

<taskdef resource="testngtasks" classpath="testng.jar"> 
</taskdef> 

您應該添加罐子你classpath.test

<path id="classpath.test"> 
    <fileset dir="lib"> 
     <include name="**/*.jar"/> 
    </fileset> 
    </path> 

所在類別com/beust/jcommander/ParameterException是界定?

您可以打印類路徑以確保該jar包含在其中。

<pathconvert property="classpath.test.prop" refid="classpath.test"/> 
<echo>Classpath is ${classpath.test.prop}</echo> 

,你應該在你的TestNG的任務調用使用classpathrefclasspath

<testng outputdir="${testdir}" classpathref="classpath.test"> 
     <xmlfileset dir="${srcdir}" includes="TestNG.xml"/> 
</testng> 
+0

它的工作。但我收到另一個錯誤。我錯誤地更新了帖子。 – Abhinav

+0

我更新了我的答案。如果你喜歡並接受有用的答案,人們會更樂意幫助你。 –

+0

它已經加入:路徑ID = 「classpath.test」> <文件集DIR = 「$ {LIBDIR}」> <包括名稱= 「**/*罐」/> <路徑REFID = 「classpath.base」/> – Abhinav