Answers for "how to test api in java"

1

java unit test an api

@Test
public void
  givenUserExists_whenUserInformationIsRetrieved_thenRetrievedResourceIsCorrect()
  throws ClientProtocolException, IOException {
  
    // Given
    HttpUriRequest request = new HttpGet( "https://api.github.com/users/eugenp" );
 
    // When
    HttpResponse response = HttpClientBuilder.create().build().execute( request );
 
    // Then
    GitHubUser resource = RetrieveUtil.retrieveResourceFromResponse(
      response, GitHubUser.class);
    assertThat( "eugenp", Matchers.is( resource.getLogin() ) );
}
Posted by: Guest on March-29-2020
-1

what to test in api

Basicall we are checking response body
to verify if request matches with response.
After that we are writing SQL query
to double check if database matches.
We can say happy path if all pass
Posted by: Guest on January-10-2021

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language