我正在使用放心和弹簧启动来编写我的测试。
UPDATE Employees SET PayPerHour = PayPerHour * 1.1 -- everyone gets a 10% payrise YAY!
在日志中,我看到它说在端口上启动Tomcat和STarting服务Tomcat但是它失败并出现此错误 -
@RunWith(SpringJUnit4ClassRunner.class)
@SpringApplicationConfiguration(classes = ApplicationSErvice.class)
@WebAppConfiguration
@IntegrationTest("server.port:0")//dynamically pick up ports
public class MyTestClass{
@Value("${local.server.port}")
int port;
@Before
public void setup(){
RestAssured.port=port;
}
@Test
public void testMethod(){
//asserting
}
答案 0 :(得分:4)
对于Web集成测试,您应该使用@WebIntegrationTest
代替。
@RunWith(SpringJUnit4ClassRunner.class)
@SpringApplicationConfiguration(classes = Application.class)
@WebIntegrationTest
public class ApplicationTest {
@Value("${local.server.port}")
private int port;
@Before
public void setup() {
RestAssured.baseURI = "http://localhost:" + port;
}
@Test
public void testStatus() {
given().contentType(ContentType.JSON).get("/greeting").prettyPeek().then().statusCode(200);
}
@Test
public void testMessage() {
given().contentType(ContentType.JSON).get("/greeting").then()
.body("content", is("Hello, World!"));
}
}