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

[kohttp-mockk] Mockk integration #161

Open
neisip opened this issue Sep 26, 2019 · 1 comment · May be fixed by #188
Open

[kohttp-mockk] Mockk integration #161

neisip opened this issue Sep 26, 2019 · 1 comment · May be fixed by #188
Assignees
Labels
enhancement New feature or request
Milestone

Comments

@neisip
Copy link

neisip commented Sep 26, 2019

It would be really nice to have ability to somehow swap defaultHttpClient: okhttp3.Call.Factory with Mock Entity in tests. For now current implementation of functions like httpGet {} can be only tested by using MockWebServer from okhttp or you have to inject okhttp3.Call.Factory manually.

Ideally i would like to have integration with mockk, because it's designated mocking framework for kotlin.

Example:

@EnableOkHttpMock
class MyTest {
    
    private val sut = MyBestService()
    
    fun `test foo is bar`() {
        //given
        every { httpGet(any()) } returns "foo" to "bar"
        
        //when
        val res = sut.getBar()
        
        //then
        assert("bar", res)
    }
}

@rybalkinsd
Copy link
Owner

There is a available out of the box now:

 mockkStatic("io.github.rybalkinsd.kohttp.dsl.HttpGetDslKt")
 every { httpGet(any(), any()) } returns Response.Builder()....build()

Need to add separate module, which will invoke all the static mocks initialisation.
Also need some sugar

@rybalkinsd rybalkinsd self-assigned this Nov 28, 2019
@rybalkinsd rybalkinsd added the enhancement New feature or request label Nov 28, 2019
@rybalkinsd rybalkinsd changed the title Mockk integration [kohttp-mockk] Mockk integration Nov 28, 2019
@rybalkinsd rybalkinsd added this to the 0.12.0 milestone Nov 28, 2019
@rybalkinsd rybalkinsd linked a pull request May 14, 2020 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants