12
Testing Android Enrique López Mañas

Presentation android JUnit

Embed Size (px)

DESCRIPTION

Presentation on Android and JUnit

Citation preview

Page 1: Presentation android JUnit

Testing AndroidEnrique López Mañas

Page 2: Presentation android JUnit

Unit Testing What is unit testing?

Page 3: Presentation android JUnit

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

Page 4: Presentation android JUnit

Using JUnit

Page 5: Presentation android JUnit

Using JUnit

Page 6: Presentation android JUnit

Running

Page 7: Presentation android JUnit

Results

Page 8: Presentation android JUnit

AnnotationsAnnotation 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 = Exception.class)

Fails if not exception

@Test(timeout=100) Fails if timeout

Page 9: Presentation android JUnit

AssertionsAssertion Description

fail(string) Fails with message

assertTrue([message], boolean condition)

Asserts if true

assertsEquals([String message], expected, actual)

Asserts if equal

assertNull([message], object)

Asserts if object is null

assertNotNull([message], object)

Asserts if object is not null

Page 10: Presentation android JUnit

Android Testing Activity Testing Content Provider Testing Service Testing

Page 11: Presentation android JUnit

Next… Testing tools Maven Continuous Integration

Page 12: Presentation android JUnit

Links http://www.junit.org/

http://www.neo-tech.es

http://developer.android.com/tools/testing/testing_android.html