Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Android Network Connectivity Test

Android Network Connectivity Test

Avatar for Parlinggoman Hasibuan

Parlinggoman Hasibuan

March 18, 2016
Tweet

More Decks by Parlinggoman Hasibuan

Other Decks in Programming

Transcript

  1. OUR AGENDA • HOW KMKLabs DO UNIT TESTING IN NETWORK

    • HOW KMKLabs DO INTEGRATION TESTING IN NETWORK • HOW KMKLabs DO ACCEPTANCE TESTING IN NETWORK
  2. UNIT TESTING • f(x) = …. • condition: f(x) >

    0 and f(x) <= 1 • (sigmoid function)
  3. F(x) = x * 0.001 • x = 1, f(1)

    = 0.0001 => success • x = 2, f(2) = 0.0002 => success • x = -1, f(-1) = -0.0001 => failed condition: f(x) > 1000
  4. F(x) = 1/(1+ e^(-x) ) • x = 1, f(1)

    = 0.73 => success • x = 2, f(2) = 0.88 => success • x = -1, f(-1) = 0.26 => success
  5. OUR AGENDA • HOW KMKLabs DO UNIT TESTING IN NETWORK

    • HOW KMKLabs DO INTEGRATION TESTING IN NETWORK • HOW KMKLabs DO ACCEPTANCE TESTING IN NETWORK
  6. Unit Test in Networking? import org.mockito.Mockito; import static org.mockito.Mockito.verify; 


    ... @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
  7. OUR AGENDA • HOW KMKLabs DO UNIT TESTING IN NETWORK

    • HOW KMKLabs DO INTEGRATION TESTING IN NETWORK • HOW KMKLabs DO ACCEPTANCE TESTING IN NETWORK
  8. Integration Test • What happens if some one in server

    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 ?
  9. What is that basically? • 2 Sides (client and Server)

    • Run every changes push to client or server You can use jenkins
  10. In Android side: @RunWith(RobolectricTestRunner.class) @Config(constants = BuildConfig.class, sdk = 21)


    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); }
 }
  11. OUR AGENDA • HOW KMKLabs DO UNIT TESTING IN NETWORK

    • HOW KMKLabs DO INTEGRATION TESTING IN NETWORK • HOW KMKLabs DO ACCEPTANCE TESTING IN NETWORK
  12. Acceptance Test • go to http://developer.android.com/training/testing/start/index.html • Tools that we

    need : • Espresso • UI Automator • Test Runner add to build.grade
  13. Acceptance Test • Acceptance test is a test that to

    define that feature that we worked on is based on the story