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. 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() }+ }+ }+
  2. 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() }+ }+ }+
  3. 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() }+ }+ }+
  4. 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() } } }
  5. 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() }+ }+ }+
  6. 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() }+ }+ }+
  7. 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() }+ }+ }+
  8. 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() }+ }+ }+
  9. 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() }+ }+ }+
  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() }_ }+ }+
  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() }_ }+ }+
  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() }_ }+ }+
  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() }_ }+ }+
  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() }_ }+ }+
  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() }_ }+ }+
  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() }_ }+ }+
  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() }_ }+ }+
  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() }_ }+ }+
  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() }_ }+ }+
  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() }+ }+ }+
  21. class Counter { private var count = 0 fun count():

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

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

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

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

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

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

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

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

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

    Int { count++ return count }+ fun reset(): Int { count = 0 return count }+ }
  31. 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())
  32. 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())
  33. 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())
  34. 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())
  35. 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())
  36. 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())
  37. 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())
  38. 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())
  39. 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())
  40. 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
  41. 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
  42. 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
  43. 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
  44. 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
  45. 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
  46. 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
  47. 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
  48. 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
  49. 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
  50. 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
  51. @RunWith(AndroidJUnit4::class) class MainActivityTest { @get:Rule val activityTestRule: ActivityTestRule<MainActivity> = 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)
  52. @RunWith(AndroidJUnit4::class) class MainActivityTest { @get:Rule val activityTestRule: ActivityTestRule<MainActivity> = 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)
  53. @RunWith(AndroidJUnit4::class) class MainActivityTest { @get:Rule val activityTestRule: ActivityTestRule<MainActivity> = 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)
  54. @RunWith(AndroidJUnit4::class) class MainActivityTest { @get:Rule val activityTestRule: ActivityTestRule<MainActivity> = 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)
  55. @RunWith(AndroidJUnit4::class) class MainActivityTest { @get:Rule val activityTestRule: ActivityTestRule<MainActivity> = 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)
  56. @RunWith(AndroidJUnit4::class) class MainActivityTest { @get:Rule val activityTestRule: ActivityTestRule<MainActivity> = 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)
  57. @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) }
  58. @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) }
  59. @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) }
  60. @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) }+
  61. @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) }+
  62. @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) }+
  63. @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) }+
  64. @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) }+
  65. @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) }+
  66. @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) }+
  67. @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) } }
  68. @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) }+ }-
  69. @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) }+ }--
  70. @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) }+ }-
  71. @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) }+ }-
  72. @RunWith(AndroidJUnit4::class) class MainActivityUiTest { @get:Rule val activityTestRule: ActivityTestRule<MainActivity> = 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())
  73. @RunWith(AndroidJUnit4::class) class MainActivityUiTest { @get:Rule val activityTestRule: ActivityTestRule<MainActivity> = 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())
  74. @RunWith(AndroidJUnit4::class) class MainActivityUiTest { @get:Rule val activityTestRule: ActivityTestRule<MainActivity> = 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())
  75. @RunWith(AndroidJUnit4::class) class MainActivityUiTest { @get:Rule val activityTestRule: ActivityTestRule<MainActivity> = 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())
  76. @RunWith(AndroidJUnit4::class) class MainActivityUiTest { @get:Rule val activityTestRule: ActivityTestRule<MainActivity> = 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())
  77. @RunWith(AndroidJUnit4::class) class MainActivityUiTest { @get:Rule val activityTestRule: ActivityTestRule<MainActivity> = 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())
  78. @RunWith(AndroidJUnit4::class) class MainActivityUiTest { @get:Rule val activityTestRule: ActivityTestRule<MainActivity> = 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())
  79. @RunWith(AndroidJUnit4::class) class MainActivityUiTest { @get:Rule val activityTestRule: ActivityTestRule<MainActivity> = 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())
  80. @RunWith(AndroidJUnit4::class) class MainActivityUiTest { @get:Rule val activityTestRule: ActivityTestRule<MainActivity> = 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())
  81. @RunWith(AndroidJUnit4::class) class MainActivityUiTest { @get:Rule val activityTestRule: ActivityTestRule<MainActivity> = 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())
  82. @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 }
  83. @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 }
  84. @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 }
  85. @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 }
  86. @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 }
  87. @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 }
  88. @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 }
  89. @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 }
  90. @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 }
  91. @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 }
  92. @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 }
  93. @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 }
  94. @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
  95. • Why test? • Types of tests • Unit Tests

    • Integration Tests • UI Tests • Continuous Integration (CI) • Test-Driven Development (TDD) • Tests == Quality Conclusion