准备:
首先您需要了解maven、testNG、jenkins、tomcat、git。源代码放在github上。
如果你需要在本地执行,你需要安装jenkins+tomcat
1、maven项目
1.1 在idea中创建maven项目
1.2 pom.xml
需要加入maven、testng的依赖
<dependency> <groupId>org.testng</groupId> <artifactId>testng</artifactId> <version>6.9.10</version> </dependency> <dependency> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <!-- 经过测试 maven-compiler-plugin 插件版本请使用3.3,否则在jenkins上无法执行测试 --> <version>3.3</version> <type>maven-plugin</type> </dependency> |
1.3 testNG
通过配置xml文件制定要执行的用例
<?xml version="1.0" encoding="UTF-8"?> <suite name="Suite" parallel="false"> <test name="Test"> <classes> <class name="com.demo.test.testcase.Compare"/> <class name="com.demo.test.testcase.Compare_queryGhtRegwaterView"/> </classes> </test> <!-- Test --> <listeners> <!-- arrow插件实现用例失败重跑以及生成测试报告 --> <listener class-name="com.demo.arrow.TestResultListener" /> <listener class-name="com.demo.arrow.RetryListener" /> <listener class-name="com.demo.arrow.PowerEmailableReporter" /> </listeners> </suite> <!-- Suite --> |
2 Git
2.1 github官网 在github上注册
2.2 本地项目上传到git
idea中的配置:file-setting-version control-github
配置的时候可以点击test测试连接是否正常。
上传代码:
登陆github查看项目地址
3.jenkins+tomcat
3.1 安装tomcat9+jenkins2.5
3.2 jenkins 插件安装
安装插件:Email Extension Plugin ,Git plugin,Maven Integration plugin
3.3 Global Tool Configuration
配置:jdk,maven,git
3.4 系统配置
更改主目录可以通过:我的电脑-高级系统设置-环境变量;添加JENKINS_HOME.重启jenkins后生效。