-
Notifications
You must be signed in to change notification settings - Fork 1.8k
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
Support runBlocking for UI Tests #464
Comments
It is possible to create a test dependency for coroutine to put there As a personal consideration In production mode :
|
I totally agree. Using the system property, tests may pass where production would fail. It should be the opposite. |
As mentionned by @gildor (in #458) and @svenjacobs (in #227), there are other uses-cases for which it is valid to block the UI thread when it comes to application initialization and cleanup. Especially when theses operations are fast, it would add unnecessary complexity to do it in a non-blocking fashion. The more it goes, the more I am getting convinced think that:
|
Reposting this from #227 so that it doesn't get lost:
|
Such features are usually implemented as default safety mechanism against accidental misusages, but when they start to make programming experience worse or require explicit opt-in (especially on every call-site) it's a good marker that feature is harmful. I think we should revert this change:
|
there are also valid times when you know |
If the change is reverted (which I think it should be), maybe scarier documentation to discourage runBlocking? |
Some kind of opt-in (maybe Android Also, I am loosely familiar with As @svenjacobs there was a legacy project, were I got 60% less startup time using If coroutines had this behaviour by that time, we probably would solve it with less efficiency and a really uglier callback hell code, almost no reusable code for the new refactored version, but still there would be blocking code there, just not using coroutines. The easier integration was exactly the selling point by the time. Sometimes we need to use a bad approach to help in an already worse situation. So then we can focus in re-architecting it all, I believe we can help developers do the right thing, but we must let them do the bad choices also. ¯\_(ツ)_/¯ |
I'm very inclined to replace my usages of |
Launch and then somehow making it blocking would be a workaround. That's exactly what runBlocking is good for. I really hope for a soon revert. |
It is already reverted in |
So this is case closed, right? It was released in |
It is released in |
I've got a question about this and please excuse my ignorance as I'm just getting started with coroutines. One instance where I am using runBlocking as a convenience method is in Android WebClient, where request handling takes place on the ChromeIO thread and the view remains on the UI thread. If I wish to check that a request is the main frame, I can do this:
But the view is on the main thread so that will fail. I can use runBlocking as a pseudo thread manager, like this
And that does the trick but shows the error info message,
I could achieve the same thing with an RxJava So this seems like a good use case, unless I'm totally mistaken. |
As mentionned by @PaulWoitaschek in #458, there is a problem with the fact that
runBlocking
fails by default in a UI thread (see #227).The problem is that if one wants to perform UI tests, then (depending on tool used) the test methods may be called on the UI thread. (this is apparently the case for android, and it is the case for TestFx with Junit5)
Then there is actually no good solution for theses tests. Yes, one could run the tests using the system property introduced in #458, and the tests will pass. But this is not a good solution, because the tests will pass even if there is a
runBlocking
in the actual production code, and we'd end-up with passing tests, but failing application.So here is two proposed solutions:
runTest
method which would not fail, even if in UI thread (proposed by @PaulWoitaschek).failsInUI
(or better named) argument torunBlocking
which would allow to explicitly by-pass the checkers (only for this call of runBlocking)The text was updated successfully, but these errors were encountered: