Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug causing test to not run properly #25

Closed
ArturoKuang opened this issue Feb 20, 2021 · 1 comment
Closed

Bug causing test to not run properly #25

ArturoKuang opened this issue Feb 20, 2021 · 1 comment

Comments

@ArturoKuang
Copy link

ArturoKuang commented Feb 20, 2021

Please complete the following information:

  • Library Version [e.g. v1.0.0]
  • Affected Device(s) [e.g. Samsung Galaxy s10 with Android 9.0]

Describe the Bug:
Any class that uses MainCoroutinesRule doesn't actually run the test. If you put the line assertThat(-1, `is`(0)) in any class that uses MainCoroutinesRule it would pass.

Expected Behavior:
assertThat(-1, `is`(0)) should assert and fail

Proposed Solution:
The following code should change from:

@ExperimentalCoroutinesApi
class MainCoroutinesRule : TestRule, TestCoroutineScope by TestCoroutineScope() {

  private val testCoroutinesDispatcher = TestCoroutineDispatcher()

  override fun apply(base: Statement?, description: Description?) = object : Statement() {
    override fun evaluate() {
      Dispatchers.setMain(testCoroutinesDispatcher)
      cleanupTestCoroutines()
      Dispatchers.resetMain()
    }
  }
}

to this:

@ExperimentalCoroutinesApi
class MainCoroutinesRule : TestRule, TestCoroutineScope by TestCoroutineScope() {

  private val testCoroutinesDispatcher = TestCoroutineDispatcher()

  override fun apply(base: Statement?, description: Description?) = object : Statement() {
    override fun evaluate() {
      Dispatchers.setMain(testCoroutinesDispatcher)
      try {
        base?.evaluate()
      } finally {
        cleanupTestCoroutines()
        Dispatchers.resetMain()
      }
    }
  }
}
@ArturoKuang ArturoKuang changed the title Bug causing test to run properly Bug causing test to not run properly Feb 20, 2021
@skydoves
Copy link
Owner

Resolved in ee4af50
Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants