package Ġso y . gab im ore no . fl aky tests rules Ċ Ċ import Ġandroidx . test . espress o . Esp ress o . on View Ċ 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 . rules . Activity Scenario Rule Ċ import Ġandroidx . test . ext . junit . runners . Android JUnit 4 Ċ import Ġorg . hamcrest . Core Matchers . not Ċ import Ġorg . junit . Before Ċ import Ġorg . junit . Rule Ċ import Ġorg . junit . Test Ċ import Ġorg . junit . runner . RunWith Ċ Ċ @ RunWith ( Android JUnit 4 :: class ) Ċ class ĠMainActivity Test Ġ{ ĊĊĠĠĠ Ġcompanion Ġobject Ġ{ ĊĠĠĠĠĠĠĠ Ġprivate Ġconst Ġval ĠEXPECT ED _ TEXT Ġ= Ġ" Hello ĠWorld !" ĊĠĠĠĠĠĠĠ Ġprivate Ġconst Ġval ĠUN EXPECTED _ TEXT Ġ= Ġ" foo " ĊĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ get : Rule ĊĠĠĠ Ġvar Ġactivity Rule : ĠActivity Scenario Rule < MainActivity > Ġ= ĠActivity Scenario Rule ( MainActivity :: class . java ) ĊĊĠĠĠ Ġ// ĠComment Ġ/ ĠUncomment ĠRetry Fl aky Test Until Success Rule Ġor ĠRetry Fl aky Test Until Failure Rule Ġdepending Ġon Ġthe Ġcase ĊĠĠĠ Ġ@ Rule ĊĠĠĠ Ġ@ Jvm Field ĊĠĠĠ Ġval Ġretry Fl aky Test Until Success Rule Ġ= ĠRetry Fl aky Test Until Success Rule () Ċ Ċ // ĠĠĠ Ġ@ Rule Ċ // ĠĠĠ Ġ@ Jvm Field Ċ // ĠĠĠ Ġval Ġretry Fl aky Test Until Failure Rule Ġ= ĠRetry Fl aky Test Until Failure Rule () ĊĊĠĠĠ Ġprivate Ġlateinit Ġvar Ġmaybe Expected Text : ĠString ĊĊĠĠĠ Ġ@ Before ĊĠĠĠ Ġfun ĠsetUp () Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġsuffix Ġ= Ġif Ġ(( 0 .. 1 ). random () Ġ== Ġ 0 ) Ġ"" Ġelse Ġ"." ĊĠĠĠĠĠĠĠ Ġmaybe Expected Text Ġ= ĠEXPECT ED _ TEXT Ġ+ Ġsuffix ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġcheck Shows Expected Text () Ġ{ ĊĠĠĠĠĠĠĠ Ġon View ( with Id ( R . id . tv Text )) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. check ( matches ( with Text ( EXPECTED _ TEXT ))) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġcheck DoesNot Show Unexpected Text () Ġ{ ĊĠĠĠĠĠĠĠ Ġon View ( with Id ( R . id . tv Text )) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. check ( matches ( not ( with Text ( UN EXPECTED _ TEXT )))) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġcheck Shows Maybe Expected Text () Ġ{ ĊĠĠĠĠĠĠĠ Ġon View ( with Id ( R . id . tv Text )) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. check ( matches ( with Text ( maybe Expected Text ))) ĊĠĠĠ Ġ} Ċ } Ċ