question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

asserts should support kotlin coroutines support.

See original GitHub issue

I am trying to test network connectivity and by method is a suspend function. It work be nice if there is coroutine support present like mockito provides, for example, coAssertThat().

Currently, we need to wrap the assert call inside runBlocking{} scope. runBlocking { assertThat(mockNetworkInfo.isConnected()) }

it would be nice if this support is provided so that all we need to do is: coAssertThat(mockNetworkInfo.isConnected())

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:6

github_iconTop GitHub Comments

1reaction
JakeWhartoncommented, Apr 3, 2020

I do not know of any. But I’ll start following that JUnit 5 issue (despite being extremely bearish on 5.x).

If you wanted to get really, really creative with JUnit 4 I believe you can do this as a custom test runner. You would discover the test methods yourself which would be in the form

@Test public Object testName(Continuation<? extends Unit> continuation)

and then invoke them with some very low-level coroutine machinery.

I could be convinced to be nerd-sniped by this task… I just have to find the time…

And, of course, the big problem here is that JUnit 4 test runners do not compose so you couldn’t combine it with parameterized or anything else.

0reactions
hs-kdhilloncommented, Apr 3, 2020

Sounds good will try to implement this.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Testing Kotlin coroutines on Android
Unit testing code that uses coroutines requires some extra attention, as their execution can be asynchronous and happen across multiple threads.
Read more >
Testing Kotlin Coroutines - Kt. Academy
To use TestCoroutineScheduler on coroutines, we should use a dispatcher that supports it. The standard option is StandardTestDispatcher . Unlike most ...
Read more >
kotlinx-coroutines-test
The coroutine dispatcher used for tests is single-threaded, meaning that the child coroutines of the runTest block will run on the thread that...
Read more >
Assertions in kotlin coroutines / callback - Stack Overflow
Which call is suspending here? · Hmm believe it or not, that is actually a good question. · I added a stripped version...
Read more >
Kotlin Flow Assert Delight - Coding with Mohit
Let's look at a simple example we could write a test for. The snippet below shows a repository that takes in an API...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found