Skip to content

Instantly share code, notes, and snippets.

@gbzarelli
Created July 30, 2020 01:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gbzarelli/ca01ddcf1026cf57524400e26a8e4b3e to your computer and use it in GitHub Desktop.
Save gbzarelli/ca01ddcf1026cf57524400e26a8e4b3e to your computer and use it in GitHub Desktop.
Used in Medium article about Tests
@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT)
class SampleE2ETests {
@Autowired
private TestRestTemplate restTemplate;
@Autowired
private PersonRepository personRepository;
@AfterEach
void tearDown() throws Exception {
personRepository.deleteAll();
}
@Test
void exampleTest() {
Person peter = new Person("Peter", "Pan");
personRepository.save(peter);
String body = restTemplate.getForObject("/hello/Pan", String.class);
assertThat(body).isEqualTo("Hello Peter Pan!");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment