package Ġcom . google . samples . quickstart . canonical Ċ Ċ import Ġandroidx . test . espress o . Esp ress o . on Data Ċ 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 . Root Matchers . is Dialog Ċ import Ġandroidx . test . espress o . matcher . View Matchers Ċ import Ġandroidx . test . ext . junit . runners . Android JUnit 4 Ċ import Ġandroidx . test . platform . app . Instrumentation Registry Ċ import Ġandroidx . test . rule . Activity Test Rule Ċ import Ġandroidx . test . uia utom ator . Ui Device Ċ import Ġandroidx . test . uia utom ator . Ui Selector Ċ import Ġorg . hamcrest . Matchers Ċ import Ġorg . junit . After Ċ import Ġorg . junit . Before Ċ import Ġorg . junit . Rule Ċ import Ġorg . junit . Test Ċ import Ġorg . junit . runner . RunWith Ċ Ċ @ RunWith ( Android JUnit 4 :: class ) Ċ class ĠDatabase Interaction Test Ġ{ ĊĠĠĠ Ġ@ get : Rule ĊĠĠĠ Ġvar Ġactivity Rule : ĠActivity Test Rule < MainActivity > ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ= ĠActivity Test Rule ( MainActivity :: class . java ) ĊĊĠĠĠ Ġlateinit Ġvar Ġdevice Ġ: ĠUi Device ĊĊĠĠĠ Ġ@ Before ĊĠĠĠ Ġfun Ġsetup () Ġ{ ĊĠĠĠĠĠĠĠ Ġdevice Ġ= ĠUi Device . getInstance ( Instrumentation Registry . get Instrumentation ()) ĊĠĠĠĠĠĠĠ Ġon View ( View Matchers . with Id ( R . id . sign _ in _ button )) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. perform ( click ()) ĊĠĠĠĠĠĠĠ Ġval Ġgoogle SignIn Dialog Ġ= Ġdevice . find Object ( Ui Selector (). text (" example @ gmail . com ")) ĊĠĠĠĠĠĠĠ Ġgoogle SignIn Dialog . click And WaitFor New Window () ĊĠĠĠĠĠĠĠ Ġ// ĠMake Ġsure Ġthat : ĊĠĠĠĠĠĠĠ Ġ// Ġ 1 . ĠYour Ġgoogle Ġaccount Ġmust Ġhave Ġsigned Ġout Ġbefore Ġtest . ĊĠĠĠĠĠĠĠ Ġ// Ġ 2 . ĠYou Ġshould Ġhave Ġat Ġle st Ġone Ġgoogle Ġaccount Ġfor Ġyour Ġdevice , ĊĠĠĠĠĠĠĠ Ġ// Ġwhich Ġmeans , Ġwhen Ġyou Ġclick Ġsign Ġin Ġbutton , Ġyou Ġhave Ġat Ġleast ĊĠĠĠĠĠĠĠ Ġ// Ġone Ġaccount Ġto Ġchoose ĊĊĠĠĠĠĠĠĠ Ġ// ĠConstruct Ġyour Ġtest Ġdatabase : ĊĠĠĠĠĠĠĠ Ġ// ĠAccount : Ġexample @ gmail . com ĊĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġsubmit Record () Ġ{ ĊĠĠĠĠĠĠĠ Ġon View ( View Matchers . with Id ( R . id . start _ pause _ btn )) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. perform ( click ()) ĊĠĠĠĠĠĠĠ ĠThread . sleep ( 5 0 0 0 ) ĊĊĠĠĠĠĠĠĠ Ġon View ( View Matchers . with Id ( R . id . submit _ btn )) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. perform ( click ()) ĊĠĠĠĠĠĠĠ ĠThread . sleep ( 2 0 0 0 ) ĊĠĠĠĠĠĠĠ Ġon View ( View Matchers . with Text (" Submission ĠConfirm ")) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. in Root ( is Dialog ()) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. check ( matches ( View Matchers . is Displayed ())) ĊĠĠĠĠĠĠĠ Ġon View ( View Matchers . with Text (" Confirm ")) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. in Root ( is Dialog ()) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. perform ( click ()) ĊĠĠĠĠĠĠĠ ĠThread . sleep ( 1 0 0 0 ) ĊĊĠĠĠĠĠĠĠ Ġon View ( View Matchers . with Id ( R . id . bottom _ navigation _ item _ profile )) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. perform ( click ()) ĊĊĠĠĠĠĠĠĠ Ġon View ( View Matchers . with Id ( R . id . run _ history _ list _ view )) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. check ( matches ( View Matchers . is Displayed ())) ĊĠĠĠĠĠĠĠ Ġon Data ( Matchers . anything ()) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. in Adapter View ( View Matchers . with Id ( R . id . run _ history _ list _ view )) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. at Position ( 0 ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. on Child View ( View Matchers . with Id ( R . id . single _ run _ time )) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. check ( matches ( View Matchers . with Text (" 0 0 : 0 0 : 0 5 "))) Ġ// ĠIn Ġyour Ġtest Ġdatabase , Ġthe Ġlatest ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. perform ( click ()) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ After ĊĠĠĠ Ġfun Ġlogout User () Ġ{ ĊĠĠĠĠĠĠĠ Ġon View ( View Matchers . with Id ( R . id . bottom _ navigation _ item _ profile )) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. perform ( click ()) ĊĠĠĠĠĠĠĠ Ġon View ( View Matchers . with Id ( R . id . logout _ button )) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. perform ( click ()) ĊĠĠĠĠĠĠĠ ĠThread . sleep ( 1 0 0 0 ) ĊĠĠĠ Ġ} Ċ }