-
Notifications
You must be signed in to change notification settings - Fork 179
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
Add support for tests with coroutines #426
Comments
The general idea at this point is to delegate these things to tests. Otherwise it would expand to RxJava, Side note — from a personal point of view, such things should be a part of code structure and test arrangement. I’m not into coroutines but with RxJava it is possible to provide and replace |
I just thought that since coroutines is really part of Kotlin core, and Spek is a Kotlin test framework, it would just avoid lots of boilerplate code... but I guess one could make extension functions... |
It is not a boilerplate, it is dealing with application level-abstractions. Nothing can deal with that good enough except the developer. Test engine has a single task — run tests. And it is not trivial already. |
I stand with @ming13 here, it should be possible to provide Coroutines support as extension project on top of Spek, similarly to how we provide Specification style right now. By providing custom style you'll have control on what is allowed and how it works if there are tweaks required for Coroutines. We might however reconsider this and provide it as a Spek's own module in future :) Closing for now. |
Hi, What's the status on this? Will this be available in Spek 2? |
I'd still recommend to build coroutines support as separate extension library. In the conversation above you can find a lot of good points made by @ming13 on why we should probably not add such functionality into the core. Btw, it's not just coroutines, we've cut on most extensions in 2.x to release sooner and spend less time on support. |
Is there a chance that spekframework provide that extension library? Please also note, that |
Having Spek without coroutines support, or any roadmap to supporting coroutines is a serious limitation. It would be great to see this implemented asap! |
As I don't use coroutines that much, I'd like to see the various pain points you guys encounter while testing coroutines using Spek. Honestly, the biggest issue here is I'm not entirely sure how this extension would look like. |
@raniejade In order to avoid boilerplate in each specification we have to add an equivalent of the following in each project: fun <R> LifeCycleAware.memoizedBlocking(mode: CachingMode = defaultCachingMode, factory: suspend () -> R, destructor: suspend (R) -> Unit): MemoizedValue<R> =
memoized(mode, factory = { runBlocking { factory() } }, destructor = { runBlocking { destructor(it) } })
fun LifeCycleAware.beforeBlocking(block: suspend () -> Unit) =
beforeGroup { runBlocking { block() } }
fun LifeCycleAware.beforeEachBlocking(block: suspend () -> Unit) =
beforeEachTest { runBlocking { block() } }
fun LifeCycleAware.afterBlocking(block: suspend () -> Unit) =
afterGroup { runBlocking { block() } }
fun LifeCycleAware.afterEachBlocking(block: suspend () -> Unit) =
afterEachTest { runBlocking { block() } } Note that:
|
That looks like a great start @jcornaz. But can this issue be re-opened or re-created? |
thanks @jcornaz! Re-opening (so it's easier to track) but I'm not committing to anything yet. |
Crazy idea: So you can call normal functions in a |
Yes indeed. It'd be great from a usage perspective. I just wonder if it would noticeably impact performances or not.
Yes, but it can be an implementation detail of Spek (use |
Interesting, KotlinTest did the same approach: kotest/kotest#332.
Probably not that significant? AFAIK |
I'll do some more thinking... if you have any more ideas keep them coming. |
I have timeouts now working (#643 - at least for JVM, K/N only supports a single thread coroutine) which is using coroutines under the hood. Would be really easy now to just add in the |
I don't know. I'd say it sound somehow appealing. As far as I could see, there is a tiny performance impact on the first test only (probably because more classes have to be loaded). But I could not notice clear impact for the rest of the tests. An other "cons" is that adding But otherwise, I have to say it is really tempting to say: "Yes, put |
I started experimenting with this on #835. |
Drive-by question, is this working in the latest version of Spek or am I missing someting? I still have to wrap my tests with |
Would it be possible to add
cdescribe
,ccontext
,cBeforeEachTest
andcit
, etc.. (for example), that would have arunBlocking
(or the new TestCoroutine system...) inside... that would avoid extra nesting (like mockk.io did...).The text was updated successfully, but these errors were encountered: