微服務場景下的自動化測試(5)

發表于:2016-10-04來源:icodeit.org/作者:icodeit.org點擊數: 標簽:微服務
@Test public void should_create_user() { given().contentType(ContentType.JSON).body(prepareUser()). when().post( /users ). then().statusCode( 201 ). body( id , notNullValue()). body( name , is ( Junta
@Test
public void should_create_user() {
    given().contentType(ContentType.JSON).body(prepareUser()).
            when().post("/users").
            then().statusCode(201).
            body("id", notNullValue()).
            body("name", is("Juntao Qiu")).
            body("email", is("juntao.qiu@gmail.com"));
}

private User prepareUser() {
    User user = new User();
    user.setName("Juntao Qiu");
    user.setEmail("juntao.qiu@gmail.com");
    user.setPassword("password");
    return user;
}

如果使用Spring,還可以通過 profile 來切換不同的數據庫。比如下面這個例子中,默認的profile會連接數據庫 jigsaw ,而 integration 的profile會連接 jigsaw_test 數據庫:

spring:
  datasource:
    url: jdbc:mysql://localhost:3306/jigsaw
    driver-class-title: com.mysql.jdbc.Driver
    username: root
    password: password

---

spring:
  profiles: integration

  datasource:
    url: jdbc:mysql://localhost:3306/jigsaw_test
    driver-class-title: com.mysql.jdbc.Driver
    username: root
    password: password

組件測試會涉及到的組件包括:

原文轉自:http://icodeit.org/2016/10/testing-in-microservice-context/

国产97人人超碰caoprom_尤物国产在线一区手机播放_精品国产一区二区三_色天使久久综合给合久久97