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

Publish FlowAssert as a library? #1416

Closed
ychescale9 opened this issue Jul 18, 2019 · 6 comments · Fixed by #1863
Closed

Publish FlowAssert as a library? #1416

ychescale9 opened this issue Jul 18, 2019 · 6 comments · Fixed by #1863
Assignees

Comments

@ychescale9
Copy link

I like the FlowAssert test DSL for its resemblance to the RxJava2 test API. Are there plans to publish it as a standalone library / artifact or contribute to kotlinx.coroutines?

@JakeWharton
Copy link
Member

JakeWharton commented Jul 18, 2019 via email

@JakeWharton
Copy link
Member

JakeWharton commented Jul 20, 2019 via email

@AlecKazakova
Copy link
Collaborator

@JakeWharton when u do dis

@JakeWharton JakeWharton self-assigned this Jun 3, 2020
@JakeWharton
Copy link
Member

yeah let's do this

@mhernand40
Copy link

mhernand40 commented Jun 6, 2020

Not sure what things will be taken into consideration for the published version of FlowAssert, but looking at the current implementation, it is somewhat similar to a collectToList { … } utility I came up with where it's usages would be like so:

@Test
fun test() = runBlockingTest {
    val values = fooFlow.collectToList {
        // perform actions that result in emissions here
    }

    // Assert on the contents of the returned List here
}

The similarity is that it too internally launches a collector Coroutine and uses a Channel to send the values and produce a List of values emitted.

One thing I noticed is that when I used Hot Flows for my mock dependencies, such as Channel.asFlow() or MutableStateFlow, and then performed updates within the collectToList block, many of the values get dropped unless the test explicitly invokes yield() after each update. Based on the discussion in Kotlin/kotlinx.coroutines#2082, it seems this behavior is expected. If for such tests I would want to avoid using yield(), then the inner launched Coroutine that performs the collection would have to be launched using Dispatchers.Unconfined. Just thought I'd share in case it helps. Really looking forward to an official FlowAssert library! 😃

@JakeWharton
Copy link
Member

https://github.com/cashapp/turbine

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

Successfully merging a pull request may close this issue.

4 participants