Unable to advance time with ShadowSystemClock robolectric

31 Views Asked by At

I've been trying to advance the time of System.currentTimeMillis() in a class under test. I know! pass a clock don't use the System.currentTimeMillis() directly, unfortunately this is not an option on the code I'm working on.

Anyway, to advance time I've tried using the ShadowSystemClock, however this does not seem to be working for me.

I'm using robolectric 4.4

@RunWith(RobolectricTestRunner::class)
@Config(manifest = "AndroidManifest.xml",
    sdk = [22],
    application = TestApplication::class,
    shadows = [ShadowSystemClock::class])
class myclass{

    @test 
    fun testOne (){
         functionOne()
         ShadowSystemClock.advanceBy(Duration.ofMinutes(1L))
         functionTwo()
    }
}

I've found a few examples through github and have tried implementing these with little success.

Any advice with the ShadowSystemClock class is greatly appreciated.

0

There are 0 best solutions below