Testing
Android
Enrique López Mañas
Unit Testing
 What   is unit testing?
Unit Testing with JUnit
   JUnit 4.x is a test framework which uses
    annotations to identify methods that are test
    methods. JUnit assumes that all test methods can
    be executed in an arbitrary order. Therefore tests
    should not depend on other tests.



http://en.wikipedia.org/wiki/JUnit
Using JUnit
Using JUnit
Running
Results
Annotations
Annotation           Description
@Test                Test method
@Before              Execute before each test
@After               Execute after each test
@BeforeClass         Execute once before all
                     tests
@AfterClass          Execute once after all tests
@Ignore              Ignore test
@Test (expected =    Fails if not exception
Exception.class)
@Test(timeout=100)   Fails if timeout
Assertions
Assertion                  Description
fail(string)               Fails with message
assertTrue([message],      Asserts if true
boolean condition)
assertsEquals([String      Asserts if equal
message], expected,
actual)
assertNull([message],      Asserts if object is null
object)
assertNotNull([message],   Asserts if object is not null
object)
Android Testing
 ActivityTesting
 Content Provider Testing
 Service Testing
Next…
 Testing
        tools
 Maven Continuous Integration
Links
 http://www.junit.org/


 http://www.neo-tech.es


 http://developer.android.com/tools/testin
 g/testing_android.html

Presentation android JUnit