package Ġcom . challenge . android _ template . database Ċ Ċ import Ġandroidx . arch . core . executor . testing . Instant Task Executor Rule Ċ import Ġandroidx . room . Room Ċ import Ġandroidx . test . core . app . Application Provider Ċ import Ġandroidx . test . ext . junit . runners . Android JUnit 4 Ċ import Ġandroidx . test . filters . Small Test Ċ import Ġcom . challenge . android _ template . database . dao . Foo Dao Ċ import Ġcom . challenge . android _ template . database . entity . Foo Entity Ċ import Ġcom . challenge . android _ template . model . Foo Ċ import Ġcom . google . common . truth . Truth . assertThat Ċ import Ġkotlinx . coroutines . Experimental Cor outines Api Ċ import Ġkotlinx . coroutines . test . run Blocking Test Ċ import Ġorg . junit . After Ċ import Ġorg . junit . Before Ċ import Ġorg . junit . Rule Ċ import Ġorg . junit . Test Ċ import Ġorg . junit . runner . RunWith Ċ import Ġjava . io . IOException Ċ Ċ /** Ċ Ġ* ĠThis Ġis Ġan ĠInstrument ed Ġtest Ġwhich Ġis Ġthe Ġtype Ġrecommend Ġwhen Ġunit Ġtesting Ġdb Ċ Ġ* Ġmainly Ġbecause Ġthis Ġway Ġwe Ġuse Ġthe Ġsqlite Ġversion Ġfrom Ġan Ġemulator Ġor Ġreal Ċ Ġ* Ġdevice Ġinstead Ġof Ġthe Ġversion Ġon Ġour Ġlocal Ġmachine . Ċ Ġ*/ Ċ Ċ @ Experimental Cor outines Api Ċ @ RunWith ( Android JUnit 4 :: class ) Ċ @ Small Test Ċ class ĠFoo Instrument ed Db Client Test Ġ{ ĊĊĠ Ġprivate Ġlateinit Ġvar Ġfoo Dao : ĠFoo Dao ĊĠ Ġprivate Ġlateinit Ġvar Ġdb : ĠApp Database ĊĊĠ Ġ@ get : Rule ĊĠ Ġvar Ġinstant Task Executor Rule Ġ= ĠInstant Task Executor Rule () ĊĊĠ Ġ@ Before ĊĠ Ġfun Ġsetup () Ġ{ ĊĠĠĠ Ġdb Ġ= ĠRoom . in Memory Database Builder ( ĊĠĠĠĠĠ ĠApplication Provider . getApplicationContext (), ĊĠĠĠĠĠ ĠApp Database :: class . java ĊĠĠĠ Ġ). allow MainThread Queries (). build () ĊĠĠĠ Ġfoo Dao Ġ= Ġdb . foo Dao ĊĠ Ġ} ĊĊĠ Ġ@ After ĊĠ Ġ@ Throws ( IOException :: class ) ĊĠ Ġfun Ġteardown () Ġ{ ĊĠĠĠ Ġdb . close () ĊĠ Ġ} ĊĊĠ Ġ@ Test ĊĠ Ġ@ Throws ( Exception :: class ) ĊĠ Ġfun Ġread Write Fo os () Ġ= Ġrun Blocking Test Ġ{ ĊĠĠĠ Ġval Ġdummy Foo Ġ= ĠFoo Entity . from Model ( ĊĠĠĠĠĠ ĠFoo ( 1 , Ġ" Sh in ji ") ĊĠĠĠ Ġ) ĊĠĠĠ Ġfoo Dao . insert ( dummy Foo ) ĊĠĠĠ Ġval Ġfo os Ġ= Ġfoo Dao . getAll () ĊĠĠĠ ĠassertThat ( fo os . first (). name ). isEqualTo (" Sh in ji ") ĊĠ Ġ} Ċ Ċ }