zoukankan      html  css  js  c++  java
  • 契约测试SpringCloud Contract遇到的问题

    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://stackoverflow.com/questions/42405945/spring-cloud-contract-generated-test-doesnt-have-mockmvc-configured-and-fails

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

    package com.xxx.xxx.contract;
    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.ActiveProfiles;
    import org.springframework.test.context.junit4.SpringRunner;
    import org.springframework.web.context.WebApplicationContext;
    
    import com.xxx.xxx.Application;
    
    import io.restassured.module.mockmvc.RestAssuredMockMvc;
    @RunWith(SpringRunner.class)
    @SpringBootTest(classes = Application.class)
    //@ActiveProfiles("unit-test")  //当契约测试时想使用不同的配置文件时,取消注释时会使用loan-unit-test.yml配置文件
    public abstract class ConstractTestBase {
        static{
            System.setProperty("aes.xxx", "abc");
        }
    
        @Autowired
        private WebApplicationContext context;
        @Before
        public void setUp() throws Exception {
            RestAssuredMockMvc.webAppContextSetup(context);
        } 
    }

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

    contracts {
        baseClassForTests = 'com.xxx.xxx.contract.ConstractTestBase' 
    }
  • 相关阅读:
    webpack打包注意事项
    打印内存, 打印16进制
    c++ 字符集转换
    RegSvr32 加载失败,找不到指定的模块
    错误码设计
    mfc 移动绘制的图形
    获取、设置光标
    c++ 函数中定义函数
    python linux 自动补全 tab.py
    3.4.5节 完整神经网络样例程序
  • 原文地址:https://www.cnblogs.com/duanxz/p/14919810.html
Copyright © 2011-2022 走看看