契约测试遇到的问题

1、java.lang.IllegalStateException: You haven‘t configured a MockMVC instance. You can do this statically

在服务提供方,执行gradle test后,契约的validate失败,错误信息如下图:

契约测试遇到的问题

 

It turns out that I need to add the base class that I am missing(like the FraudBase.java) in the sample. That‘s where the MockMvc is being instantiated.

https://*.com/questions/42405945/spring-cloud-contract-generated-test-doesnt-have-mockmvc-configured-and-fails

第一步:我加了一个base class如下:

package loan.contract;
import org.junit.Before;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.ActiveProfiles;

import com.LoanApplication;
import com.web.PrePayController;

import io.restassured.module.mockmvc.RestAssuredMockMvc;
/**
 * @author duanxz
 * 2021年6月22日 下午6:24:40
 */
@SpringBootTest(classes = LoanApplication.class)
@ActiveProfiles("unit-test")
public class LoanBaseControllerTest {

    @Autowired
    private PrePayController prePayController;

    @Before
    public void before(){
        RestAssuredMockMvc.standaloneSetup(prePayController);
    }

}

第二步:在gradle脚本中,指定

contracts {
    baseClassForTests = ‘loan.LoanBaseControllerTest‘
}

 

契约测试遇到的问题

上一篇:Git命令练习


下一篇:celery 启动后等10几秒就报有关于ping command 的错误