Spring boot 如何通过Gradle配置Spring引导应用程序以执行Pact.io提供程序测试
我想使用Spring boot 如何通过Gradle配置Spring引导应用程序以执行Pact.io提供程序测试,spring-boot,pact,Spring Boot,Pact,我想使用pact.io——消费者驱动的测试框架, 它用于测试消费者定义的api契约 我的提供者应用程序是用Spring Boot和Gradle编写的 问题: 如何配置Gradle以对提供者应用程序执行pact测试 困难的部分是-启动被测应用程序,提供API,等待它启动并运行,然后对它们启动pact测试。对于以下插件,使用了gradle execfork插件 buildscript { repositories { mavenCentral() maven
pact.io
——消费者驱动的测试框架,它用于测试消费者定义的api契约 我的提供者应用程序是用Spring Boot和Gradle编写的 问题: 如何配置Gradle以对提供者应用程序执行pact测试
困难的部分是-启动被测应用程序,提供API,等待它启动并运行,然后对它们启动pact测试。对于以下插件,使用了gradle execfork插件
buildscript {
repositories {
mavenCentral()
maven {
url 'https://plugins.gradle.org/m2/'
}
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:$springbootVersion")
classpath "gradle.plugin.com.github.hesch:gradle-execfork-plugin:0.1.15"
}
}
plugins {
id "au.com.dius.pact" version "4.2.2"
id 'com.github.hesch.execfork' version '0.1.15'
}
apply plugin: "org.springframework.boot"
jar {
baseName = 'account-api'
version = "$version"
}
dependencies {
compile(
"org.springframework.boot:spring-boot-starter-parent:$springbootVersion",
"org.springframework.boot:spring-boot-starter-web:$springbootVersion",
"org.springframework.boot:spring-boot-starter-jersey:$springbootVersion",
"javax.xml.bind:jaxb-api:2.3.1",
"org.slf4j:slf4j-api:$slf4jVersion"
)
testCompile(
"org.assertj:assertj-core:$assertjVersion",
"org.springframework.boot:spring-boot-starter-test:$springbootVersion"
)
}
task startProvider(type: com.github.psxpaul.task.JavaExecFork) {
classpath = sourceSets.main.runtimeClasspath
main = 'com.dius.account.Application'
// args = [ '-d', '/foo/bar/data', '-v', '-l', '3' ]
jvmArgs = ['-Xmx500m', '-Djava.awt.headless=true']
workingDir = "$buildDir/server"
standardOutput = "$buildDir/daemon.log"
errorOutput = "$buildDir/daemon-error.log"
// stopAfter = verify
waitForPort = 8080
waitForOutput = 'started'
}
假设Spring启动应用程序处于
package com.dius.account;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
@SpringBootApplication
public class Application {
public static void main(String[] args) {
new SpringApplicationBuilder(Application.class).run(args);
}
}
Pact为消费者测试提供了库,因此无需启动服务器 至于提供者,您的
@SpringBootTest
注释就可以了
您正在使用的gradle插件是消费者发布契约所必需的Hi-Artem-您是否有有效示例的链接?我从这个示例项目中得到的服务器的方法是:如果有一个带有TestRunner的安装程序,这对我来说会更有意义,但是我还没有找到它的任何文档。你可以使用我的,提供者:消费者:如果需要,它包括管道