package Ġca . six . demo . ut est 2 Ċ Ċ import Ġandroidx . test . core . app . Activity Scenario Ċ import Ġandroidx . test . espress o . Esp ress o . on View Ċ import Ġandroidx . test . espress o . action . View Actions . click Ċ import Ġandroidx . test . espress o . assertion . View Assertions . matches Ċ import Ġandroidx . test . espress o . matcher . View Matchers . with Id Ċ import Ġandroidx . test . espress o . matcher . View Matchers . with Text Ċ import Ġandroidx . test . ext . junit . runners . Android JUnit 4 Ċ import Ġca . six . demo . ut est 2 . temp . Ro bo lectric Test Src Activity Ċ import Ġca . six . demo . ut est 2 . core . Worker Ċ import Ġorg . junit . After Ċ import Ġorg . junit . Before Ċ import Ġorg . junit . Test Ċ import Ġorg . junit . runner . RunWith Ċ import Ġorg . mockito . Mockito .* Ċ Ċ @ RunWith ( Android JUnit 4 :: class ) Ċ class ĠRo bo lectric Test Src Activity Logic Test Ġ{ ĊĠĠĠ Ġlateinit Ġvar Ġscenario : ĠActivity Scenario < Ro bo lectric Test Src Activity > ĊĊĠĠĠ Ġ@ Before ĊĠĠĠ Ġfun Ġsetup () Ġ{ ĊĠĠĠĠĠĠĠ Ġscenario Ġ= ĠActivity Scenario . launch ( Ro bo lectric Test Src Activity :: class . java ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ After ĊĠĠĠ Ġfun Ġclean () Ġ{ ĊĠĠĠĠĠĠĠ Ġscenario . close () ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġclick Button _ text Change Text () Ġ{ ĊĠĠĠĠĠĠĠ Ġon View ( with Id ( R . id . tv Main )) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. check ( matches ( with Text (" MainActivity "))) ĊĊĠĠĠĠĠĠĠ Ġon View ( with Id ( R . id . btn Main )) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. perform ( click ()) ĊĠĠĠĠĠĠĠ Ġon View ( with Id ( R . id . tv Main )) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. check ( matches ( with Text (" work . 2 3 "))) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġclick Button _ call Worker () Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġworker Ġ= Ġmock ( Worker :: class . java ) ĊĠĠĠĠĠĠĠ Ġscenario . on Activity Ġ{ Ġact v Ġ-> Ġact v . worker Ġ= Ġworker Ġ} ĊĊĠĠĠĠĠĠĠ Ġon View ( with Id ( R . id . btn Main )) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. perform ( click ()) ĊĊĠĠĠĠĠĠĠ Ġverify ( worker ). work Sync ( 2 3 ) ĊĠĠĠ Ġ} Ċ Ċ }