... @Test void testGetItemCalled(){ // mock the api VidioService mockService = Mockito.mock(VidioService.class); // mock the api result when(mockService.getItems()).thenReturn(createObservableListItems()); List<Item> items = sellItemController.getItems(); // verify get items is called verify(mockService).getItems(); assertEquals(10, items.size()); // verify the api result } import ApiService class SellItemController { ... public void getItems() { apiService = buildRetrofitApiService(); //build api service return apiService.getItems(); // call the api } } SellItemController.java TestSellItemController.java
team is f**ked up the code and make the api changes ? • What happens they change the spec without telling you ? • What happens if some one of your team is fucked up the code and make the user can’t login ?
public class VidioServiceIntegrationTest { @Test public void getPopularVideos() { List<Item> items = getItemsFromApi(); assertTrue(items.size() > 0); Item firstItem = items.get(0); assertTrue(item.getTitle().length > 0); assertTrue(item.getPrice() > 0); assertNotNull(item.getSeller()); } public void getItemsFromApi() { return new RestAdapter.Builder().setEndpoint(“YOUR API PATH EX: Stagging”) .setLogLevel(RestAdapter.LogLevel.FULL) // it will run in single thread .setExecutors(Executors.newSingleThreadExecutor(), Executors.newSingleThreadExecutor()) .build() .create(ApiService.class); } }