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

Request for Kotest version of GreetingServiceTest.kt #246

Open
mfickett opened this issue Oct 15, 2020 · 0 comments
Open

Request for Kotest version of GreetingServiceTest.kt #246

mfickett opened this issue Oct 15, 2020 · 0 comments

Comments

@mfickett
Copy link

There is a gRPC service test example for Kotlin using JUnit: https://github.com/micronaut-projects/micronaut-grpc/blob/master/examples/hello-world-kotlin/src/test/kotlin/helloworld/GreetingServiceTest.kt .

It would be great to have this example with Kotest, either instead or in addition.

I'm not sure if micronaut-grpc examples use kotest at all / what the build changes required would be; I think it may just be changing testRuntime to kotest in the build.gradle and adding a ProjectConfig.kt (docs at https://kotest.io/project_config/ and note it can now be a sibling of the other test files instead of being in the provided package).

The bean factory can be added to the ProjectConfig.kt or can be in its own file that's a peer of the test file. It didn't work for me to have the @Factory in the same file as the test. But I think the code changes are relatively minor:

GreetingServiceFactory.kt:

@Factory
class GreetingServiceFactory {
    @Singleton
    fun greetingClient( @GrpcChannel(GrpcServerChannel.NAME) channel : ManagedChannel ) : GreeterGrpcKt.GreeterCoroutineStub {
        return GreeterGrpcKt.GreeterCoroutineStub(
                channel
        )
    }
}

The test structure changes slightly:

GreetingServiceTest.kt:

import io.kotest.core.spec.style.StringSpec
import io.micronaut.test.extensions.kotest.annotation.MicronautTest
import io.kotest.matchers.shouldBe

@MicronautTest
class GreetingServiceTest: StringSpec() {

    @Inject
    lateinit var greetingClient : GreeterGrpcKt.GreeterCoroutineStub

    init {
        "test a response" {
            val actual = greetingClient.sayHello(
                            HelloRequest.newBuilder().setName("John").build()
                    ).message
            actual shouldBe "Hello John"
        }
    }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant