[英]Unable to generate contract tests when using spring-cloud-contract-oa3 and spring cloud contract gradle plugin
When when I specify the contract in an OA3 yml file and then build the project the build passes but it doesn't generate the contract tests .当我在 OA3 yml 文件中指定合同然后构建项目时,构建通过但它不会生成合同测试。 If I replace the OA3 yml contract file with a groovy equivalent then the build passes and it generates and runs the contract tests.如果我将 OA3 yml 合同文件替换为 groovy 等效文件,则构建通过并生成并运行合同测试。
I have the following setup:我有以下设置:
my build.gradle looks like:我的 build.gradle 看起来像:
buildscript {
repositories {
mavenCentral()
maven { url 'https://jitpack.io' }
}
dependencies {
classpath 'org.springframework.cloud:spring-cloud-contract-gradle-plugin:3.1.2'
classpath 'com.github.mzielinski:spring-cloud-contract-oa3:3.1.2.0'
}
}
plugins {
id 'org.springframework.boot' version '2.6.8'
id 'io.spring.dependency-management' version '1.0.11.RELEASE'
id 'java'
id 'war'
id 'java-library'
id 'maven-publish'
id 'com.adarshr.test-logger' version '3.0.0'
id "org.unbroken-dome.test-sets" version "4.0.0"
id 'groovy'
}
apply plugin: 'spring-cloud-contract'
testSets {
contractTest
}
ext {
springBootStarterVersion = '2.6.8'
springCloudVersion = '2021.0.3'
projectLombokVersion = '1.18.24'
}
repositories {
mavenLocal()
mavenCentral()
}
dependencies {
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.8.2'
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine'
testImplementation unitTesting
testImplementation 'org.springframework.cloud:spring-cloud-starter-contract-verifier'
compileOnly "org.projectlombok:lombok:${projectLombokVersion}"
annotationProcessor "org.projectlombok:lombok:${projectLombokVersion}"
testAnnotationProcessor "org.projectlombok:lombok:${projectLombokVersion}"
}
dependencyManagement {
imports {
mavenBom "org.springframework.cloud:spring-cloud-dependencies:${springCloudVersion}"
}
}
test {
useJUnitPlatform()
}
contractTest {
useJUnitPlatform()
}
contracts {
testFramework = org.springframework.cloud.contract.verifier.config.TestFramework.JUNIT5
baseClassForTests = 'com.my.project.contract.BaseContractTest'
testMode = 'MockMvc'
contractsPath = 'src/contractTest/resources/contracts'
}
}
@Lamminski, I guess, I was able to reproduce your issue. @Lamminski,我想,我能够重现您的问题。
First issue is with 'com.github.mzielinski:spring-cloud-contract-oa3:3.1.2.0' in buildSrc.第一个问题是 buildSrc 中的 'com.github.mzielinski:spring-cloud-contract-oa3:3.1.2.0'。 Please, move it into testImplementation.请把它移到 testImplementation 中。 Then you should be able to see generated contracts in /tmp/sccoa3___.yml files然后你应该能够在 /tmp/sccoa3___.yml 文件中看到生成的合约
Generally, spring-cloud-contract-oa3 converts open-api into yaml contracts in /tmp directory and then such files are used for generating contract DSLs with YmlContract class from SSC.一般来说,spring-cloud-contract-oa3 将 open-api 转换为 /tmp 目录下的 yaml 合约,然后这些文件用于从 SSC 生成具有 YmlContract 类的合约 DSL。
Additionally, I noticed also using my example from https://github.com/mzielinski/spring-cloud-contract-oa3/blob/develop/src/test/resources/openapi/verify_oa3.yml and your build.gradle file, that scc has a problem to convert properly contracts generated from this file in two places (to tests):此外,我还注意到使用来自https://github.com/mzielinski/spring-cloud-contract-oa3/blob/develop/src/test/resources/openapi/verify_oa3.yml的示例和您的 build.gradle 文件, scc 在两个地方(到测试)正确转换从此文件生成的合同时存在问题:
In SPOCK for example generated test has such code在 SPOCK 例如生成的测试有这样的代码
assertThatJson(parsedJson).field("['request']").isEqualTo("{"path":"/etc/passwd"}")
There is invalid escaping.存在无效转义。 Generated contract has生成的合约有
body:
path: "/etc/passwd"
so looks OK.所以看起来不错。
I am using sscoa3 in production and I did not have such issue yet, but I will try to fix YamlContract in SSC to convert it in proper way.我在生产中使用 sscoa3,我还没有遇到这样的问题,但我会尝试在 SSC 中修复 YamlContract 以正确转换它。
You are able to see stacktrace from YmlContract also by running gradle build with --debug flag.您还可以通过使用 --debug 标志运行 gradle build 从 YmlContract 看到堆栈跟踪。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.