Currently, Fandy is the mobile apps tech lead works for OLX Indonesia and has been working on both Android and iOS since Cupcake and iOS 2.x respectively. As a tech lead he is responsible for delivering software into production safely and quickly in a sustainable way.
***
This slide was shared at Tech in Asia Product Development Conference 2017 (PDC'17) on 9-10 August 2017.
Get more insightful updates from TIA by subscribing techin.asia/updateselalu
2. 2
What To Do Before Writing Unit Test?
- Refactor your code,● You have legacy code?, Refactor it
● For a new project, use clean architecture approaches
● Convince yourself and your team, be consistent!
● Convince your BOSS!!, or should I?
3. 3
● Do Test Review instead of Code Review
● Understanding their intent
● Communication
Change Your Team Behaviour
5. 5
@Test
public void testCategoryTableCreatedSuccessfully() {
mDatabaseHelper =
new CategorySQLiteDatabaseHelper(
RuntimeEnvironment.application, DB_NAME, DB_VERSION);
SQLiteDatabase db = mDatabaseHelper.getReadableDatabase();
Cursor cursor = db.rawQuery(
"SELECT * FROM sqlite_master " +
"WHERE type='table' " +
"AND name = '" + Category.TABLE_NAME +"'", null);
assertEquals(1, cursor.getCount());
}
6. 6
Unit testing is a software development process in which the
smallest testable parts of an application, called units, are
individually and independently scrutinized for proper
operation. Unit testing can be done manually but is often
automated.
http://searchsoftwarequality.techtarget.com/definition/unit-testing
What is Unit Test?
7. 7
● Trustworthy
● Maintainable
● Readable
Best Practice - Writing Good Unit Test
http://osherove.com/blog/2012/9/17/readable-maintainable-trustworthy-unit
-tests-in-java.html
8. 8
@Test
public void testTransformApiResponseToModel() {
DataResponse response = mockResponse();
DataMapper mapper = new DataMapper();
for (CategoryResponse category : response.results) {
CategoryModel model = mapper.transform(category);
Assert.assertEquals(category.id, model.id);
}
}
9. 9
@Test
public void testProductIsExpired() {
long tomorrowInMillis = System.currentTimeMillis() + 86410000;
boolean isExpired = Product.checkExpiration(tomorrowInMillis);
Assert.assertEquals(true, isExpired);
}