Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Intro to Android Testing

Chuck Greb
December 01, 2018

Intro to Android Testing

Originally presented at DevFest Conakry 2018 in Guinea, West Africa.

https://www.meetup.com/Meetup-GDG-Conakry/events/253639851/

In this talk we'll cover why it's important to test your app, and the different types of testing frameworks available for Android including local unit tests, instrumentation tests, and Espresso.

Chuck Greb

December 01, 2018
Tweet

More Decks by Chuck Greb

Other Decks in Technology

Transcript

  1. Intro to Android Testing
    Charles “Chuck” Greb
    @ecgreb
    DevFest Conakry
    December 1st, 2018

    View full-size slide

  2. • Software Engineer
    • Mobile applications since 2009
    • Mostly Android
    • Button
    About me

    View full-size slide

  3. • Verify code is correct
    • Prevent regressions
    • Documentation
    Why test?

    View full-size slide

  4. Testing Strategies

    View full-size slide

  5. • Don’t test
    • Manual
    • Automation
    Testing Strategies

    View full-size slide

  6. Types of Automated Tests

    View full-size slide

  7. • Unit
    • Integration
    • User Interface (UI)
    Types of Automated Tests

    View full-size slide

  8. Testing Pyramid
    https://martinfowler.com/bliki/TestPyramid.html

    View full-size slide

  9. Android Testing Pyramid

    View full-size slide

  10. class MainActivity : AppCompatActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(savedInstanceState)
    setContentView(R.layout.activity_main)
    setSupportActionBar(toolbar)
    val counter = Counter()
    counter_view.text = counter.reset().toString()
    count_button.setOnClickListener {
    counter_view.text = counter.count().toString()
    }+
    reset_button.setOnClickListener {
    counter_view.text = counter.reset().toString()
    }+
    }+
    }+

    View full-size slide

  11. class MainActivity : AppCompatActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(savedInstanceState)
    setContentView(R.layout.activity_main)
    setSupportActionBar(toolbar)
    val counter = Counter()
    counter_view.text = counter.reset().toString()
    count_button.setOnClickListener {
    counter_view.text = counter.count().toString()
    }+
    reset_button.setOnClickListener {
    counter_view.text = counter.reset().toString()
    }+
    }+
    }+

    View full-size slide

  12. class MainActivity : AppCompatActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(savedInstanceState)
    setContentView(R.layout.activity_main)
    setSupportActionBar(toolbar)
    val counter = Counter()
    counter_view.text = counter.reset().toString()
    count_button.setOnClickListener {
    counter_view.text = counter.count().toString()
    }
    reset_button.setOnClickListener {
    counter_view.text = counter.reset().toString()
    }+
    }+
    }+

    View full-size slide

  13. class MainActivity : AppCompatActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(savedInstanceState)
    setContentView(R.layout.activity_main)
    setSupportActionBar(toolbar)
    val counter = Counter()
    counter_view.text = counter.reset().toString()
    count_button.setOnClickListener {
    counter_view.text = counter.count().toString()
    }
    reset_button.setOnClickListener {
    counter_view.text = counter.reset().toString()
    }
    }
    }

    View full-size slide

  14. class MainActivity : AppCompatActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(savedInstanceState)
    setContentView(R.layout.activity_main)
    setSupportActionBar(toolbar)
    val counter = Counter()
    counter_view.text = counter.reset().toString()
    count_button.setOnClickListener {
    counter_view.text = counter.count().toString()
    }+
    reset_button.setOnClickListener {
    counter_view.text = counter.reset().toString()
    }+
    }+
    }+

    View full-size slide

  15. class MainActivity : AppCompatActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(savedInstanceState)
    setContentView(R.layout.activity_main)
    setSupportActionBar(toolbar)
    val counter = Counter()
    counter_view.text = counter.reset().toString()
    count_button.setOnClickListener {
    counter_view.text = counter.count().toString()
    }+
    reset_button.setOnClickListener {
    counter_view.text = counter.reset().toString()
    }+
    }+
    }+

    View full-size slide

  16. class MainActivity : AppCompatActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(savedInstanceState)
    setContentView(R.layout.activity_main)
    setSupportActionBar(toolbar)
    val counter = Counter()
    counter_view.text = counter.reset().toString()
    count_button.setOnClickListener {
    counter_view.text = counter.count().toString()
    }+
    reset_button.setOnClickListener {
    counter_view.text = counter.reset().toString()
    }+
    }+
    }+

    View full-size slide

  17. class MainActivity : AppCompatActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(savedInstanceState)
    setContentView(R.layout.activity_main)
    setSupportActionBar(toolbar)
    val counter = Counter()
    counter_view.text = counter.reset().toString()
    count_button.setOnClickListener {
    counter_view.text = counter.count().toString()
    }+
    reset_button.setOnClickListener {
    counter_view.text = counter.reset().toString()
    }+
    }+
    }+

    View full-size slide

  18. class MainActivity : AppCompatActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(savedInstanceState)
    setContentView(R.layout.activity_main)
    setSupportActionBar(toolbar)
    val counter = Counter()
    counter_view.text = counter.reset().toString()
    count_button.setOnClickListener {
    counter_view.text = counter.count().toString()
    }+
    reset_button.setOnClickListener {
    counter_view.text = counter.reset().toString()
    }+
    }+
    }+

    View full-size slide

  19. class MainActivity : AppCompatActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(savedInstanceState)
    setContentView(R.layout.activity_main)
    setSupportActionBar(toolbar)
    val counter = Counter()
    counter_view.text = counter.reset().toString()
    count_button.setOnClickListener {
    counter_view.text = counter.count().toString()
    }+
    reset_button.setOnClickListener {
    counter_view.text = counter.reset().toString()
    }_
    }+
    }+

    View full-size slide

  20. class MainActivity : AppCompatActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(savedInstanceState)
    setContentView(R.layout.activity_main)
    setSupportActionBar(toolbar)
    val counter = Counter()
    counter_view.text = counter.reset().toString()
    count_button.setOnClickListener {
    counter_view.text = counter.count().toString()
    }+
    reset_button.setOnClickListener {
    counter_view.text = counter.reset().toString()
    }_
    }+
    }+

    View full-size slide

  21. class MainActivity : AppCompatActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(savedInstanceState)
    setContentView(R.layout.activity_main)
    setSupportActionBar(toolbar)
    val counter = Counter()
    counter_view.text = counter.reset().toString()
    count_button.setOnClickListener {
    counter_view.text = counter.count().toString()
    }+
    reset_button.setOnClickListener {
    counter_view.text = counter.reset().toString()
    }_
    }+
    }+

    View full-size slide

  22. class MainActivity : AppCompatActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(savedInstanceState)
    setContentView(R.layout.activity_main)
    setSupportActionBar(toolbar)
    val counter = Counter()
    counter_view.text = counter.reset().toString()
    count_button.setOnClickListener {
    counter_view.text = counter.count().toString()
    }+
    reset_button.setOnClickListener {
    counter_view.text = counter.reset().toString()
    }_
    }+
    }+

    View full-size slide

  23. class MainActivity : AppCompatActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(savedInstanceState)
    setContentView(R.layout.activity_main)
    setSupportActionBar(toolbar)
    val counter = Counter()
    counter_view.text = counter.reset().toString()
    count_button.setOnClickListener {
    counter_view.text = counter.count().toString()
    }+
    reset_button.setOnClickListener {
    counter_view.text = counter.reset().toString()
    }_
    }+
    }+

    View full-size slide

  24. class MainActivity : AppCompatActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(savedInstanceState)
    setContentView(R.layout.activity_main)
    setSupportActionBar(toolbar)
    val counter = Counter()
    counter_view.text = counter.reset().toString()
    count_button.setOnClickListener {
    counter_view.text = counter.count().toString()
    }+
    reset_button.setOnClickListener {
    counter_view.text = counter.reset().toString()
    }_
    }+
    }+

    View full-size slide

  25. class MainActivity : AppCompatActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(savedInstanceState)
    setContentView(R.layout.activity_main)
    setSupportActionBar(toolbar)
    val counter = Counter()
    counter_view.text = counter.reset().toString()
    count_button.setOnClickListener {
    counter_view.text = counter.count().toString()
    }+
    reset_button.setOnClickListener {
    counter_view.text = counter.reset().toString()
    }_
    }+
    }+

    View full-size slide

  26. class MainActivity : AppCompatActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(savedInstanceState)
    setContentView(R.layout.activity_main)
    setSupportActionBar(toolbar)
    val counter = Counter()
    counter_view.text = counter.reset().toString()
    count_button.setOnClickListener {
    counter_view.text = counter.count().toString()
    }+
    reset_button.setOnClickListener {
    counter_view.text = counter.reset().toString()
    }_
    }+
    }+

    View full-size slide

  27. class MainActivity : AppCompatActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(savedInstanceState)
    setContentView(R.layout.activity_main)
    setSupportActionBar(toolbar)
    val counter = Counter()
    counter_view.text = counter.reset().toString()
    count_button.setOnClickListener {
    counter_view.text = counter.count().toString()
    }+
    reset_button.setOnClickListener {
    counter_view.text = counter.reset().toString()
    }_
    }+
    }+

    View full-size slide

  28. class MainActivity : AppCompatActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(savedInstanceState)
    setContentView(R.layout.activity_main)
    setSupportActionBar(toolbar)
    val counter = Counter()
    counter_view.text = counter.reset().toString()
    count_button.setOnClickListener {
    counter_view.text = counter.count().toString()
    }+
    reset_button.setOnClickListener {
    counter_view.text = counter.reset().toString()
    }_
    }+
    }+

    View full-size slide

  29. class MainActivity : AppCompatActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(savedInstanceState)
    setContentView(R.layout.activity_main)
    setSupportActionBar(toolbar)
    val counter = Counter()
    counter_view.text = counter.reset().toString()
    count_button.setOnClickListener {
    counter_view.text = counter.count().toString()
    }+
    reset_button.setOnClickListener {
    counter_view.text = counter.reset().toString()
    }+
    }+
    }+

    View full-size slide

  30. class Counter {
    private var count = 0
    fun count(): Int {
    count++
    return count
    }+
    fun reset(): Int {
    count = 0
    return count
    }+
    }

    View full-size slide

  31. class Counter {
    private var count = 0
    fun count(): Int {
    count++
    return count
    }+
    fun reset(): Int {
    count = 0
    return count
    }+
    }

    View full-size slide

  32. class Counter {
    private var count = 0
    fun count(): Int {
    count++
    return count
    }+
    fun reset(): Int {
    count = 0
    return count
    }+
    }

    View full-size slide

  33. class Counter {
    private var count = 0
    fun count(): Int {
    count++
    return count
    }+
    fun reset(): Int {
    count = 0
    return count
    }+
    }

    View full-size slide

  34. class Counter {
    private var count = 0
    fun count(): Int {
    count++
    return count
    }+
    fun reset(): Int {
    count = 0
    return count
    }+
    }

    View full-size slide

  35. class Counter {
    private var count = 0
    fun count(): Int {
    count++
    return count
    }+
    fun reset(): Int {
    count = 0
    return count
    }+
    }

    View full-size slide

  36. class Counter {
    private var count = 0
    fun count(): Int {
    count++
    return count
    }_
    fun reset(): Int {
    count = 0
    return count
    }+
    }

    View full-size slide

  37. class Counter {
    private var count = 0
    fun count(): Int {
    count++
    return count
    }_
    fun reset(): Int {
    count = 0
    return count
    }+
    }

    View full-size slide

  38. class Counter {
    private var count = 0
    fun count(): Int {
    count++
    return count
    }_
    fun reset(): Int {
    count = 0
    return count
    }+
    }

    View full-size slide

  39. class Counter {
    private var count = 0
    fun count(): Int {
    count++
    return count
    }+
    fun reset(): Int {
    count = 0
    return count
    }+
    }

    View full-size slide

  40. MainActivity

    View full-size slide

  41. MainActivity Counter

    View full-size slide

  42. MainActivity Counter

    View full-size slide

  43. MainActivity Counter

    View full-size slide

  44. MainActivity Counter
    CounterTest
    JUnit

    View full-size slide

  45. MainActivity Counter
    MainActivityTest CounterTest
    JUnit
    Instrumentation

    View full-size slide

  46. MainActivity Counter
    MainActivityTest CounterTest
    MainActivityUiTest
    JUnit
    Instrumentation
    Espresso

    View full-size slide

  47. Unit Tests
    JUnit

    View full-size slide

  48. class CounterTest {
    @Test
    fun shouldNotBeNull() {
    val counter = Counter()
    assertNotNull(counter)
    }+
    @Test
    fun reset_shouldReturnZero() {
    val counter = Counter()
    assertEquals(0, counter.reset())
    }a
    @Test
    fun count_shouldIncrementNumber() {
    val counter = Counter()
    assertEquals(1, counter.count())
    assertEquals(2, counter.count())
    assertEquals(3, counter.count())

    View full-size slide

  49. class CounterTest {
    @Test
    fun shouldNotBeNull() {
    val counter = Counter()
    assertNotNull(counter)
    }+
    @Test
    fun reset_shouldReturnZero() {
    val counter = Counter()
    assertEquals(0, counter.reset())
    }a
    @Test
    fun count_shouldIncrementNumber() {
    val counter = Counter()
    assertEquals(1, counter.count())
    assertEquals(2, counter.count())
    assertEquals(3, counter.count())

    View full-size slide

  50. class CounterTest {
    @Test+
    fun shouldNotBeNull() {
    val counter = Counter()+
    assertNotNull(counter)
    }+
    @Test
    fun reset_shouldReturnZero() {
    val counter = Counter()
    assertEquals(0, counter.reset())
    }a
    @Test
    fun count_shouldIncrementNumber() {
    val counter = Counter()
    assertEquals(1, counter.count())
    assertEquals(2, counter.count())
    assertEquals(3, counter.count())

    View full-size slide

  51. class CounterTest {
    @Test+
    fun shouldNotBeNull() {
    val counter = Counter()+
    assertNotNull(counter)
    }+
    @Test
    fun reset_shouldReturnZero() {
    val counter = Counter()
    assertEquals(0, counter.reset())
    }a
    @Test
    fun count_shouldIncrementNumber() {
    val counter = Counter()
    assertEquals(1, counter.count())
    assertEquals(2, counter.count())
    assertEquals(3, counter.count())

    View full-size slide

  52. class CounterTest {
    @Test+
    fun shouldNotBeNull() {
    val counter = Counter()+
    assertNotNull(counter)
    }+
    @Test
    fun reset_shouldReturnZero() {
    val counter = Counter()
    assertEquals(0, counter.reset())
    }a
    @Test
    fun count_shouldIncrementNumber() {
    val counter = Counter()
    assertEquals(1, counter.count())
    assertEquals(2, counter.count())
    assertEquals(3, counter.count())

    View full-size slide

  53. class CounterTest {
    @Test+
    fun shouldNotBeNull() {
    val counter = Counter()+
    assertNotNull(counter)
    }+
    @Test
    fun reset_shouldReturnZero() {
    val counter = Counter()
    assertEquals(0, counter.reset())
    }a
    @Test
    fun count_shouldIncrementNumber() {
    val counter = Counter()
    assertEquals(1, counter.count())
    assertEquals(2, counter.count())
    assertEquals(3, counter.count())

    View full-size slide

  54. class CounterTest {
    @Test+
    fun shouldNotBeNull() {
    val counter = Counter()+
    assertNotNull(counter)
    }+
    @Test
    fun reset_shouldReturnZero() {
    val counter = Counter()
    assertEquals(0, counter.reset())
    }a
    @Test
    fun count_shouldIncrementNumber() {
    val counter = Counter()
    assertEquals(1, counter.count())
    assertEquals(2, counter.count())
    assertEquals(3, counter.count())

    View full-size slide

  55. class CounterTest {
    @Test+
    fun shouldNotBeNull() {
    val counter = Counter()+
    assertNotNull(counter)
    }+
    @Test
    fun reset_shouldReturnZero() {
    val counter = Counter()
    assertEquals(0, counter.reset())
    }a
    @Test
    fun count_shouldIncrementNumber() {
    val counter = Counter()
    assertEquals(1, counter.count())
    assertEquals(2, counter.count())
    assertEquals(3, counter.count())

    View full-size slide

  56. class CounterTest {
    @Test+
    fun shouldNotBeNull() {
    val counter = Counter()+
    assertNotNull(counter)
    }+
    @Test
    fun reset_shouldReturnZero() {
    val counter = Counter()
    assertEquals(0, counter.reset())
    }a
    @Test
    fun count_shouldIncrementNumber() {
    val counter = Counter()
    assertEquals(1, counter.count())
    assertEquals(2, counter.count())
    assertEquals(3, counter.count())

    View full-size slide

  57. assertEquals(0, counter.reset())
    }a
    @Test
    fun count_shouldIncrementNumber() {
    val counter = Counter()
    assertEquals(1, counter.count())
    assertEquals(2, counter.count())
    assertEquals(3, counter.count())
    }b
    @Test
    fun reset_shouldResetCounter() {
    val counter = Counter()
    counter.count()
    counter.count()
    counter.count()
    counter.reset()
    assertEquals(1, counter.count())
    }c
    }d

    View full-size slide

  58. assertEquals(0, counter.reset())
    }a
    @Testc
    fun count_shouldIncrementNumber() {
    val counter = Counter()c
    assertEquals(1, counter.count())c
    assertEquals(2, counter.count())
    assertEquals(3, counter.count())
    }b
    @Test
    fun reset_shouldResetCounter() {
    val counter = Counter()
    counter.count()
    counter.count()
    counter.count()
    counter.reset()
    assertEquals(1, counter.count())
    }c
    }d

    View full-size slide

  59. assertEquals(0, counter.reset())
    }a
    @Testc
    fun count_shouldIncrementNumber() {
    val counter = Counter()c
    assertEquals(1, counter.count())c
    assertEquals(2, counter.count())
    assertEquals(3, counter.count())
    }b
    @Test
    fun reset_shouldResetCounter() {
    val counter = Counter()
    counter.count()
    counter.count()
    counter.count()
    counter.reset()
    assertEquals(1, counter.count())
    }c
    }d

    View full-size slide

  60. assertEquals(0, counter.reset())
    }a
    @Testc
    fun count_shouldIncrementNumber() {
    val counter = Counter()c
    assertEquals(1, counter.count())c
    assertEquals(2, counter.count())
    assertEquals(3, counter.count())
    }b
    @Test
    fun reset_shouldResetCounter() {
    val counter = Counter()
    counter.count()
    counter.count()
    counter.count()
    counter.reset()
    assertEquals(1, counter.count())
    }c
    }d

    View full-size slide

  61. assertEquals(0, counter.reset())
    }a
    @Testc
    fun count_shouldIncrementNumber() {
    val counter = Counter()c
    assertEquals(1, counter.count())c
    assertEquals(2, counter.count())
    assertEquals(3, counter.count())
    }b
    @Test
    fun reset_shouldResetCounter() {
    val counter = Counter()
    counter.count()
    counter.count()
    counter.count()
    counter.reset()
    assertEquals(1, counter.count())
    }c
    }d

    View full-size slide

  62. assertEquals(0, counter.reset())
    }a
    @Testc
    fun count_shouldIncrementNumber() {
    val counter = Counter()c
    assertEquals(1, counter.count())c
    assertEquals(2, counter.count())
    assertEquals(3, counter.count())
    }b
    @Test
    fun reset_shouldResetCounter() {
    val counter = Counter()
    counter.count()
    counter.count()
    counter.count()
    counter.reset()
    assertEquals(1, counter.count())
    }c
    }d

    View full-size slide

  63. assertEquals(0, counter.reset())
    }a
    @Testc
    fun count_shouldIncrementNumber() {
    val counter = Counter()c
    assertEquals(1, counter.count())c
    assertEquals(2, counter.count())
    assertEquals(3, counter.count())
    }b
    @Test
    fun reset_shouldResetCounter() {
    val counter = Counter()
    counter.count()
    counter.count()
    counter.count()
    counter.reset()
    assertEquals(1, counter.count())
    }c
    }d

    View full-size slide

  64. assertEquals(0, counter.reset())
    }a
    @Testc
    fun count_shouldIncrementNumber() {
    val counter = Counter()c
    assertEquals(1, counter.count())c
    assertEquals(2, counter.count())
    assertEquals(3, counter.count())
    }b
    @Test
    fun reset_shouldResetCounter() {
    val counter = Counter()
    counter.count()
    counter.count()
    counter.count()
    counter.reset()
    assertEquals(1, counter.count())
    }c
    }d

    View full-size slide

  65. assertEquals(0, counter.reset())
    }a
    @Testc
    fun count_shouldIncrementNumber() {
    val counter = Counter()c
    assertEquals(1, counter.count())c
    assertEquals(2, counter.count())
    assertEquals(3, counter.count())
    }b
    @Test
    fun reset_shouldResetCounter() {
    val counter = Counter()
    counter.count()
    counter.count()
    counter.count()
    counter.reset()
    assertEquals(1, counter.count())
    }c
    }d

    View full-size slide

  66. assertEquals(0, counter.reset())
    }a
    @Testc
    fun count_shouldIncrementNumber() {
    val counter = Counter()c
    assertEquals(1, counter.count())c
    assertEquals(2, counter.count())
    assertEquals(3, counter.count())
    }b
    @Test
    fun reset_shouldResetCounter() {
    val counter = Counter()
    counter.count()
    counter.count()
    counter.count()
    counter.reset()
    assertEquals(1, counter.count())
    }c
    }d

    View full-size slide

  67. assertEquals(0, counter.reset())
    }a
    @Testc
    fun count_shouldIncrementNumber() {
    val counter = Counter()c
    assertEquals(1, counter.count())c
    assertEquals(2, counter.count())
    assertEquals(3, counter.count())
    }b
    @Test
    fun reset_shouldResetCounter() {
    val counter = Counter()
    counter.count()
    counter.count()
    counter.count()
    counter.reset()
    assertEquals(1, counter.count())
    }c
    }d

    View full-size slide

  68. Integration Tests
    Instrumentation

    View full-size slide

  69. @RunWith(AndroidJUnit4::class)
    class MainActivityTest {
    @get:Rule
    val activityTestRule: ActivityTestRule =
    ActivityTestRule(MainActivity::class.java, false, false)
    @Before
    fun setUp() {
    activityTestRule.launchActivity(Intent())
    }a
    @Test
    fun shouldNotBeNull() {
    assertNotNull(activityTestRule.activity)
    }b
    @Test
    fun counterView_shouldDisplayZeroOnCreate() {
    assertEquals("0", activityTestRule.activity.counter_view.text)

    View full-size slide

  70. @RunWith(AndroidJUnit4::class)
    class MainActivityTest {
    @get:Rule
    val activityTestRule: ActivityTestRule =
    ActivityTestRule(MainActivity::class.java, false, false)
    @Before
    fun setUp() {
    activityTestRule.launchActivity(Intent())
    }a
    @Test
    fun shouldNotBeNull() {
    assertNotNull(activityTestRule.activity)
    }b
    @Test
    fun counterView_shouldDisplayZeroOnCreate() {
    assertEquals("0", activityTestRule.activity.counter_view.text)

    View full-size slide

  71. @RunWith(AndroidJUnit4::class)
    class MainActivityTest {
    @get:Rule
    val activityTestRule: ActivityTestRule =
    ActivityTestRule(MainActivity::class.java, false, false)
    @Before
    fun setUp() {
    activityTestRule.launchActivity(Intent())
    }a
    @Test
    fun shouldNotBeNull() {
    assertNotNull(activityTestRule.activity)
    }b
    @Test
    fun counterView_shouldDisplayZeroOnCreate() {
    assertEquals("0", activityTestRule.activity.counter_view.text)

    View full-size slide

  72. @RunWith(AndroidJUnit4::class)
    class MainActivityTest {
    @get:Rule
    val activityTestRule: ActivityTestRule =
    ActivityTestRule(MainActivity::class.java, false, false)
    @Before
    fun setUp() {
    activityTestRule.launchActivity(Intent())
    }a
    @Test
    fun shouldNotBeNull() {
    assertNotNull(activityTestRule.activity)
    }b
    @Test
    fun counterView_shouldDisplayZeroOnCreate() {
    assertEquals("0", activityTestRule.activity.counter_view.text)

    View full-size slide

  73. @RunWith(AndroidJUnit4::class)
    class MainActivityTest {
    @get:Rule
    val activityTestRule: ActivityTestRule =
    ActivityTestRule(MainActivity::class.java, false, false)
    @Before
    fun setUp() {
    activityTestRule.launchActivity(Intent())
    }a
    @Test
    fun shouldNotBeNull() {
    assertNotNull(activityTestRule.activity)
    }b
    @Test
    fun counterView_shouldDisplayZeroOnCreate() {
    assertEquals("0", activityTestRule.activity.counter_view.text)

    View full-size slide

  74. @RunWith(AndroidJUnit4::class)
    class MainActivityTest {
    @get:Rule
    val activityTestRule: ActivityTestRule =
    ActivityTestRule(MainActivity::class.java, false, false)
    @Before
    fun setUp() {
    activityTestRule.launchActivity(Intent())
    }a
    @Test
    fun shouldNotBeNull() {
    assertNotNull(activityTestRule.activity)
    }b
    @Test
    fun counterView_shouldDisplayZeroOnCreate() {
    assertEquals("0", activityTestRule.activity.counter_view.text)

    View full-size slide

  75. @Test
    fun shouldNotBeNull() {
    assertNotNull(activityTestRule.activity)
    }b
    @Test
    fun counterView_shouldDisplayZeroOnCreate() {
    assertEquals("0", activityTestRule.activity.counter_view.text)
    }c
    @Test @UiThreadTest
    fun counterView_shouldDisplayNewCountOnCountButtonClick() {
    activityTestRule.activity.count_button.performClick()
    assertEquals("1", activityTestRule.activity.counter_view.text)
    activityTestRule.activity.count_button.performClick()
    assertEquals("2", activityTestRule.activity.counter_view.text)
    activityTestRule.activity.count_button.performClick()
    assertEquals("3", activityTestRule.activity.counter_view.text)
    }

    View full-size slide

  76. @Test+
    fun shouldNotBeNull() {
    assertNotNull(activityTestRule.activity)
    }b
    @Test
    fun counterView_shouldDisplayZeroOnCreate() {
    assertEquals("0", activityTestRule.activity.counter_view.text)
    }c
    @Test @UiThreadTest
    fun counterView_shouldDisplayNewCountOnCountButtonClick() {
    activityTestRule.activity.count_button.performClick()
    assertEquals("1", activityTestRule.activity.counter_view.text)
    activityTestRule.activity.count_button.performClick()
    assertEquals("2", activityTestRule.activity.counter_view.text)
    activityTestRule.activity.count_button.performClick()
    assertEquals("3", activityTestRule.activity.counter_view.text)
    }

    View full-size slide

  77. @Test+
    fun shouldNotBeNull() {
    assertNotNull(activityTestRule.activity)
    }b
    @Test
    fun counterView_shouldDisplayZeroOnCreate() {
    assertEquals("0", activityTestRule.activity.counter_view.text)
    }c
    @Test @UiThreadTest
    fun counterView_shouldDisplayNewCountOnCountButtonClick() {
    activityTestRule.activity.count_button.performClick()
    assertEquals("1", activityTestRule.activity.counter_view.text)
    activityTestRule.activity.count_button.performClick()
    assertEquals("2", activityTestRule.activity.counter_view.text)
    activityTestRule.activity.count_button.performClick()
    assertEquals("3", activityTestRule.activity.counter_view.text)
    }

    View full-size slide

  78. @Test
    fun shouldNotBeNull() {
    assertNotNull(activityTestRule.activity)
    }b
    @Test
    fun counterView_shouldDisplayZeroOnCreate() {
    assertEquals("0", activityTestRule.activity.counter_view.text)
    }c
    @Test @UiThreadTest+
    fun counterView_shouldDisplayNewCountOnCountButtonClick() {
    activityTestRule.activity.count_button.performClick()+
    assertEquals("1", activityTestRule.activity.counter_view.text)
    activityTestRule.activity.count_button.performClick()+
    assertEquals("2", activityTestRule.activity.counter_view.text)
    activityTestRule.activity.count_button.performClick()+
    assertEquals("3", activityTestRule.activity.counter_view.text)
    }+

    View full-size slide

  79. @Test
    fun shouldNotBeNull() {
    assertNotNull(activityTestRule.activity)
    }b
    @Test
    fun counterView_shouldDisplayZeroOnCreate() {
    assertEquals("0", activityTestRule.activity.counter_view.text)
    }c
    @Test @UiThreadTest+
    fun counterView_shouldDisplayNewCountOnCountButtonClick() {
    activityTestRule.activity.count_button.performClick()+
    assertEquals("1", activityTestRule.activity.counter_view.text)
    activityTestRule.activity.count_button.performClick()+
    assertEquals("2", activityTestRule.activity.counter_view.text)
    activityTestRule.activity.count_button.performClick()+
    assertEquals("3", activityTestRule.activity.counter_view.text)
    }+

    View full-size slide

  80. @Test
    fun shouldNotBeNull() {
    assertNotNull(activityTestRule.activity)
    }b
    @Test
    fun counterView_shouldDisplayZeroOnCreate() {
    assertEquals("0", activityTestRule.activity.counter_view.text)
    }c
    @Test @UiThreadTest+
    fun counterView_shouldDisplayNewCountOnCountButtonClick() {
    activityTestRule.activity.count_button.performClick()+
    assertEquals("1", activityTestRule.activity.counter_view.text)
    activityTestRule.activity.count_button.performClick()+
    assertEquals("2", activityTestRule.activity.counter_view.text)
    activityTestRule.activity.count_button.performClick()+
    assertEquals("3", activityTestRule.activity.counter_view.text)
    }+

    View full-size slide

  81. @Test
    fun shouldNotBeNull() {
    assertNotNull(activityTestRule.activity)
    }b
    @Test
    fun counterView_shouldDisplayZeroOnCreate() {
    assertEquals("0", activityTestRule.activity.counter_view.text)
    }c
    @Test @UiThreadTest+
    fun counterView_shouldDisplayNewCountOnCountButtonClick() {
    activityTestRule.activity.count_button.performClick()+
    assertEquals("1", activityTestRule.activity.counter_view.text)
    activityTestRule.activity.count_button.performClick()+
    assertEquals("2", activityTestRule.activity.counter_view.text)
    activityTestRule.activity.count_button.performClick()+
    assertEquals("3", activityTestRule.activity.counter_view.text)
    }+

    View full-size slide

  82. @Test
    fun shouldNotBeNull() {
    assertNotNull(activityTestRule.activity)
    }b
    @Test
    fun counterView_shouldDisplayZeroOnCreate() {
    assertEquals("0", activityTestRule.activity.counter_view.text)
    }c
    @Test @UiThreadTest+
    fun counterView_shouldDisplayNewCountOnCountButtonClick() {
    activityTestRule.activity.count_button.performClick()+
    assertEquals("1", activityTestRule.activity.counter_view.text)
    activityTestRule.activity.count_button.performClick()+
    assertEquals("2", activityTestRule.activity.counter_view.text)
    activityTestRule.activity.count_button.performClick()+
    assertEquals("3", activityTestRule.activity.counter_view.text)
    }+

    View full-size slide

  83. @Test
    fun shouldNotBeNull() {
    assertNotNull(activityTestRule.activity)
    }b
    @Test
    fun counterView_shouldDisplayZeroOnCreate() {
    assertEquals("0", activityTestRule.activity.counter_view.text)
    }c
    @Test @UiThreadTest+
    fun counterView_shouldDisplayNewCountOnCountButtonClick() {
    activityTestRule.activity.count_button.performClick()+
    assertEquals("1", activityTestRule.activity.counter_view.text)
    activityTestRule.activity.count_button.performClick()+
    assertEquals("2", activityTestRule.activity.counter_view.text)
    activityTestRule.activity.count_button.performClick()+
    assertEquals("3", activityTestRule.activity.counter_view.text)
    }+

    View full-size slide

  84. @Test
    fun shouldNotBeNull() {
    assertNotNull(activityTestRule.activity)
    }b
    @Test
    fun counterView_shouldDisplayZeroOnCreate() {
    assertEquals("0", activityTestRule.activity.counter_view.text)
    }c
    @Test @UiThreadTest+
    fun counterView_shouldDisplayNewCountOnCountButtonClick() {
    activityTestRule.activity.count_button.performClick()+
    assertEquals("1", activityTestRule.activity.counter_view.text)
    activityTestRule.activity.count_button.performClick()+
    assertEquals("2", activityTestRule.activity.counter_view.text)
    activityTestRule.activity.count_button.performClick()+
    assertEquals("3", activityTestRule.activity.counter_view.text)
    }+

    View full-size slide

  85. @Test @UiThreadTest+
    fun counterView_shouldDisplayNewCountOnCountButtonClick() {
    activityTestRule.activity.count_button.performClick()+
    assertEquals("1", activityTestRule.activity.counter_view.text)
    activityTestRule.activity.count_button.performClick()+
    assertEquals("2", activityTestRule.activity.counter_view.text)
    activityTestRule.activity.count_button.performClick()+
    assertEquals("3", activityTestRule.activity.counter_view.text)
    }+
    @Test @UiThreadTest
    fun counterView_shouldDisplayZeroOnResetButtonClick() {
    activityTestRule.activity.count_button.performClick()
    activityTestRule.activity.count_button.performClick()
    activityTestRule.activity.count_button.performClick()
    activityTestRule.activity.reset_button.performClick()
    assertEquals("0", activityTestRule.activity.counter_view.text)
    }
    }

    View full-size slide

  86. @Test @UiThreadTest+
    fun counterView_shouldDisplayNewCountOnCountButtonClick() {
    activityTestRule.activity.count_button.performClick()+
    assertEquals("1", activityTestRule.activity.counter_view.text)
    activityTestRule.activity.count_button.performClick()+
    assertEquals("2", activityTestRule.activity.counter_view.text)
    activityTestRule.activity.count_button.performClick()+
    assertEquals("3", activityTestRule.activity.counter_view.text)
    }+
    @Test @UiThreadTest
    fun counterView_shouldDisplayZeroOnResetButtonClick() {
    activityTestRule.activity.count_button.performClick()
    activityTestRule.activity.count_button.performClick()
    activityTestRule.activity.count_button.performClick()
    activityTestRule.activity.reset_button.performClick()
    assertEquals("0", activityTestRule.activity.counter_view.text)
    }+
    }-

    View full-size slide

  87. @Test @UiThreadTest+
    fun counterView_shouldDisplayNewCountOnCountButtonClick() {
    activityTestRule.activity.count_button.performClick()+
    assertEquals("1", activityTestRule.activity.counter_view.text)
    activityTestRule.activity.count_button.performClick()+
    assertEquals("2", activityTestRule.activity.counter_view.text)
    activityTestRule.activity.count_button.performClick()+
    assertEquals("3", activityTestRule.activity.counter_view.text)
    }+
    @Test @UiThreadTest
    fun counterView_shouldDisplayZeroOnResetButtonClick() {
    activityTestRule.activity.count_button.performClick()
    activityTestRule.activity.count_button.performClick()
    activityTestRule.activity.count_button.performClick()
    activityTestRule.activity.reset_button.performClick()
    assertEquals("0", activityTestRule.activity.counter_view.text)
    }+
    }--

    View full-size slide

  88. @Test @UiThreadTest+
    fun counterView_shouldDisplayNewCountOnCountButtonClick() {
    activityTestRule.activity.count_button.performClick()+
    assertEquals("1", activityTestRule.activity.counter_view.text)
    activityTestRule.activity.count_button.performClick()+
    assertEquals("2", activityTestRule.activity.counter_view.text)
    activityTestRule.activity.count_button.performClick()+
    assertEquals("3", activityTestRule.activity.counter_view.text)
    }+
    @Test @UiThreadTest
    fun counterView_shouldDisplayZeroOnResetButtonClick() {
    activityTestRule.activity.count_button.performClick()
    activityTestRule.activity.count_button.performClick()
    activityTestRule.activity.count_button.performClick()
    activityTestRule.activity.reset_button.performClick()
    assertEquals("0", activityTestRule.activity.counter_view.text)
    }+
    }-

    View full-size slide

  89. @Test @UiThreadTest+
    fun counterView_shouldDisplayNewCountOnCountButtonClick() {
    activityTestRule.activity.count_button.performClick()+
    assertEquals("1", activityTestRule.activity.counter_view.text)
    activityTestRule.activity.count_button.performClick()+
    assertEquals("2", activityTestRule.activity.counter_view.text)
    activityTestRule.activity.count_button.performClick()+
    assertEquals("3", activityTestRule.activity.counter_view.text)
    }+
    @Test @UiThreadTest
    fun counterView_shouldDisplayZeroOnResetButtonClick() {
    activityTestRule.activity.count_button.performClick()
    activityTestRule.activity.count_button.performClick()
    activityTestRule.activity.count_button.performClick()
    activityTestRule.activity.reset_button.performClick()
    assertEquals("0", activityTestRule.activity.counter_view.text)
    }+
    }-

    View full-size slide

  90. UI Tests
    Espresso

    View full-size slide

  91. @RunWith(AndroidJUnit4::class)
    class MainActivityUiTest {
    @get:Rule
    val activityTestRule: ActivityTestRule =
    ActivityTestRule(MainActivity::class.java, false, false)
    @Before
    fun setUp() {
    activityTestRule.launchActivity(Intent())
    }a
    @Test
    fun counterView_shouldDisplayZeroOnCreate() {
    onView(withId(R.id.counter_view)).check(matches(withText("0")))
    }a
    @Test
    fun counterView_shouldDisplayNewCountOnCountButtonClick() {
    onView(withId(R.id.count_button)).perform(click())

    View full-size slide

  92. @RunWith(AndroidJUnit4::class)
    class MainActivityUiTest {
    @get:Rule
    val activityTestRule: ActivityTestRule =
    ActivityTestRule(MainActivity::class.java, false, false)
    @Before
    fun setUp() {
    activityTestRule.launchActivity(Intent())
    }a
    @Test
    fun counterView_shouldDisplayZeroOnCreate() {
    onView(withId(R.id.counter_view)).check(matches(withText("0")))
    }a
    @Test
    fun counterView_shouldDisplayNewCountOnCountButtonClick() {
    onView(withId(R.id.count_button)).perform(click())

    View full-size slide

  93. @RunWith(AndroidJUnit4::class)
    class MainActivityUiTest {
    @get:Rule
    val activityTestRule: ActivityTestRule =
    ActivityTestRule(MainActivity::class.java, false, false)
    @Before
    fun setUp() {
    activityTestRule.launchActivity(Intent())
    }a
    @Test+
    fun counterView_shouldDisplayZeroOnCreate() {
    +onView(withId(R.id.counter_view)).check(matches(withText(“0")))
    }b
    @Test
    fun counterView_shouldDisplayNewCountOnCountButtonClick() {
    onView(withId(R.id.count_button)).perform(click())

    View full-size slide

  94. @RunWith(AndroidJUnit4::class)
    class MainActivityUiTest {
    @get:Rule
    val activityTestRule: ActivityTestRule =
    ActivityTestRule(MainActivity::class.java, false, false)
    @Before
    fun setUp() {
    activityTestRule.launchActivity(Intent())
    }a
    @Test
    fun counterView_shouldDisplayZeroOnCreate() {
    onView(withId(R.id.counter_view)).check(matches(withText("0")))
    }b
    @Test
    fun counterView_shouldDisplayNewCountOnCountButtonClick() {
    onView(withId(R.id.count_button)).perform(click())

    View full-size slide

  95. @RunWith(AndroidJUnit4::class)
    class MainActivityUiTest {
    @get:Rule
    val activityTestRule: ActivityTestRule =
    ActivityTestRule(MainActivity::class.java, false, false)
    @Before
    fun setUp() {
    activityTestRule.launchActivity(Intent())
    }a
    @Test
    fun counterView_shouldDisplayZeroOnCreate() {
    onView(withId(R.id.counter_view)).check(matches(withText("0")))
    }b
    @Test
    fun counterView_shouldDisplayNewCountOnCountButtonClick() {
    onView(withId(R.id.count_button)).perform(click())

    View full-size slide

  96. @RunWith(AndroidJUnit4::class)
    class MainActivityUiTest {
    @get:Rule
    val activityTestRule: ActivityTestRule =
    ActivityTestRule(MainActivity::class.java, false, false)
    @Before
    fun setUp() {
    activityTestRule.launchActivity(Intent())
    }a
    @Test
    fun counterView_shouldDisplayZeroOnCreate() {
    onView(withId(R.id.counter_view)).check(matches(withText("0")))
    }b
    @Test
    fun counterView_shouldDisplayNewCountOnCountButtonClick() {
    onView(withId(R.id.count_button)).perform(click())

    View full-size slide

  97. @RunWith(AndroidJUnit4::class)
    class MainActivityUiTest {
    @get:Rule
    val activityTestRule: ActivityTestRule =
    ActivityTestRule(MainActivity::class.java, false, false)
    @Before
    fun setUp() {
    activityTestRule.launchActivity(Intent())
    }a
    @Test
    fun counterView_shouldDisplayZeroOnCreate() {
    onView(withId(R.id.counter_view)).check(matches(withText("0")))
    }b
    @Test
    fun counterView_shouldDisplayNewCountOnCountButtonClick() {
    onView(withId(R.id.count_button)).perform(click())

    View full-size slide

  98. @RunWith(AndroidJUnit4::class)
    class MainActivityUiTest {
    @get:Rule
    val activityTestRule: ActivityTestRule =
    ActivityTestRule(MainActivity::class.java, false, false)
    @Before
    fun setUp() {
    activityTestRule.launchActivity(Intent())
    }a
    @Test
    fun counterView_shouldDisplayZeroOnCreate() {
    onView(withId(R.id.counter_view)).check(matches(withText("0")))
    }b
    @Test
    fun counterView_shouldDisplayNewCountOnCountButtonClick() {
    onView(withId(R.id.count_button)).perform(click())

    View full-size slide

  99. @RunWith(AndroidJUnit4::class)
    class MainActivityUiTest {
    @get:Rule
    val activityTestRule: ActivityTestRule =
    ActivityTestRule(MainActivity::class.java, false, false)
    @Before
    fun setUp() {
    activityTestRule.launchActivity(Intent())
    }a
    @Test
    fun counterView_shouldDisplayZeroOnCreate() {
    onView(withId(R.id.counter_view)).check(matches(withText("0")))
    }b
    @Test
    fun counterView_shouldDisplayNewCountOnCountButtonClick() {
    onView(withId(R.id.count_button)).perform(click())

    View full-size slide

  100. @RunWith(AndroidJUnit4::class)
    class MainActivityUiTest {
    @get:Rule
    val activityTestRule: ActivityTestRule =
    ActivityTestRule(MainActivity::class.java, false, false)
    @Before
    fun setUp() {
    activityTestRule.launchActivity(Intent())
    }a
    @Test
    fun counterView_shouldDisplayZeroOnCreate() {
    onView(withId(R.id.counter_view)).check(matches(withText("0")))
    }b
    @Test
    fun counterView_shouldDisplayNewCountOnCountButtonClick() {
    onView(withId(R.id.count_button)).perform(click())

    View full-size slide

  101. @Test
    fun counterView_shouldDisplayNewCountOnCountButtonClick() {
    onView(withId(R.id.count_button)).perform(click())
    onView(withId(R.id.counter_view)).check(matches(withText("1")))
    onView(withId(R.id.count_button)).perform(click())
    onView(withId(R.id.counter_view)).check(matches(withText("2")))
    onView(withId(R.id.count_button)).perform(click())
    onView(withId(R.id.counter_view)).check(matches(withText("3")))
    }a
    @Test
    fun counterView_shouldDisplayZeroOnResetButtonClick() {
    onView(withId(R.id.count_button)).perform(click())
    onView(withId(R.id.count_button)).perform(click())
    onView(withId(R.id.count_button)).perform(click())
    onView(withId(R.id.reset_button)).perform(click())
    onView(withId(R.id.counter_view)).check(matches(withText("0")))
    }a
    }

    View full-size slide

  102. @Test
    fun counterView_shouldDisplayNewCountOnCountButtonClick() {
    onView(withId(R.id.count_button)).perform(click())
    onView(withId(R.id.counter_view)).check(matches(withText("1")))
    onView(withId(R.id.count_button)).perform(click())
    onView(withId(R.id.counter_view)).check(matches(withText("2")))
    onView(withId(R.id.count_button)).perform(click())
    onView(withId(R.id.counter_view)).check(matches(withText("3")))
    }a
    @Test
    fun counterView_shouldDisplayZeroOnResetButtonClick() {
    onView(withId(R.id.count_button)).perform(click())+
    onView(withId(R.id.count_button)).perform(click())+
    onView(withId(R.id.count_button)).perform(click())+
    onView(withId(R.id.reset_button)).perform(click())
    onView(withId(R.id.counter_view)).check(matches(withText("0")))
    }a
    }

    View full-size slide

  103. @Test
    fun counterView_shouldDisplayNewCountOnCountButtonClick() {
    onView(withId(R.id.count_button)).perform(click())
    onView(withId(R.id.counter_view)).check(matches(withText("1")))
    onView(withId(R.id.count_button)).perform(click())
    onView(withId(R.id.counter_view)).check(matches(withText("2")))
    onView(withId(R.id.count_button)).perform(click())
    onView(withId(R.id.counter_view)).check(matches(withText("3")))
    }a
    @Test
    fun counterView_shouldDisplayZeroOnResetButtonClick() {
    onView(withId(R.id.count_button)).perform(click())+
    onView(withId(R.id.count_button)).perform(click())+
    onView(withId(R.id.count_button)).perform(click())+
    onView(withId(R.id.reset_button)).perform(click())
    onView(withId(R.id.counter_view)).check(matches(withText("0")))
    }a
    }

    View full-size slide

  104. @Test
    fun counterView_shouldDisplayNewCountOnCountButtonClick() {
    onView(withId(R.id.count_button)).perform(click())a
    onView(withId(R.id.counter_view)).check(matches(withText("1")))
    onView(withId(R.id.count_button)).perform(click())b
    onView(withId(R.id.counter_view)).check(matches(withText("2")))
    onView(withId(R.id.count_button)).perform(click())c
    onView(withId(R.id.counter_view)).check(matches(withText("3")))
    }a
    @Test
    fun counterView_shouldDisplayZeroOnResetButtonClick() {
    onView(withId(R.id.count_button)).perform(click())+
    onView(withId(R.id.count_button)).perform(click())+
    onView(withId(R.id.count_button)).perform(click())+
    onView(withId(R.id.reset_button)).perform(click())
    onView(withId(R.id.counter_view)).check(matches(withText("0")))
    }a
    }

    View full-size slide

  105. @Test
    fun counterView_shouldDisplayNewCountOnCountButtonClick() {
    onView(withId(R.id.count_button)).perform(click())a
    onView(withId(R.id.counter_view)).check(matches(withText("1")))
    onView(withId(R.id.count_button)).perform(click())
    onView(withId(R.id.counter_view)).check(matches(withText("2")))
    onView(withId(R.id.count_button)).perform(click())
    onView(withId(R.id.counter_view)).check(matches(withText("3")))
    }a
    @Test
    fun counterView_shouldDisplayZeroOnResetButtonClick() {
    onView(withId(R.id.count_button)).perform(click())+
    onView(withId(R.id.count_button)).perform(click())+
    onView(withId(R.id.count_button)).perform(click())+
    onView(withId(R.id.reset_button)).perform(click())
    onView(withId(R.id.counter_view)).check(matches(withText("0")))
    }a
    }

    View full-size slide

  106. @Test
    fun counterView_shouldDisplayNewCountOnCountButtonClick() {
    onView(withId(R.id.count_button)).perform(click())a
    onView(withId(R.id.counter_view)).check(matches(withText("1")))
    onView(withId(R.id.count_button)).perform(click())
    onView(withId(R.id.counter_view)).check(matches(withText("2")))
    onView(withId(R.id.count_button)).perform(click())
    onView(withId(R.id.counter_view)).check(matches(withText("3")))
    }a
    @Test
    fun counterView_shouldDisplayZeroOnResetButtonClick() {
    onView(withId(R.id.count_button)).perform(click())+
    onView(withId(R.id.count_button)).perform(click())+
    onView(withId(R.id.count_button)).perform(click())+
    onView(withId(R.id.reset_button)).perform(click())
    onView(withId(R.id.counter_view)).check(matches(withText("0")))
    }a
    }

    View full-size slide

  107. @Test
    fun counterView_shouldDisplayNewCountOnCountButtonClick() {
    onView(withId(R.id.count_button)).perform(click())a
    onView(withId(R.id.counter_view)).check(matches(withText("1")))
    onView(withId(R.id.count_button)).perform(click())
    onView(withId(R.id.counter_view)).check(matches(withText("2")))
    onView(withId(R.id.count_button)).perform(click())
    onView(withId(R.id.counter_view)).check(matches(withText("3")))
    }a
    @Test
    fun counterView_shouldDisplayZeroOnResetButtonClick() {
    onView(withId(R.id.count_button)).perform(click())+
    onView(withId(R.id.count_button)).perform(click())+
    onView(withId(R.id.count_button)).perform(click())+
    onView(withId(R.id.reset_button)).perform(click())
    onView(withId(R.id.counter_view)).check(matches(withText("0")))
    }a
    }

    View full-size slide

  108. @Test
    fun counterView_shouldDisplayNewCountOnCountButtonClick() {
    onView(withId(R.id.count_button)).perform(click())a
    onView(withId(R.id.counter_view)).check(matches(withText("1")))
    onView(withId(R.id.count_button)).perform(click())
    onView(withId(R.id.counter_view)).check(matches(withText("2")))
    onView(withId(R.id.count_button)).perform(click())
    onView(withId(R.id.counter_view)).check(matches(withText("3")))
    }a
    @Test
    fun counterView_shouldDisplayZeroOnResetButtonClick() {
    onView(withId(R.id.count_button)).perform(click())+
    onView(withId(R.id.count_button)).perform(click())+
    onView(withId(R.id.count_button)).perform(click())+
    onView(withId(R.id.reset_button)).perform(click())
    onView(withId(R.id.counter_view)).check(matches(withText("0")))
    }a
    }

    View full-size slide

  109. @Test
    fun counterView_shouldDisplayNewCountOnCountButtonClick() {
    onView(withId(R.id.count_button)).perform(click())
    onView(withId(R.id.counter_view)).check(matches(withText("1")))
    onView(withId(R.id.count_button)).perform(click())
    onView(withId(R.id.counter_view)).check(matches(withText("2")))
    onView(withId(R.id.count_button)).perform(click())
    onView(withId(R.id.counter_view)).check(matches(withText("3")))
    }a
    @Test
    fun counterView_shouldDisplayZeroOnResetButtonClick() {
    onView(withId(R.id.count_button)).perform(click())+
    onView(withId(R.id.count_button)).perform(click())+
    onView(withId(R.id.count_button)).perform(click())+
    onView(withId(R.id.reset_button)).perform(click())
    onView(withId(R.id.counter_view)).check(matches(withText("0")))
    }a
    }

    View full-size slide

  110. @Test
    fun counterView_shouldDisplayNewCountOnCountButtonClick() {
    onView(withId(R.id.count_button)).perform(click())
    onView(withId(R.id.counter_view)).check(matches(withText("1")))
    onView(withId(R.id.count_button)).perform(click())
    onView(withId(R.id.counter_view)).check(matches(withText("2")))
    onView(withId(R.id.count_button)).perform(click())
    onView(withId(R.id.counter_view)).check(matches(withText("3")))
    }a
    @Test
    fun counterView_shouldDisplayZeroOnResetButtonClick() {
    onView(withId(R.id.count_button)).perform(click())
    onView(withId(R.id.count_button)).perform(click())
    onView(withId(R.id.count_button)).perform(click())
    onView(withId(R.id.reset_button)).perform(click())
    onView(withId(R.id.counter_view)).check(matches(withText("0")))
    }a
    }

    View full-size slide

  111. @Test
    fun counterView_shouldDisplayNewCountOnCountButtonClick() {
    onView(withId(R.id.count_button)).perform(click())
    onView(withId(R.id.counter_view)).check(matches(withText("1")))
    onView(withId(R.id.count_button)).perform(click())
    onView(withId(R.id.counter_view)).check(matches(withText("2")))
    onView(withId(R.id.count_button)).perform(click())
    onView(withId(R.id.counter_view)).check(matches(withText("3")))
    }a
    @Test
    fun counterView_shouldDisplayZeroOnResetButtonClick() {
    onView(withId(R.id.count_button)).perform(click())
    onView(withId(R.id.count_button)).perform(click())
    onView(withId(R.id.count_button)).perform(click())
    onView(withId(R.id.reset_button)).perform(click())
    onView(withId(R.id.counter_view)).check(matches(withText("0")))
    }a
    }

    View full-size slide

  112. @Test
    fun counterView_shouldDisplayNewCountOnCountButtonClick() {
    onView(withId(R.id.count_button)).perform(click())
    onView(withId(R.id.counter_view)).check(matches(withText("1")))
    onView(withId(R.id.count_button)).perform(click())
    onView(withId(R.id.counter_view)).check(matches(withText("2")))
    onView(withId(R.id.count_button)).perform(click())
    onView(withId(R.id.counter_view)).check(matches(withText("3")))
    }a
    @Test
    fun counterView_shouldDisplayZeroOnResetButtonClick() {
    onView(withId(R.id.count_button)).perform(click())
    onView(withId(R.id.count_button)).perform(click())
    onView(withId(R.id.count_button)).perform(click())
    onView(withId(R.id.reset_button)).perform(click())
    onView(withId(R.id.counter_view)).check(matches(withText("0")))
    }a
    }

    View full-size slide

  113. @Test
    fun counterView_shouldDisplayNewCountOnCountButtonClick() {
    onView(withId(R.id.count_button)).perform(click())
    onView(withId(R.id.counter_view)).check(matches(withText("1")))
    onView(withId(R.id.count_button)).perform(click())
    onView(withId(R.id.counter_view)).check(matches(withText("2")))
    onView(withId(R.id.count_button)).perform(click())
    onView(withId(R.id.counter_view)).check(matches(withText("3")))
    }a
    @Test
    fun counterView_shouldDisplayZeroOnResetButtonClick() {
    onView(withId(R.id.count_button)).perform(click())
    onView(withId(R.id.count_button)).perform(click())
    onView(withId(R.id.count_button)).perform(click())
    onView(withId(R.id.reset_button)).perform(click())
    onView(withId(R.id.counter_view)).check(matches(withText("0")))
    }a
    }p

    View full-size slide

  114. Conclusion
    Testing is fun!

    View full-size slide

  115. • Why test?
    • Types of tests
    • Unit Tests
    • Integration Tests
    • UI Tests
    • Continuous Integration (CI)
    • Test-Driven Development (TDD)
    • Tests == Quality
    Conclusion

    View full-size slide

  116. Tests == Quality

    View full-size slide

  117. Merci
    Charles “Chuck” Greb
    @ecgreb
    DevFest Conakry
    December 1st, 2018

    View full-size slide

  118. usebutton.com

    View full-size slide