2

I have been using ErrorCollector Rule for collecting the failed test cases with a code that looks something like this :

@Rule
ErrorCollector collector = new ErrorCollector();

Map<X, Y> inputOutputMap = new HashMap<X,Y>();
inputOutputMap.add(new X("Input"), new Y("Output"));

//Mocking service layers and returning expected outputs.

for(Entry<X,Y> entry : inputOutputMap.entrySet()){

     String url = "/do/something"        

     Gson gson = new Gson();
     String json = gson.toJson();

    try{
    this.mockMvc.perform(get(url)
                .contentType(MediaType.APPLICATION_JSON)
                .content(json)).andExpect(status().isInternalServerError());
    } catch(Exception e) {
        collector.checkThat(e.getMessage, entry.getValue().getMessage());
    } 

}

So my problem is after collecting all the errors is there a way I can print all the errors also the way I write the test cases is this a write way - iterating a map and checking for output for respective input?

4

1 回答 1

1

You could extend ErrorCollector and make verify public. Then call it and catch the MultipleFailureException. From that get the Throwables via getFailures.

getFailures

This is probably better than re-implementing ErrorCollector from scratch.

于 2014-06-23T13:36:04.460 回答