java+jenkins+testng+selenium+ant
1、安裝jdk7以上
2、http://mirrors.jenkins-ci.org/windows/latest 下載最新的war包
3、cmd命令在war包目錄下執行:java -jar jenkins.war
4、輸入http://localhost:8080可以打開jenkins頁面
5、安裝TortoiseSVN,新建文件,打開后空白處右鍵TortoiseSVN——Create repository here,得到svn目錄
file:///D:/test/jenkins/test
6、打開svn目錄后,直接將eclipse項目拷貝進去,在項目上右鍵SVN commint提交
7、安裝ant,配置環境變量ANT_HOME D:/ apache-ant-1.9.0 path D:/ apache-ant-1.9.0/bin classpath
D:/apache-ant-1.9.0/lib
8、ant驗證:win+R -- cmd輸入如下命令:ant
如果出現如下內容,說明安裝成功:
Buildfile: build.xml does not exist!
Build failed
說明ant安裝成功!
9、打開http://localhost:8080,在jenkins中新建第一個自由風格的項目
10、在源碼管理中選擇Subversion,輸入項目路徑:file:///D:/test/jenkins/test/testjenkins
11、構建中選擇Execute Windows... 輸入ant
12、保存,立即構建
項目的對應build.xml和testng.xml
build.xml
如果項目只是純編譯,default設置為compile;
<?xml version="1.0" encoding="UTF-8"?> <!--Hello是工程名,testng是最后一個target的name--> <project name="Hello" default="testng" basedir="."> <!-- 導入的外部包 --> <target name="external package"> <echo message ="第一步配置外部包"/>
<!-- <taskdef resource="testngtasks" classpath="lib/testng-5.12.jar"/> --> <taskdef resource="testngtasks"> <classpath> <pathelement location="lib/testng-5.12.jar" /> </classpath> </taskdef> </target> <!-- 源文件 --> <target name="source" depends="external package"> <echo message ="第二步配置源文件"/> <property name="srcdir" location="src" /> <property name="libdir" location="lib" /> <property name="full-compile" value="true" /> </target> <!-- 路徑 --> <target name="path" depends="source"> <echo message ="第三步配置classpath路徑"/> <path id="classpath.base" /> <path id="classpath.test"> <fileset dir="${libdir}"> <include name="**/*.jar" /> </fileset> <!--<pathelement location="test" />--> <pathelement location="${srcdir}" /> <path refid="classpath.base" /> </path> </target> <!-- 清理 --> <target name="clean" depends="path"> <echo message ="第四步配置清理"/> <delete verbose="${full-compile}"> <fileset dir="${srcdir}" includes="**/*.class" /> </delete> </target> <!-- 編譯 --> <target name="compile" depends="clean"> <echo message ="第五步配置編譯"/> <javac srcdir="${srcdir}" destdir="${srcdir}" verbose="${full-compile}" includeAntRuntime="false"> <classpath refid="classpath.test" /> </javac> </target> <!-- testng自動化測試 --> <target name="testng" depends="compile"> <echo message ="第六步配置自動化測試"/> <!-- testoutput測試結果是輸出路徑 --> <testng outputdir="testoutput" classpathref="classpath.test"> <!-- testng.xml配置在src目錄下 --> <xmlfileset dir="${srcdir}" includes="testng.xml" /> </testng> </target> </project>
testng.xml
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd"> <suite name="Default suite" preserve-order="true"> <test preserve-order="true" name="baidutest"> <classes> <!-- 包名+類名 --> <class name="test.ComplexCalculationTest"> <methods> <!-- 方法名 --> <include name="DivisionTest"/> <include name="MultiplyTest"/> </methods> </class> <class name="test.SimpleCalculationTest"> <methods> <include name="AddTest"/> <include name="SubtrationTest"/> </methods> </class> </classes> </test> </suite>
浙公網安備 33010602011771號