没有为我的存根生成自动测试类

时间:2019-07-24 07:11:11

标签: spring-boot stub spring-cloud-contract

没有为我的存根生成自动测试类。到了某个时候,但现在停止了。

我的基础测试班:

package address;

import org.junit.Before;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;

import CustomerPreviousAddressApplication;

import PreviousAddressController;
import io.restassured.module.mockmvc.RestAssuredMockMvc;

@RunWith(SpringRunner.class)
@SpringBootTest(classes = CustomerPreviousAddressApplication.class)
public abstract class PreviousAddressBaseTest {

    @Autowired
    private PreviousAddressController previousAddressController;

    @Before
    public void setup() {
        RestAssuredMockMvc.standaloneSetup(previousAddressController);
    }
}

实际存根:

package contracts

import org.springframework.cloud.contract.spec.Contract


Contract.make {

    description ""

    request {
        url("/previous-address")
        method GET()
    }
    response {
        status 200
        headers {
            header(
                    'Content-Type', value(consumer('text/plain;charset=ISO-8859-1'), producer(regex('text/plain;charset=ISO-8859-1')))
            )
        }
        body(
                "Send me something!"
        )
    }
}

我在pom文件中包括以下依赖项:

    <build>
      <plugins>
        <plugin>
          <groupId>org.springframework.cloud</groupId>
          <artifactId>spring-cloud-contract-maven-plugin</artifactId>
          <!-- <version>2.1.1.RELEASE</version> -->
          <version>1.2.2.RELEASE</version>
          <extensions>true</extensions>
          <configuration>
            <baseClassForTests>
                address.PreviousAddressBaseTest
            </baseClassForTests>
          </configuration>
        </plugin>
      </plugins>
    </build>

那不是我要做的全部吗?但是,尚未生成测试文件

1 个答案:

答案 0 :(得分:0)

您似乎缺少以下依赖项:

<dependency>
    <groupId>org.springframework.cloud</groupId>
    <artifactId>spring-cloud-starter-contract-verifier</artifactId>
    <scope>test</scope>
</dependency>

根据文档,该文件负责根据合同文件生成测试代码。

文档:https://spring.io/projects/spring-cloud-contract