1、POM 文件:

<?xml version="1.0" encoding="UTF-8"?>
<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>zhongan</groupId>
<artifactId>collection-test</artifactId>
<version>1.0-SNAPSHOT</version> <properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
</properties> <build>
<defaultGoal>compile</defaultGoal>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.6.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<!-- Optional plugins for using Spock -->
<!-- Only required if names of spec classes don't match default Surefire patterns (`*Test` etc.) -->
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.19.1</version>
<configuration>
<includes>
<!--<include>themis/shenpijieguo/*Spec</include>-->
<include>themis/shenpijieguo/*Spec</include>
</includes>
</configuration>
</plugin>
<!-- Mandatory plugins for using Spock -->
<plugin>
<!-- The gmavenplus plugin is used to compile Groovy code. To learn more about this plugin,
visit https://github.com/groovy/GMavenPlus/wiki -->
<groupId>org.codehaus.gmavenplus</groupId>
<artifactId>gmavenplus-plugin</artifactId>
<version>1.4</version>
<executions>
<execution>
<goals>
<goal>compile</goal>
<goal>testCompile</goal>
</goals>
</execution>
</executions>
</plugin> <plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-report-plugin</artifactId>
<version>2.20</version>
<configuration>
<showSuccess>false</showSuccess>
</configuration>
</plugin>
<!-- Only required for spock-example build -->
<!--<plugin>-->
<!--<artifactId>maven-deploy-plugin</artifactId>-->
<!--<version>2.5</version>-->
<!--<configuration>-->
<!--<skip>true</skip>-->
<!--</configuration>-->
<!--</plugin>--> <!-- 用mvn ant生成格式更友好的report -->
<plugin>
<groupId>org.jvnet.maven-antrun-extended-plugin</groupId>
<artifactId>maven-antrun-extended-plugin</artifactId> <!-- //////////// -->
<executions>
<execution>
<id>test-reports</id>
<phase>test</phase> <!-- //////////// -->
<configuration>
<tasks>
<junitreport todir="${basedir}/target/surefire-reports">
<fileset dir="${basedir}/target/surefire-reports">
<include name="**/*.xml" />
</fileset>
<report format="frames" todir="${basedir}/target/surefire-reports" /> <!-- //////////// -->
</junitreport>
</tasks>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>org.apache.ant</groupId>
<artifactId>ant-junit</artifactId>
<version>1.10.1</version>
</dependency>
<dependency>
<groupId>org.apache.ant</groupId>
<artifactId>ant-trax</artifactId>
<version>1.8.0</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</build> <dependencies>
<!-- Mandatory dependencies for using Spock -->
<dependency>
<groupId>org.spockframework</groupId>
<artifactId>spock-core</artifactId>
<version>1.0-groovy-2.4</version>
</dependency>
<!-- Optional dependencies for using Spock -->
<dependency> <!-- use a specific Groovy version rather than the one specified by spock-core -->
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy-all</artifactId>
<version>2.4.1</version>
</dependency>
<dependency> <!-- enables mocking of classes (in addition to interfaces) -->
<groupId>cglib</groupId>
<artifactId>cglib-nodep</artifactId>
<version>3.1</version>
<!--<scope>profile.test</scope>-->
</dependency>
<dependency> <!-- enables mocking of classes without default constructor (together with CGLIB) -->
<groupId>org.objenesis</groupId>
<artifactId>objenesis</artifactId>
<version>2.1</version>
<!--<scope>profile.test</scope>-->
</dependency>
<dependency> <!-- only required if Hamcrest matchers are used -->
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-core</artifactId>
<version>1.3</version>
<!--<scope>profile.test</scope>-->
</dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<version>1.4.185</version>
</dependency>
<dependency>
<groupId>com.github.rest-driver</groupId>
<artifactId>rest-server-driver</artifactId>
<version>1.1.43</version>
</dependency>
<dependency> <!--mysql 数据库 driver jar-->
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.6</version>
</dependency> <!-- Spring jar-->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>4.2.3.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-aop</artifactId>
<version>4.2.3.RELEASE</version>
<!--<version>${springframework.version}</version>-->
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-beans</artifactId>
<version>4.2.3.RELEASE</version>
<!--<version>${springframework.version}</version>-->
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>4.2.3.RELEASE</version>
<!--<version>${springframework.version}</version>-->
</dependency>
<!--<dependency>-->
<!--<groupId>org.springframework</groupId>-->
<!--<artifactId>spring-context-support</artifactId>-->
<!--&lt;!&ndash;<version>${springframework.version}</version>&ndash;&gt;-->
<!--</dependency>-->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-expression</artifactId>
<version>4.2.3.RELEASE</version>
</dependency> <dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
<version>2.5.4</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.5.4</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
<version>2.5.4</version>
</dependency> <!--读取Excel-->
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
<version>3.10-FINAL</version>
</dependency> <!--Json-->
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>1.1.15</version>
</dependency> <dependency>
<groupId>com.jayway.jsonpath</groupId>
<artifactId>json-path</artifactId>
<version>2.2.0</version>
</dependency> <!-- guava -->
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>18.0</version>
</dependency>
<!-- Joda Time--> <dependency>
<groupId>joda-time</groupId>
<artifactId>joda-time</artifactId>
<version>2.3</version>
</dependency>
<!-- https://mvnrepository.com/artifact/javassist/javassist -->
<dependency>
<groupId>javassist</groupId>
<artifactId>javassist</artifactId>
<version>3.12.1.GA</version>
</dependency>
<!--<dependency>-->
<!--<groupId>com.athaydes</groupId>-->
<!--<artifactId>spock-reports</artifactId>-->
<!--<version>1.4.0</version>-->
<!--<scope>test</scope>-->
<!--&lt;!&ndash; this avoids affecting your version of Groovy/Spock &ndash;&gt;-->
<!--<exclusions>-->
<!--<exclusion>-->
<!--<groupId>*</groupId>-->
<!--<artifactId>*</artifactId>-->
<!--</exclusion>-->
<!--</exclusions>-->
<!--</dependency>--> <!-- // if you don't already have slf4j-api and an implementation of it in the classpath, add this! -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.13</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<version>1.7.13</version>
<scope>test</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/junit/junit -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache.ant/ant-trax -->
<!--<dependency>-->
<!--<groupId>org.apache.ant</groupId>-->
<!--<artifactId>ant-trax</artifactId>-->
<!--<version>1.8.0</version>-->
<!--</dependency>-->
<!--<dependency>-->
<!--<groupId>org.apache.ant</groupId>-->
<!--<artifactId>ant-junit</artifactId>-->
<!--<version>1.10.1</version>-->
<!--</dependency>-->
<dependency>
<groupId>org.jvnet.maven-antrun-extended-plugin</groupId>
<artifactId>maven-antrun-extended-plugin</artifactId>
<version>1.43</version>
</dependency> </dependencies> <repositories>
<!-- Only required if a snapshot version of Spock is used -->
<repository>
<id>spock-snapshots</id>
<url>https://oss.sonatype.org/content/repositories/snapshots/</url>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories> <!-- Only required in spock-example build -->
<distributionManagement>
<repository>
<id>foo</id>
<url>file:///fake.repository.to.make.maven.happy</url>
</repository>
<snapshotRepository>
<id>bar</id>
<url>file:///fake.repository.to.make.maven.happy</url>
</snapshotRepository>
</distributionManagement>
</project> 2、测试类父类:继承Specification 初始化数据库,cookie等
package themis

