TechnionYearlyProject / DailyPulseMe

A tool that tracks and analyzes your heart rate data during your calendar events, helping you live a healthier life.
https://dailypulse.azurewebsites.net
0 stars 1 forks source link

Automatic Tests for Backend. - 18hours #83

Closed mohamedMahameed closed 6 years ago

mohamedMahameed commented 6 years ago

I found this code for how to test a REST controller : this code tests a small web application which returns greeting to the user when he goes to the path "\" .

` @RunWith(SpringRunner.class) @SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT) @DirtiesContext public class HelloWorldConfigurationTests {

@LocalServerPort
private int port;

@Autowired
private TestRestTemplate restTemplate;

@Test
public void testGreeting() throws Exception {
    ResponseEntity<String> entity = restTemplate
            .getForEntity("http://localhost:" + this.port + "/", String.class);
    assertEquals(HttpStatus.OK, entity.getStatusCode());
}

} `

you have to import all the needed classes , and small google search explains each class and function very well . I think our basic tests should go like in the code above.

mabdalazez commented 6 years ago

i has finished to build the automatic end to end tests template and i have wrote some tests for example and now we can test our controller as we want. this is tutorials i have used to achieve that : http://www.baeldung.com/integration-testing-in-spring https://docs.spring.io/spring-security/site/docs/current/reference/html/test-mockmvc.html https://docs.spring.io/spring-boot/docs/current/reference/html/boot-features-testing.html#boot-features-testing-spring-boot-applications-testing-autoconfigured-tests