title: Spring Boot integration tests failing when run after one another
body: <p>I have a Spring Boot integration test and a Spring Boot web integration test. Both tests pass when run individually. However, when run as part of a suite, the test that is executed second always fails. Each test starts up (and tears down) my application and, in turn, my <code>h2</code> database. I have experimented with swapping the order of the tests and it always the latter test that fails.</p>
  
  <p>What can I do to ensure that these tests are self-contained/will not affect each other?</p>
  
  <p><strong>Note:</strong> I am using the class annotations <code>@RunWith(SpringRunner.class)</code> and <code>@SpringBootTest</code> for both tests, with the web integration test passing the argument <code>webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT</code> to the latter annotation.</p>
  
  <p><strong>Integration test:</strong></p>
  
  <pre><code>@Test
  public void testFindAll() {
      List&lt;Object&gt; objects = objectRepository.findAll();
      assertThat(objects.size(), is(greaterThanOrEqualTo(0)));
  }
  </code></pre>
  
  <p><strong>Web integration test:</strong></p>
  
  <pre><code>@Test
  public void testListAll() throws IOException {
      TestRestTemplate testRestTemplate = new TestRestTemplate();
      ResponseEntity&lt;String&gt; responseEntity = testRestTemplate.getForEntity("url/api/v1/objects", String.class);
  
      assertThat(responseEntity.getStatusCode(), equalTo(OK));
  
      ObjectMapper objectMapper = new ObjectMapper();
      JsonNode responseJson = objectMapper.readTree(responseEntity.getBody());
  
      assertThat(responseJson.isMissingNode(), is(false));
      assertThat(responseJson.toString(), equalTo("[]"));
  }
  </code></pre>