import com.github.restdriver.serverdriver.RestServerDriver
import commons.CommonUtil
import spock.lang.Shared
import spock.lang.Specification /**
* 测试类-基类
* (添加了几个db连接的static属性)
*
* Created by lyh2015 on 16/7/13.
*/
class BaseSpockTest extends Specification {
@Shared static themis_db = CommonUtil.getSqlInstanceOfthemisdb()
@Shared static cookie = collection.version.Common.getcookie(Common.loginurl,Common.loginparam)
@Shared header_cookie = RestServerDriver.header("Cookie",cookie)
} 3、测试类,继承基础父类
package themis.shenpijieguo

import spock.lang.Unroll
import themis.BaseSpockTest
import themis.Common class applygetApplyDetailInputSpec extends BaseSpockTest { def setupSpec() {
//TODO: 设置每个测试类的环境
}
def setup() {
//TODO: 设置每个测试方法的环境,每个测试方法执行一次
} @Unroll("该case验证接口url=#url,入参applyId=#applyId,ruleId=#ruleId")
def "测试方法1"() {
given: "清理脏数据"
// handleOk &= themis_db.execute('''delete from case_operation_records where id=?''',id);
// and: "添加测试数据"
// handleOk &= themis_db.execute('''delete from case_operation_records where id=?''',id);
println("themis_db:" + themis_db.getConnection().getMetaPropertyValues().toString())
and: "实际值"
def paramStr=""
HashMap paramMap = new HashMap();
paramMap.put("ruleId",ruleId)
paramMap.put("applyId",applyId) Set keySets=paramMap.keySet()
for (String keyName:keySets){
if (paramMap.get(keyName)!=""){
paramStr+="&"+keyName+"="+paramMap.get(keyName)
}
}
paramStr=paramStr.substring(1, paramStr.length())
def reponse = Common.PostUrl(url,paramStr, header_cookie)
// def content = reponse.getContent()
def jsonNodes=reponse.asJson()
println("paramStr:" + paramStr)
println("reponse:" + reponse)
println("jsonNodes:" + jsonNodes)
def r_status = reponse.getStatusCode()
def r_success=jsonNodes.get("success").asText()
def r_errorMsg=jsonNodes.get("errorMsg").asText()
def r_errorCode=jsonNodes.get("errorCode").asText()
def r_attributes=jsonNodes.get("attributes").asText()
def r_attributesJson=jsonNodes.get("attributesJson").asText()
def r_exception=jsonNodes.get("exception").asText() and: "预期值"
//TODO:
expect: "随处可用的断言"
r_status==200&&r_success=="true"&&r_errorMsg==""&&r_errorCode==""&&r_attributes=="null"&&r_attributesJson=="null"&&r_exception=="null" where: "不是必需的测试数据"
index | applyId|ruleId| url
1 | 10975001|2230012|Common.hostUrl+"/apply/getApplyDetailInput.json"
} def cleanup() {
//TODO: 清理每个测试方法的环境,每个测试方法执行一次
} def cleanupSepc() {
//TODO: 清理每个测试类的环境
}
} 4、用例执行:
1)使用Junit suite执行:
package themis;

