代码之家  ›  专栏  ›  技术社区  ›  Andy

黄瓜测试用例在一起运行时失败,但在单独运行时通过

  •  0
  • Andy  · 技术社区  · 7 年前

    Scenario Outline: To check if the service returns all the ids when more than 10000 Ids are returned by the query
    Given sample request <payload>
     When the new end point is invoked
     Then the service returns <idCount> Ids
    
    Examples: 
      | payload          | idCount | 
      | sample-payload-1 | 17575   | 
      | sample-payload-2 | 4       | 
      | sample-payload-3 | 23535   | 
      | sample-payload-4 | 34535   | 
    

    public class MyStepdefs extends AbstractStepsDefs {
    
    @Autowired
    MyController myController;
    
    private String requestPayload;
    
    private List<String> ids;
    
    @Given("^sample request (.+)$")
    public void sample_request_something(String payload) throws Throwable {
        this.requestPayload = payload;
    }
    
    @When("^the new end point is invoked$")
    public void the_new_end_point_is_invoked() throws Throwable {
        String responseJSON = MyUtil.getPostResponseJSON(myController, "/ids", requestPayload);
        responseJSON = responseJSON.replace("[", "").replace("]", "").replaceAll("\"", "");
        ids = Arrays.asList(responseJSON.split(","));
    }
    
    @Then("^service returns list of available (.+)$")
    public void service_returns_list_of_available_something(String ids) throws Throwable {
        List<String> list = Arrays.asList(ids.split(","));
        Assert.assertTrue(this.ids.containsAll(list));
    }
    
    @Then("^the service returns (.+) ids$")
    public void the_service_returns_ids(String idCount) throws Throwable {
        System.out.println("Actual Size:" + this.ids.size());
        System.out.println("Expected Size:" + Integer.parseInt(idCount));
        Assert.assertEquals(this.ids.size(), Integer.parseInt(idCount));
    }
    
    @After
    @Before
    public void cleanUp() {
        ids = null;
    }
    

    第二个 then

    ids 列表不相同。但是当我单独运行同一个测试时,在大小匹配时不会得到这个错误。

    1 回复  |  直到 7 年前
        1
  •  1
  •   Andy    7 年前

    counter sample-payload-1 ]会单独工作,因为它有一个新的实例副本 .随后的样品将只有 柜台

    改变了的 .

    返回 0 柜台

    如果 scope Singleton