title: Collect JSON object in a file when a Junit test fails
body: <p>I have ~50 JSON arrays as an array of models being plugged into Unit tests to compare resultant configs. Each file looks like this:
  0.json
  1.json... and so on</p>
  
  <p>[{model1},{model2},{model3}]
   I am trying to run unit tests to compare the resultant configs and want to run the tests in a manner that the test itself keeps running and collect the models if an assertion fails and output it to a json file somewhere.</p>
  
  <p>Say, model2 fails, I want to collect model2 into a file output.json as an array</p>
  
  <p>Till now, the code looks like this, even if the test is file by file, its fine, but will save me days of effort:</p>
  
  <pre><code>@Test
  public void compareAWithB() throws Exception {
      File lbJsonFile1 = new File("src/test/resources/iad_ad3/6.json");
          compareAWithBHelper(lbJsonFile1);
  }
  
  public void compareAWithBHelper(File lbJsonFile) throws Exception {
          Model[] dtos = new ObjectMapper().readValue(lbJsonFile, Model[].class);
          for(Model dto : dtos) {
              Model model = ModelConverter.apiToDao(dto);
              String A = doSomeThing();
              String B = doSomething2();
  
              Assert.assertEquals(A,B);
  //Required: if assert fails, collect the json object and continue
  }
  
  </code></pre>
  
  <p>I tried using SoftAssertions in AssertJ, but weirdly, it was not printing out all the json objects OR maybe, I don't really understand the checkThat() method properly.</p>
  
  <p>Tried using collectors.checkThat, couldn't get it to work reliably. This is a production area, so, don't have much room for errors, and wanna reduce the manual effort. </p>
  
  <p>Made another attempt to use collectors as one of the posts on stackoverflow, couldn't get it to work reliably</p>
  
  <pre><code>/*try {
                  collector.checkThat(A, CoreMatchers.equalTo(B));
              } catch (AssertionError error) {
                  System.out.println(dto.toString());
                  throw new AssertionError(error.getMessage());
  }*/
  </code></pre>
  
  <p>Can someone please help ?</p>