Droid con 2013 workshop unit testing in android [robolectirc]

Post on 06-May-2015

275 views 1 download

description

The presentation we did as part of DroidCon 2013 Workshop

Transcript of Droid con 2013 workshop unit testing in android [robolectirc]

Unit Testing Android Applications

Leena SNHead of Engineering@leenasn

Krishnaprasad RSoftware Architect@krikrn

Multunus Software Pvt. Ltd.Agile Software Development@multunus

Demo of AndroidUnitTestCase

AndroidInstrumentationTestCase

● Extension to JUnit● Provides wrappers for instantiating Activities ● Provide methods for interacting with

Activities

The Problem

● Slow tests● Resulting in slow iterations

The Solution

● Mocking ● But its not easy :(

● Google has stripped all the classes with android.jar with RuntimeException(“Stub”)

● Most classes and methods are final● Non public constructors● Lack of interfaces● Many static methods

Mocking is Hard because..

● Faster tests - runs in JVM● Emulates Android SDK and Resources

Why Robolectric?

Lets see it in action!

● Emulates Android SDK, modified to run it on JVM Using○ Shadow Objects○ View and Resource Loading

How it works

● Extending Robolectric is easy too● Awesome Community Support

What is Special

● Never runs on actual device as it emulates the environment

● It can test small units, so can not replace automated integration tests

● The above are for purpose :)

What Robolectric is NOT

Summary