ClassNotFoundException:使用MockRestServiceServer时出现org.junit.Assert异常

时间:2018-12-24 17:24:02

标签: spring-boot junit spring-boot-test

我正在尝试运行以下测试

  import org.springframework.test.web.client.MockRestServiceServer;
    ....            

@Test
void successPost () {
MockRestServiceServer server = MockRestServiceServer.bindTo(restTemplate).build();

    server.expect(once(), requestTo("http://localhost:8080/test"))
                .andExpect(header("X-AUTH", "myToken"))
                .andRespond(withSuccess("{ \"msg\":\"hi\"}", MediaType.APPLICATION_JSON));

            WebClient<String, DummyResponse> client = new WebClient<>(restTemplate, retryTemplate, DummyResponse.class);
            DummyResponse result = client.post("http://localhost:8080","/test", "myRequest", "myToken");

            // Verify all expectations met
            server.verify();
            assertThat(result.getMsg(), is("hi"));
}

,当我有.andExpect(header("X-AUTH", "myToken"))时失败 ClassNotFoundException:org.junit.Assert

项目仅包含JUnit 5依赖项和

<dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-test</artifactId>
        <version>2.1.0.RELEASE</version>
        <scope>test</scope>
        <exclusions>
            <exclusion>
                <groupId>junit</groupId>
                <artifactId>junit</artifactId>
            </exclusion>
        </exclusions>
    </dependency>

0 个答案:

没有答案