2017-09-29 30 views
0

以下是我的Build.xml文件。当我编译我的项目它显示生成成功,但是当我运行它然后生成失败“未能创建任务或键入testng”原因:名称是未定义的。 操作:检查拼写。 操作:检查是否声明了任何自定义任务/类型。 操作:检查是否发生了任何/声明。ANT编译工作正常,但ANT运行无法正常工作构建失败“未能创建任务或键入testng”

<?xml version="1.0" encoding="UTF-8"?> 
<project name="projectName" default="clean" basedir="C:\Users\saad bin usman\workspace\testNG"> <!-- dot indicates that basedir is pointing towards project root directory --> 

<!-- ========== Initialize Properties =================================== --> 
<property name="ws.home" value="${basedir}" /> 
<property name="ws.jars" value="D:\jars" /> 
<property name="test.dest" value="${ws.home}/build"/> 
<property name="test.src" value="${ws.home}/src"/> 
<property name="ng.result" value="test-output"/> 

<echo> value of base dir = ${basedir} </echo> 

<!-- properties for copying the results --> 
<tstamp> 
<format property="year" pattern="yyyy" /> 
<format property="DSTAMP" pattern="yyyy-MM-dd" /> 
<format property="TSTAMP" pattern="HH:mm:ss" /> 
<format property="dateversion" pattern="yyyy.MM.dd.HH:mm:ss" /> 
<format property="time.stamp" pattern="yyyy-MM-dd_HH-mm-ss aa_"/> 
</tstamp> 

<property name="testng.report.dir" value="${ws.home}/testngReports/${time.stamp}"/> 
<property name="testngXslt.report.dir" value="${ws.home}/testngXsltReports/${time.stamp}"/> 

<!-- ====== For setting the classpath ==== --> 
<target name="setClassPath" unless="test.classpath"> 
<path id="classpath_jars"> 
<fileset dir="${ws.jars}" includes = "*.jar"/> 
</path> 
<pathconvert pathsep=":" 
property="test.classpath" 
refid="classpath_jars" /> 

</target> 

<!-- ============ Initializing other stuff =========== --> 
<target name="init" depends="setClassPath"> 
<tstamp> 
<format property="start.time" pattern="MM-dd-yyyy (HH-mm-ss)"/> 
</tstamp> 
<condition property="ANT" 
value="$(env.ANT_HOME)/bin/ant.bat" 
else="$(env.ANT_HOME)/bin/ant"> 
<!-- os family="windows" /--> 
<os family="mac" /> 
</condition> 



<!-- 
<!- use direct path for classpath if you don't prefer to use 'lib' directory: classpath="/Users/yash/Documents/Jar Files/testng-6.8.jar" -> 
<taskdef name="testng" classname="org.testng.TestNGAntTask"> 
<classpath> 
<pathelement location="./lib/testng.jar"/> 
</classpath> 
</taskdef> 
--> 

</target> 

<target name="all"> 
</target> 

<!-- cleaning the destination folders --> 
<target name="clean"> 
<echo message="deleting existing build directory"/> 
<delete dir="${test.dest}"/> 
</target> 

<!-- target for compiling the java files --> 
<target name="compile" depends="init, clean"> 
<delete includeemptydirs="true" quiet="true"> 
<fileset dir="${test.dest}" includes="**/*"/> 
</delete> 
<echo message="making directory....."/> 
<mkdir dir="${test.dest}"/> 
<echo message="classpath-------: ${test.classpath}"/> 
<echo message="compiling....."/> 
<javac 
debug="true" 
destdir="${test.dest}" 
srcdir="${test.src}" 
classpath="${test.classpath}" 
includeantruntime="true"/> 
</target> 

<!-- build --> 
<target name="build" depends="init"> 
</target> 

<!-- ========== Test executions & Generating reports using Testng utility for multiple suites ============== --> 
<!-- run --> 


<target name="run" depends="compile"> 

    <taskdef resource="testngtasks" classpath="D:\saad bin usman\saad's doc\softwares\eclipse\plugins\org.testng.eclipse_6.9.8.201510130443\lib\*.jar" /> 

    <testng classpath="classpath.test" suitename="smsweb" outputDir="test-output" > 
     <xmlfileset dir="${ws.home}" includes="testng.xml" /> 
    </testng> 


    </target> 

<target name="testngReportCopyAndReportParser"> 
<!-- Copy to TestNG report directory--> 
<mkdir dir="${testngDir}"> 
</mkdir> 

<!-- to copy previous suite result to TestNG report directory --> 
<copy todir="${testngDir}"> 
<fileset dir="test-output"/> 
</copy> <!-- end of Testng Report --> 
</target> 

<!-- ========== Test executions & Generating reports using Testng XSLT utility for multiple suites ============== --> 
<!-- run --> 
<target name="runAsTestngXslt" depends="compile"> 

<!--suite 1 begin --> 
<property name="suite.web.CopyRegressionCustomer" value="CopyRegressionCustomer" /> 
<testng classpath="${test.classpath}:${test.dest}" suitename="CopyRegressionCustomer" outputDir="test-output" > 
<xmlfileset dir="." includes="webSuites/CopyRegressionCustomer.xml" /> 
</testng> 
<antcall target="testngXsltReportCopy"> 
<param name="testngXsltDir" value="${testngXslt.report.dir}${suite.web.CopyRegressionCustomer}"/> 
</antcall> 

