Gradle PactVerify任务未验证约束

时间:2019-08-18 20:17:59

标签: pact pact-jvm pact-java

我无法使用gradle pactVerify任务运行契约生产者合同测试

我是pact的新手,正在尝试在两个springboot服务之间设置pact接触测试。我创建了契约消费者方测试并生成了契约文件(例如:ConsumerService-ProviderService.json)。我正在尝试使用gradle au.com.dius.pact插件设置生产者端测试。

下面是我的build.gradle文件

import com.wiredforcode.gradle.spawn.*

buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath("org.springframework.boot:spring-boot-gradle-plugin:2.1.7.RELEASE")
        classpath('au.com.dius:pact-jvm-provider-gradle:4.0.0-beta.5')
    }
}

plugins {
    id "java"
    id "au.com.dius.pact" version "4.0.0-beta.5"
    id "com.wiredforcode.spawn" version "0.8.2"
}

apply plugin: 'idea'
apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'

bootJar {
    baseName = 'gs-actuator-service'
    version =  '0.1.0'
}

repositories {
    mavenCentral()
}

dependencies {
    compile("org.springframework.boot:spring-boot-starter-web")
    compile("org.springframework.boot:spring-boot-starter-actuator")
    testCompile("org.springframework.boot:spring-boot-starter-test")
}

test {
    useJUnitPlatform()
}

task startProvider(type: SpawnProcessTask, dependsOn: 'assemble') {
    command "java -jar $buildDir/libs/gs-actuator-service-0.1.0.jar"
    ready 'Started Application'
}

task terminateProvider(type: KillProcessTask)

pact {
    serviceProviders {
        'ProviderService' {
            host = 'localhost'
            port = 8081
            startProviderTask = startProvider
            terminateProviderTask = terminateProvider
            hasPactWith('ConsumerService') {
                // Currently we don't have pact broker and pact folder with json file is copied into build folder of producer.
                pactSource = file("$buildDir/pacts/ConsumerService-ProviderService.json")
            }
        }
    }

}

下面是ConsumerService-ProviderService.json

{
  "provider": { "name": "ProviderService" },
  "consumer": { "name": "ConsumerService" },
  "interactions": [ {
      "description": "a GET request",
      "request": { "method": "GET", "path": "/employee" },
      "response": {
        "status": 200,
        "headers": { "Content-Type": "application/json" },
        "body": {   "firstName": "some name" },
        "matchingRules": {
          "header": { "Content-Type": {
              "matchers": [{
                  "match": "regex",
                  "regex": "application/json"
                }],
              "combine": "AND"
            }
          }, "body": { "$.firstName": { "matchers": [ { "match": "type" } ], "combine": "AND" }}
        }
      }, "providerStates": [ { "name": "get Employee call is made" } ]
    }],
  "metadata": {
    "pactSpecification": { "version": "3.0.0" },
    "pact-jvm": { "version": "3.6.10" }
  }
}

当我运行./gradlew pactVerify时,什么都没有发生,服务就会启动(我可以卷曲服务)。我什至不确定生产方合同测试是否在运行。 gradle pactVerify任务永远不会完成,我只能在控制台上看到生产者服务日志。

0 个答案:

没有答案