integration-testingandroid-testingandroid-jetpackandroid-workmanagerinstrumented-test

Testing WorkManager - RUNNING instead of ENQUEUED


I am following this example, but my test fails, since workInfo.state is RUNNING instead of ENQUEUED. Does anyone know what might be the issue? Please let me know if I should provide more code/context.


Solution

  • I have no idea why, but adding constraints to the request resolved the issue. It did not matter what constraints I set, it succeeded anyhow. That is, the test passed both with NetworkType.METERED and NetworkType.UNMETERED

    val constraints = Constraints.Builder().setRequiredNetworkType(NetworkType.METERED).build()
    val request = PeriodicWorkRequestBuilder<EchoWorker>(15, MINUTES)
            .setInputData(input)
            .setConstraints(constraints) // added this line
            .build()