import org.junit.runner.RunWith;
import org.junit.runners.Suite;
import org.junit.runners.Suite.SuiteClasses;
import themis.shenpijieguo.applydetailSearchByReportSpec;
import themis.shenpijieguo.applydetailSearchSpec; @RunWith(Suite.class)
@SuiteClasses({applydetailSearchByReportSpec.class,applydetailSearchSpec.class})
public class JunitTestSuites {
} 2)使用maven-surefire-plugin,maven-surefire-report-plugin执行 a、在pom文件中的surefire插件中指定运行的测试类,执行命令mvn clean test时在\target\surefire-reports生成xml和TXT结果文件。
b、mvn surefire-report:report时,生成\target\site\surefire-report.html结果文件
c、pom文件配置见文章开头

上述HTML格式太丑,采用下列插件HTML格式要更好
3)使用maven-antrun-extended-plugin执行
a、pom文件配置见文章开头
b、使用命令mvn clean test ,生成\target\surefire-reports\index.html结果文件




												

spock+maven+junitReport接口测试框架的更多相关文章

  1. JAVA+Maven+TestNG搭建接口测试框架及实例

    1.配置JDK 见另一篇博客:http://www.cnblogs.com/testlurunxiu/p/5933912.html 2.安装Eclipse以及TestNG Eclipse下载地址:ht ...

  2. 2--JAVA+Maven+TestNG搭建接口测试框架搭建

    1.配置JDK 2.安装Eclipse以及TestNG Eclipse下载地址:http://beust.com/eclipse TestNG安装过程:输入网址:http://beust.com/ec ...

  3. ITF Demo代码(用VBScript构建的接口测试框架)

    ITF Demo代码(用VBScript构建的接口测试框架) http://blog.csdn.net/testing_is_believing/article/details/20872629

  4. 基于LoadRunner构建接口测试框架

    基于LoadRunner构建接口测试框架 http://www.docin.com/p-775544153.html

  5. 初探接口测试框架--python系列7

    点击标题下「蓝色微信名」可快速关注 坚持的是分享,搬运的是知识,图的是大家的进步,没有收费的培训,没有虚度的吹水,喜欢就关注.转发(免费帮助更多伙伴)等来交流,想了解的知识请留言,给你带来更多价值,是 ...

  6. 初探接口测试框架--python系列2

    点击标题下「蓝色微信名」可快速关注 坚持的是分享,搬运的是知识,图的是大家的进步,没有收费的培训,没有虚度的吹水,喜欢就关注.转发(免费帮助更多伙伴)等来交流,想了解的知识请留言,给你带来更多价值,是 ...

  7. 初探接口测试框架--python系列3

    点击标题下「微信」可快速关注 坚持的是分享,搬运的是知识,图的是大家的进步,没有收费的培训,没有虚度的吹水,喜欢就关注.转发(免费帮助更多伙伴)等来交流,想了解的知识请留言,给你带来更多价值,是我们期 ...

  8. 初探接口测试框架--python系列4

    点击标题下「蓝色微信名」可快速关注 坚持的是分享,搬运的是知识,图的是大家的进步,没有收费的培训,没有虚度的吹水,喜欢就关注.转发(免费帮助更多伙伴)等来交流,想了解的知识请留言,给你带来更多价值,是 ...

  9. 初探接口测试框架--python系列5

    点击标题下「蓝色微信名」可快速关注 坚持的是分享,搬运的是知识,图的是大家的进步,没有收费的培训,没有虚度的吹水,喜欢就关注.转发(免费帮助更多伙伴)等来交流,想了解的知识请留言,给你带来更多价值,是 ...

