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

Continuous integration and deployment on Android

Continuous integration and deployment on Android

Droidcon Bucharest 2016 slides

Dino Kovač

March 12, 2016
Tweet

More Decks by Dino Kovač

Other Decks in Programming

Transcript

  1. ABOUT INFINUM • independent design and development agency • 90

    employees • 15 Android Engineers • hundreds of projects
  2. ANDROID LINT • common android specific issues and best practices

    • LinearLayout orientation • using method introduced in SDK level > minSdk • missing super calls
  3. CHECKSTYLE • helps to keep a consistent code style •

    highly configurable using config file • works well in combination with AS code style if(url.equals(otherUrl)){
 System.out.print("it's equal!");
 }
 
 if(url.equals(otherUrl))
 System.out.print("it's equal!");
 
 if (url.equals(otherUrl)) {
 System.out.print("it's equal!");
 }
  4. PMD, FINDBUGS • warn you about common Java pitfalls •

    findbugs works on class files • pmd works on source files
  5. JAVA.NET.URL @Test
 public void urlEquals() throws Exception {
 URL url

    = new URL("https://infinum.co");
 URL otherUrl = new URL("https://www.infinum.co");
 
 Assert.assertEquals(url, otherUrl);
 }
  6. JAVA.NET.URL - JAVADOCS • Two hosts are considered equivalent if

    both host names can be resolved into the same IP addresses; else if either host name can't be resolved, the host names must be equal without regard to case; or both host names equal to null. • Since hosts comparison requires name resolution, this operation is a blocking operation.
  7. MATH.ABS • does not always return positive numbers! • integer

    values range from -2147483648 to 2147483647 Assert.assertTrue(Math.abs(Integer.MIN_VALUE) >= 0);
  8. TESTING APPROACHES • instrumentation tests - robotium / espresso •

    unit tests - plain JUnit • functional tests - robolectric
  9. TESTS • we use a combination of unit tests and

    functional tests • centered around the clients needs and the specification
  10. @Test
 public void correctLoginRequest() throws Exception {
 String user =

    "testUserName";
 String pass = "testPass0&";
 
 enqueueResponse("sdk-login-response.json");
 Sdk.login(user, pass, mock(SdkCallback.class));
 
 RecordedRequest request = takeLastRequest();
 
 assertThat(request.getMethod()).isEqualTo("POST");
 assertThat(request.getPath()).isEqualTo("/login");
 assertThat(request.getHeader(“Accept")) .isEqualTo("application/json");
 assertThat(request.getHeader(“Content-Type")) .isEqualTo("application/x-www-form-urlencoded");
 assertThat(request.getBody().readUtf8()) .isEqualTo("login=" + user + "&password=" + "testPass0%26");
 }
  11. @Test
 public void successfulLogoutDeletesTokens() throws Exception {
 stub(mockPlatform().preferenceStore().getAccessToken()) .toReturn("abcdefghijklmnopqrstuvwyxz0123456789");
 


    enqueueEmptyResponse(HttpURLConnection.HTTP_OK);
 Sdk.logout();
 
 verify(mockPlatform().preferenceStore()).clearAccessToken();
 verify(mockPlatform().preferenceStore()).clearRefreshToken();
 }
  12. NO DETAILED SPECS? • when you have a detailed spec,

    tests like these are easy • when you don’t have it → the tests ARE the spec!
  13. CONTINUOUS INTEGRATION • each push to the git repo triggers

    a build on the CI service • CI service checks out the code, runs static analysis and tests • if the build fails, you get notified • if you break the build you fix it!
  14. CIRCLE CI • hosted CI service • nice android support

    • configurable via .yml file • support for saving and displaying build artifacts
  15. CIRCLE CI - DOWNSIDES • integrates only with github •

    no support for x86 emulators • your code is ‘in the cloud’
  16. BROKEN BUILDS • clients want their features done yesterday •

    project managers / product owners don’t care about broken builds • ‘we’ll fix the build after the release’
  17. AUTOMATIC DEPLOY FOR CLIENTS • for each push to the

    labs branch the release build is built • the CI build number is added to versionName: ‘1.0.0-b45’ • the .apk is uploaded to Infinum Labs • the last commit message is used as changelog
  18. Thank you! Questions please :) [email protected] @DINO_BLACKSMITH Visit infinum.co or

    find us on social networks: infinum.co infinumco infinumco infinum