<!--suite 2 begin --> 
<property name="suite.web.Copy2RegressionCustomer" value="Copy2RegressionCustomer" /> 
<testng classpath="${test.classpath}:${test.dest}" suitename="Copy2RegressionCustomer" outputDir="test-output" > 
<xmlfileset dir="." includes="webSuites/Copy2RegressionCustomer.xml" /> 
</testng> 
<antcall target="testngXsltReportCopy"> 
<param name="testngXsltDir" value="${testngXslt.report.dir}${suite.web.Copy2RegressionCustomer}"/> 
</antcall> 

</target> 

<target name="testngXsltReportCopyAndReportParser"> 
<!-- Copy to TestNG report directory--> 
<mkdir dir="${testngXsltDir}"> 
</mkdir> 

<!-- to copy previous suite result to TestngXslt report folder --> 
<xslt in="${ws.home}/test-output/testng-results.xml" style="src/xslt/testng-results.xsl" 
out="${testngXsltDir}/index.html" classpathref="test.c" processor="SaxonLiaison"> 

<param name="testNgXslt.outputDir" expression="${testngXsltDir}" /> 
<param name="testNgXslt.showRuntimeTotals" expression="true" /> 
<param name="testNgXslt.sortTestCaseLinks" expression="true" /> 
<param name="testNgXslt.testDetailsFilter" expression="FAIL,SKIP,PASS,CONF,BY_CLASS" /> 
</xslt> <!-- end of TestngXslt Report --> 
</target> 

<path id="test.c"> 
<fileset dir="${ws.jars}" includes="*.jar"> 
<include name="mail.jar"/> 
<include name="activation-1.0.2.jar"/> 
</fileset> 
</path> 

<!-- ========== Generating reports using Testng XSLT utility for single suite only ============== --> 
<target name="report" depends="run"> 
<!-- TestngXslt report --> 
<mkdir dir="${testngXslt.report.dir}"> 
</mkdir> 

<!-- to copy previous suite result to TestngXslt report folder --> 
<xslt in="${ws.home}/test-output/testng-results.xml" style="src/xslt/testng-results.xsl" 
out="${testngXslt.report.dir}/index.html" classpathref="test.c" processor="SaxonLiaison"> 

<param name="testNgXslt.outputDir" expression="${testngXslt.report.dir}" /> 
<param name="testNgXslt.showRuntimeTotals" expression="true" /> 
<param name="testNgXslt.sortTestCaseLinks" expression="true" /> 
<param name="testNgXslt.testDetailsFilter" expression="FAIL,SKIP,PASS,CONF,BY_CLASS" /> 
</xslt> <!-- end of TestngXslt Report --> 
</target> 

<target name="RunAndViewReport" depends="report"> 
<exec executable="${browser}" spawn="yes"> 
<arg line="'file:///${testngXslt.report.dir}/index.html'" /> 
</exec> 
</target> 

<target name="sendMail" depends="RunAndViewReport"> 
<zip destfile="${testngXslt.report.dir}/Report.zip" basedir="${testngXslt.report.dir}"/> 
<mail mailhost="smtp.gmail.com" mailport="465" subject="Notification of TESTNG build result" ssl="false" user="[email protected]" password="[email protected]"> 
<from address="[email protected]"/> 
<to address="[email protected]"/> 
<message>The build has finished. A details report of this build is attached</message> 
<attachments> 
<fileset dir="testngXslt.report.dir"> 
<include name="**/*.zip"/> 
</fileset> 
</attachments> 
</mail> 
</target> 

<target name="install-jars" description="Install ANT optional jars"> 
<get dest="${ws.home}/lib/mail.jar" src="file:///${ws.home}/lib/mail.jar"/> 
<fileset dir="${ws.jars}" includes="*.jar"> 
<include name="mail.jar"/> 
<include name="activation-1.0.2.jar"/> 
</fileset> 
</target> 

</project> 
+0

问题与

回答

0

使用运行像下面

 <!-- run --> 
<target name="run" depends="compile"> 
    <testng classpath="${test.classpath}:${test.dest}"> 
     <xmlfileset dir="${ws.home}" includes="testng.xml"/> 
    </testng> 
</target> 
+0

显示同样的错误.. :( –

0

taskdef嵌套你想使用里面的任务。现在它是如何工作的。首先定义任务,然后运行它。

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

<testng classpathref="classpath.test" suitename="smsweb" outputDir="test-output" > 
    <xmlfileset dir="${ws.home}" includes="testng.xml" /> 
</testng> 
+0

不工作的哥哥同样的错误发生 –

+0

是您的classpath中。 testng.jar是否正确?在你的例子中,我复制了我的答案,你有路径'/ full/path/to/testng.jar',这显然不是一条真正的路径。我以为你只是不想显示你的目录名在线,但如果这实际上是在你的脚本中,它将需要更改为testng jar文件的真实路径。 – CAustin

+0

兄弟我用我的testNG Jars。console替换它,显示错误。带有test.classpath的classpath.test意味着带有clas的属性spath但它不起作用。等待我也用你的代码更新我的build.xml。 –

相关问题