随机推荐

  1. Qt笔记——Event

    #ifndef MYBUTTON_H #define MYBUTTON_H #include <QPushButton> class MyButton : public QPushButt ...

  2. PO/POJO/BO/DTO/VO的区别(转)

    PO :persistent object持久对象 1 .有时也被称为Data对象,对应数据库中的entity,可以简单认为一个PO对应数据库中的一条记录. 2 .在hibernate持久化框架中与i ...

  3. C# 对话框使用大全

    对话框中我们常用了以下几种:1.文件对话框(FileDialog) 它又常用到两个: 打开文件对话框(OpenFileDialog) 保存文件对话(SaveFileDialog)2.字体对话框(Fon ...

  4. HDU 1465.装错信封-递推

    不容易系列之一 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Sub ...

  5. HDU 多校1.4

    Division Game Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others) ...

  6. Codeforces #427 Div2 D

    #427 Div2 D 题意 给出一个字符串,求它的子串中为 \(k-palindrome\) 的个数. \(1-palindrome\) 要求是一个回文串. \(k-palindrome (k &g ...

  7. Dfs【p4906】小奔关闹钟

    Background 由于今天是星期一,闹钟准时响了,由于小奔太困了,所以她想关停闹钟. Description 可是,他的闹钟电路太复杂了,有很多个开关,每个开关都连着其他开关,其他开关又连着更多的 ...

  8. 素数路(prime) (BFS)

    问题 C: 素数路(prime) 时间限制: 1 Sec  内存限制: 64 MB提交: 8  解决: 5[提交][状态][讨论版] 题目描述 已知一个四位的素数,要求每次修改其中的一位,并且要保证修 ...

  9. Fiddler 高级用法:Fiddler Script 与 HTTP 断点调试

    转载自 https://my.oschina.net/leejun2005/blog/399108 1.Fiddler Script 1.1 Fiddler Script简介 在web前端开发的过程中 ...

  10. Oracle 后台进程

    一.基本后台进程       1.数据库写入进程(DBWn):       数据库写入程序讲数据库告诉缓存区中的修改块写入数据文件.对于多数系统来说,一个数据库写入程序(DBW0)就已经足够,但是对于 ...