准备:
首先您需要了解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.2 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
配置:jdk,maven,git

3.4 系统配置

更改主目录可以通过:我的电脑-高级系统设置-环境变量;添加JENKINS_HOME.重启jenkins后生效。



3.5 新建构建类型为maven的项目
3.5.1 jenkins-新建-构建一个maven项目

3.5.2 源码配置

repository url:GITHUB上项目地址
credentials:凭证 通过 Add 添加凭证

3.5.2 构建触发器
通过配置日程表来配置构建触发时间。

3.5.3 配置maven执行

root pom:构建项目的时候回从pom.xml 开始执行,pom.xml中配置了要执行的testng的xml文件。
<configuration>
<suiteXmlFilles>
<suiteXmlFile>testcase.xml</suiteXmlFile>
</suiteXmlFiles>
<reportsDirectory>./result/test-report</reportsDirectory>
</configuration>
3.5.4 构建后操作

3.6 执行构建


3.7 执行完成


网友评论