我在 Jenkins 中有一个阶段来运行 e2e 测试我的测试如下所示:
@WebFluxTest(controllers = DHController.class)
public class E2ETest{
@BeforeEach
public void before(){
RestAssured.baseURI = System.getProperty("EndPoint");
}
@Test
public void getWelcome() throws Exception {
WebTestClient.bindToServer().baseUrl(baseURI).build().get()
.uri("/dh/account")
.exchange()
.expectStatus().isOk();
}
}
控制器类如下所示:
@RestController
@RequestMapping("/dh/account")
public class DHController {
@GetMapping()
public Mono<String> printDH() {
logger.info("print Welcome message");
return Mono.just("Welcome to DH account service.");
}
}
詹金斯输出
GET https://domain.name/dh/account
> WebTestClient-Request-Id: [1]
No content
< 502 BAD_GATEWAY Bad Gateway
<html>
<head><title>502 Bad Gateway</title></head>
<body>
<center><h1>502 Bad Gateway</h1></center>
<hr><center>openresty/1.15.8.2</center>
</body>
</html>
Executing test getWelcome() [com.dh.E2ETest] with result: FAILURE
E2ETest > getWelcome() FAILED
java.lang.AssertionError: Status expected:<200 OK> but was:<502 BAD_GATEWAY>