This document discusses Test Driven Development (TDD), Continuous Integration (CI), and Continuous Delivery (CD) for mobile development. It defines TDD, CI, and CD and provides examples of implementing each for both Android and iOS development. For TDD, it demonstrates writing tests first and then code to pass the tests. For CI, it recommends automating the build and test process. And for CD, it suggests using services like TestFlight to automatically deliver new builds to testers.
6. 6 CONFIDENTIAL
TDD: Basics
− First understand the requirement
− Create test that tests this
requirement
− Run test and expect FAIL
− Provide basic implementation
− Run test and expect PASS
− Improve your implementation
− Run test after improvements to
test changes
8. 8 CONFIDENTIAL
TDD: Example (cont.)
− Simple test:
public void testEmailValidationForValidEmail() {
//GIVEN
String validEmail = "sergiy-nezdoliy@globallogic.com";
//WHEN
bool result = SNUtilities.validateEmail(validEmail);
//THEN
assertTrue("Mail is valid: " + validEmail, result);
}
9. 9 CONFIDENTIAL
TDD: Example (cont.)
− Simple implementation:
public static bool validateEmail(String intpuMail) {
return FALSE;
}
//Leads to test FAIL
//Refactor code to pass test
public static bool validateEmail(String intpuMail) {
boolean isValidEmail = false;
Pattern pattern = Pattern.compile("^[_A-Za-z0-9-]+@[A-Za-z0-9-]+((.[A-Za-z]{2,}){1}$)");
isValidEmail = pattern.matcher(inputMail).matches();
return isValidEmail;
}
//Run test and – voila, PASSED
10. 10 CONFIDENTIAL
TDD: Example (cont.)
− Improve?
− Empty string
− Null value
− Extended mask for regexp (including dot support etc)
− Do not forget to test negative cases
11. 11 CONFIDENTIAL
TDD: Example (cont.)
− As a result:
//TESTS
public void testValidateNullEmail() {...}
public void testValidateEmptyValue() {...}
public void testValidateInvalidEmail() {...}
public void testValidateValidEmail() {...}
//IMPLEMENTATION
public static boolean validateEmail(String inputMail) {
boolean isValidEmail = false;
if (inputMail != null && inputMail.length() > 0) {
Pattern pattern = Pattern.compile
("^[_A-Za-z0-9-]+(.[_A-Za-z0-9]+)*@[A-Za-z0-9-]+(.[A-Za-z0-9-]+)*((.[A-Za-z]{2,}){1}$)");
isValidEmail = pattern.matcher(inputMail).matches();
}
return isValidEmail;
}
15. 15 CONFIDENTIAL
TDD: Android – What to test?
− Formatters
− Parsing, serializing, marshaling data from server
− Fields input validation (e.g. e-mail field)
− Any inner calculations
− Entities, models, DAO objects
− Database layer
− UI where possible (functional and integration testing)
− …
16. 16 CONFIDENTIAL
TDD: Android Example
//IMPLEMENTATION
public static boolean validateEmail(String inputMail) {
boolean isValidEmail = false;
if (inputMail != null && inputMail.length() > 0) {
Pattern pattern = Pattern.compile
("^[_A-Za-z0-9-]+(.[_A-Za-z0-9]+)*@[A-Za-z0-9-]+(.[A-Za-z0-9-]+)*((.[A-Za-z]{2,}){1}$)");
isValidEmail = pattern.matcher(inputMail).matches();
}
return isValidEmail;
}
//TESTS
public void testValidateNullEmail() {...}
public void testValidateEmptyValue() {...}
public void testValidateInvalidEmail() {...}
public void testValidateValidEmail() {...}
19. 19 CONFIDENTIAL
TDD: iOS– What to test? (TODO)
− Core Data layer
− Parsing, serializing, marshaling data from server
− Fields input validation (e.g. e-mail field)
− Any inner calculations
− Entities, models, DAO objects
− UI where possible (functional and integration testing)
− …
22. 22 CONFIDENTIAL
Continuous Integration: Why?
− Reduce risks:
− Fixing bugs late costs more
− Lack of project visibility (metrics, changelogs)
− Lack of deployable software
− Reduce repetitive manual processes
− Generate deployable software any time at any place
− Test early and often
− No painful waits for next build
− Visible process of building your project
23. 23 CONFIDENTIAL
Continuous Integration: Schema
Version Control System Build servers
QA, clients, managers
Developers
CI Server
CI Feedback
1. Check In
2. Check Out
3. Indicate
Change
5. Set Status
4. Report
Results
6. Notify
24. 24 CONFIDENTIAL
Continuous Integration:
− Cross-system (Windows, Linux, Mac OS)
− Extensible (plenty of plugins)
− Provides good visibility of builds
− Free
− Chuck Norris supports Jenkins!
27. 27 CONFIDENTIAL
Continuous Integration: How?
− Xcode command line tools (with some hacks)
− Run tests from command line and fail in case if failed tests
− ocunit2junit + gcovr for code coverage
− keychain issues
− Provisioning profiles import
− Jenkins should run only on Mac
28. 28 CONFIDENTIAL
Continuous Integration: iOS
CI: TDD & Code coverage?
− Using gcovr tool
− Configure project to generate .gcda data (Xcode 4.6.x):
− Add to “Other C flags”: -lgcov, -ftest-coverage, -lprofile_rt
− Set “Generate Test Coverage Files” to YES
− Set “Generate Profiling Code” to YES
− run tests -> ocunit2junit to get tests results
− configure Jenkins job to handle test reports and code coverage
(Cobertura)
30. 30 CONFIDENTIAL
Continuous Integration: How?
− Using ant
− Using Android build tools
− Using Jenkins plugin for Android
− Using bash
− Analyzing tests results? Hack for tests needed in build.xml
− Take a look at android-lint plugin:
− scans your Android projects and reports on potential bugs, performance, security and
translation issues, plus more
31. 31 CONFIDENTIAL
Continuous Integration: iOS
Continuous Integration: TDD?
− Add separate target to build.xml
− Analyze results
− Fail build in case if tests fail
33. 33 CONFIDENTIAL
Continuous Delivery: Why?
− Allows to provide new builds to test continuously
− Automation of providing builds to QA and customers
− Painless releases, quick feedbacks
35. 35 CONFIDENTIAL
Continuous Delivery: How?
− Installation over the air
− Downloading build as artifact from Jenkins
− Uploading to share (Android only)
− Installation over Wi Fi (iOS – manual)
− Cloud services: AppBlade, Knappsack, HockeyApp … - not Free
− …
− TestFlightApp – ideal free solution to manage your app
37. 37 CONFIDENTIAL
TestFlightApp: Why?
− Free
− Supports automatic uploading (can be part of Jenkins job)
− May be not embedded into app at all.
− Email notifications
− Easy to install on any allowed device (which is in Ad Hoc profile)
− Cross platform (iOS, Android)
− Provides additional services (crash reports, checkpoints etc)
− You need to include TestFlight SDK into your project for this
38. 38 CONFIDENTIAL
TestFlightApp: example of upload
curl http://testflightapp.com/api/builds.json
-F file=@$IPA
-F api_token=’<YOUR API TOKEN>'
-F team_token=’<YOUR TEAM TOKEN>'
-F notes="Uploaded on ${BUILD_ID} (Build#: '${BUILD_NUMBER}') (Build version#: '1.0').nChanges: $git_notes"
-F notify=True
-F distribution_lists=”QA"