【java 菜鸟自动化实践之五】jenkins + maven构建多个testng项目

步骤1:新建maven project项目

步骤2:新建testng的xml文件,比如,如下图:


比如,Interface_testng.xml文件:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >
<suite name="run_Interface_testng" parallel="tests" thread-count="1">
	<listeners>
		<!-- listener class-name="common.TestListener" /> <listener class-name="common.RetryListener"/ -->
		<listener class-name="org.uncommons.reportng.HTMLReporter" />
		<listener class-name="org.uncommons.reportng.JUnitXMLReporter" />
	</listeners>
	<test name="run_Interface_testng">
		<classes>
			<class name="main.run_Interface_testng" />
		</classes>
	</test>
</suite>

步骤3:在pom.xml中引入testng相关文件,可以引入多个


pom.xml:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
	<modelVersion>4.0.0</modelVersion>
	<groupId>Automation_Testing</groupId>
	<artifactId>Automation_Testing</artifactId>
	<packaging>jar</packaging>
	<version>1.0</version>
	<url>http://maven.apache.org</url>
	<dependencies>
		<dependency>
			<groupId>mysql</groupId>
			<artifactId>mysql-connector-java</artifactId>
			<version>5.1.18</version>
		</dependency>
		<dependency>
			<groupId>commons-codec</groupId>
			<artifactId>commons-codec</artifactId>
			<version>1.10</version>
		</dependency>
		<dependency>
			<groupId>org.apache.commons</groupId>
			<artifactId>commons-collections4</artifactId>
			<version>4.1</version>
		</dependency>
		<dependency>
			<groupId>commons-logging</groupId>
			<artifactId>commons-logging</artifactId>
			<version>1.2</version>
		</dependency>
		<dependency>
			<groupId>junit</groupId>
			<artifactId>junit</artifactId>
			<version>4.12</version>
			<scope>test</scope>
		</dependency>
		<dependency>
			<groupId>log4j</groupId>
			<artifactId>log4j</artifactId>
			<version>1.2.17</version>
		</dependency>
		<dependency>
			<groupId>org.apache.poi</groupId>
			<artifactId>poi</artifactId>
			<version>3.17</version>
		</dependency>
		<dependency>
			<groupId>org.apache.poi</groupId>
			<artifactId>poi-examples</artifactId>
			<version>3.17</version>
		</dependency>
		<dependency>
			<groupId>org.apache.poi</groupId>
			<artifactId>poi-excelant</artifactId>
			<version>3.17</version>
		</dependency>
		<dependency>
			<groupId>org.apache.poi</groupId>
			<artifactId>poi-ooxml</artifactId>
			<version>3.17</version>
		</dependency>
		<dependency>
			<groupId>org.apache.poi</groupId>
			<artifactId>poi-ooxml-schemas</artifactId>
			<version>3.17</version>
		</dependency>
		<dependency>
			<groupId>org.apache.poi</groupId>
			<artifactId>poi-scratchpad</artifactId>
			<version>3.17</version>
		</dependency>
		<dependency>
			<groupId>com.github.virtuald</groupId>
			<artifactId>curvesapi</artifactId>
			<version>1.04</version>
		</dependency>
		<dependency>
			<groupId>org.apache.xmlbeans</groupId>
			<artifactId>xmlbeans</artifactId>
			<version>2.6.0</version>
		</dependency>
		<dependency>
			<groupId>org.seleniumhq.selenium</groupId>
			<artifactId>selenium-java</artifactId>
			<version>2.53.0</version>
		</dependency>
		<dependency>
			<groupId>org.seleniumhq.selenium</groupId>
			<artifactId>selenium-server</artifactId>
			<version>2.53.0</version>
		</dependency>
		<dependency>
			<groupId>org.json</groupId>
			<artifactId>json</artifactId>
			<version>20171018</version>
		</dependency>
		<dependency>
			<groupId>org.testng</groupId>
			<artifactId>testng</artifactId>
			<version>6.9.10</version>
		</dependency>
		<dependency>
			<groupId>org.apache.httpcomponents</groupId>
			<artifactId>httpclient</artifactId>
			<version>4.5.4</version>
		</dependency>
		<dependency>
		    <groupId>org.apache.httpcomponents</groupId>
		    <artifactId>httpmime</artifactId>
		    <version>4.5.4</version>
		</dependency>
		<dependency>    
		    <groupId>net.sf.json-lib</groupId>    
		    <artifactId>json-lib</artifactId>    
		    <version>2.4</version>      
		    <classifier>jdk15</classifier> 
		</dependency>
		<dependency>
		    <groupId>io.appium</groupId>
		    <artifactId>java-client</artifactId>
		    <version>1.2.1</version>
		</dependency>
	     <dependency>
	            <groupId>org.uncommons</groupId>
	            <artifactId>reportng</artifactId>
	            <version>1.1.4</version>
	            <scope>test</scope>
	            <exclusions>
	                <exclusion>
	                    <groupId>org.testng</groupId>
	                    <artifactId>testng</artifactId>
	                </exclusion>
	            </exclusions>
	        </dependency>
	        <dependency>
	            <groupId>com.google.inject</groupId>
	            <artifactId>guice</artifactId>
	            <version>4.0-beta5</version>
	        </dependency>
			<dependency>
			    <groupId>org.jsoup</groupId>
			    <artifactId>jsoup</artifactId>
			    <version>1.11.2</version>
			</dependency>
			<dependency>
			    <groupId>org.quartz-scheduler</groupId>
			    <artifactId>quartz</artifactId>
			    <version>2.3.0</version>
			</dependency>
	</dependencies>
	<!-- scope标签中对应值的解释:
	 * compile,缺省值,适用于所有阶段,会随着项目一起发布。
	 * provided,类似 compile,期望 JDK、容器或使用者会提供这个依赖。如 servlet.jar。
	 * runtime,只在运行时使用,如 JDBC 驱动,适用运行和测试阶段。
	 * test,只在测试时使用,用于编译和运行测试代码。不会随项目发布。 
	 * system,类似 provided,需要显式提供包含依赖的 jar, Maven 不会在 Repository 中查找它。
	  -->		
	<build>
		<sourceDirectory>src</sourceDirectory>
		<resources>
			<resource>
				<directory>config</directory>
				<excludes>
					<exclude>**/*.java</exclude>
				</excludes>
			</resource>
			<resource>
				<directory>Datasource</directory>
				<excludes>
					<exclude>**/*.java</exclude>
				</excludes>
			</resource>
		</resources>
		<plugins>
			<plugin>
				<groupId>org.apache.maven.plugins</groupId>
				<artifactId>maven-compiler-plugin</artifactId>
				<version>3.7.0</version>
				<configuration>
					<encoding>GBK</encoding>
				</configuration>
			</plugin>
			<plugin>
				<groupId>org.apache.maven.plugins</groupId>
				<artifactId>maven-surefire-plugin</artifactId>
				<version>2.20.1</version>
				<configuration>
					<testFailureIgnore>true</testFailureIgnore>
					<!-- 解决用maven执行test时 日志乱码的问题,详见:http://www.cnblogs.com/discuss/archive/2010/10/27/1862225.html -->
					<argLine>-Dfile.encoding=UTF-8</argLine>
					<!-- 解决maven oom问题http://blog.csdn.net/e5945/article/details/7740904 -->
					<argLine>-Xms512m -Xmx1024m -XX:PermSize=128m -XX:MaxPermSize=128m</argLine>
					<forkCount>0</forkCount>
					<properties>
						<property>
							<name>usedefaultlisteners</name>
							<value>false</value>
						</property>
						<property>
							<name>listener</name>
							<value>org.uncommons.reportng.HTMLReporter,
								org.uncommons.reportng.JUnitXMLReporter</value>
						</property>
					</properties>
					<suiteXmlFiles>
						<!--  suiteXmlFile>.\Web_UI_testng.xml</suiteXmlFile>
						<suiteXmlFile>.\App_UI_testng.xml</suiteXmlFile -->
						<suiteXmlFile>.\Interface_testng.xml</suiteXmlFile>				
					</suiteXmlFiles>
					<!--定义maven运行测试生成的报表路径 -->
					<!-- reportsDirectory>./result/test-report</reportsDirectory -->
					<workingDirectory>target/</workingDirectory>
				</configuration>
			</plugin>
		</plugins>
	</build>
	<properties>
		<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
	</properties>
</project>

步骤4:搭建jenkins环境(注:环境搭建,请自行度娘,或参考本博客其他文章),并建立构建项目,配置如下图:


注:maven可以顺序或同时构建多个testng的xml文件,比如,可以同时执行webui、接口、app的多个项目自动化测试

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值