Skip to content

Converting Integration tests to Local Server tests#278

Merged
domesticmouse merged 19 commits intogooglemaps:okhttp3from
domesticmouse:okhttp3
Jun 28, 2017
Merged

Converting Integration tests to Local Server tests#278
domesticmouse merged 19 commits intogooglemaps:okhttp3from
domesticmouse:okhttp3

Conversation

@domesticmouse
Copy link
Copy Markdown
Contributor

Initial sketch of how I am thinking about crafting non integration tests out of the current integration test suite.

PTAL @markmcd

@domesticmouse domesticmouse changed the title Splitting DirectionsApiTest into Integration and Local Converting Integration tests to Local Server tests Jun 20, 2017
@domesticmouse domesticmouse requested a review from markmcd June 21, 2017 02:44
@domesticmouse domesticmouse self-assigned this Jun 22, 2017
Copy link
Copy Markdown
Contributor

@markmcd markmcd left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is great. I like the try-with-resources local context thingo. Ideally we would not need to use the mock server in the middle and could just provide a transport interface but that's one for the TODO list I think.

Only concerns are:

  • There are some floating point comparisons that assume certain precision mismatches, I could see these failing when run on different chips. Ideally we'd use assertEquals with an epsilon but if they come from strings in your serialised responses then maybe it's a non-issue.
  • These tests are only really testing that responses are deserialised into objects correctly. Given we're not doing it implicitly anymore, perhaps in the future we could add tests to ensure that objects are serialised correctly to outgoing requests, as well as the reverse.

I like the general structure too - I can imagine a future refactor where we use annotations or something to describe which in/out JSON files to use per-test, but that's one for another day ;)

import com.google.maps.model.TransitRoutingPreference;
import com.google.maps.model.TravelMode;
import com.google.maps.model.Unit;
import java.util.ArrayList;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: this looks like it's in the wrong place

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd agree, but google-java-format seems happy with it.


package com.google.maps;

import static org.junit.Assert.assertEquals;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: import ordering should follow style guide at go/javastyle (you should be able to set this in your IDE too)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Turns out there is tooling for it now...

assertThat(result.routes[0].overviewPolyline.decodePath().size(), not(0));
assertTrue(result.routes[0].legs[0].startAddress.startsWith("Sydney NSW"));
assertTrue(result.routes[0].legs[0].endAddress.startsWith("Melbourne VIC"));
try (LocalTestServerContext sc = new LocalTestServerContext(getDirectionsResponse)) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice idea 👍

assertNotNull(result.routes[0].legs[0]);
assertNotNull(result.routes[0].legs[0].arrivalTime);
assertNotNull(result.routes[0].legs[0].departureTime);
try(LocalTestServerContext sc = new LocalTestServerContext(responseTimesArePopulatedCorrectly)) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: space after try (there are a bunch of these)


assertNotNull(result.routes);
try(LocalTestServerContext sc = new LocalTestServerContext(
"{\"routes\": [{}],\"status\": \"OK\"}")){
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

one day java will support multiline here-strings 😩

}

@Test
public void testAsync() throws Exception {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a weird test to have in GeocodingApiTests - maybe it belongs it a context or pending result test? Not particularly relevant to your change though so feel free to ignore.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll have some de-dupe and re-org work to do on this test suite next Q

@domesticmouse domesticmouse merged commit a977e3e into googlemaps:okhttp3 Jun 28, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants