Open avdbrink opened 4 years ago
@GraphQLTest
works in a way similar to @DataJpaTest
. That annotation loads everything you need to test your JPA layer, and so @GraphQLTest
loads everything to test your GraphQL layer. I get your use case though. Maybe we should add support for something like that, either using a property on the GraphQLTest
annotation, or introduce a separate annotation like GraphQLResolverTest
or something (might be easier to differentiate, not sure).
Please note that this will require some effort to implement so it'll be added to the list, but not sure when we'll have time to work on it. We do encourage and welcome contributions in case you'd want to help out :)
I think ideally it should work similar to @WebMvcTest
:
In an application with multiple controllers, you can even ask for only one to be instantiated by using, for example, @WebMvcTest(HomeController.class).
from the Spring Testing the Web Layer guide.
Hi, you can find GraphQL Spring Boot server example here: https://github.com/ermadmi78/kobby-gradle-example
Tests example is placed here: https://github.com/ermadmi78/kobby-gradle-example/blob/main/cinema-server/src/test/kotlin/io/github/ermadmi78/kobby/cinema/server/CinemaServerTest.kt
To run tests from IntelliJ IDEA install Kotest plugin: https://plugins.jetbrains.com/plugin/14080-kotest
I'm trying to write a unit test for my GraphQLQueryResolver implementations. I have different implementations, that use different services. My GraphQLQueryResolver auto wires a service and I mock these service beans in my unit test, but I didn't expect to have to mock all service bean of all query resolver implementations. I'm testing only one at a time. I've created a small demo to reproduce the issue.
Maybe this is just me missing out on something obvious, but it seems to me that the @GraphQLTest annotation brings in all query resolvers, where I only want one. OR is there an easy way to reduce the number of resolvers loaded?