Quarkus:如何使用 Mockito 模拟 Smallrye-graphql-client?
我在单元测试中尝试模拟 Smallrye-graphql-client 时遇到一些问题。 我认为这将是一个类似于模拟 RestClient https://github.com/quarkusio/ 的过程夸库斯/问题/9630 但事实并非如此。
GraphQL 客户端:
@GraphQLClientApi(configKey = "graphql-client")
public interface SomeGraphQLClient {
@Query("accounts")
List<Account> getAccounts();
}
测试:
@QuarkusTest
public final class SomeGraphQLClientTest {
@InjectMock()
SomeGraphQLClient client;
@BeforeEach
void setup() {
when(client.getAccounts()).thenReturn(... list of accounts...);
}
@Test
public void someTest() {
...
}
}
application.yaml
...
smallrye-graphql-client:
graphql-client:
url: http://localhost:8081/graphql
错误消息:
Invalid use of io.quarkus.test.junit.mockito.InjectMock - the injected bean does not declare a CDI normal scope but: javax.inject.Singleton.
如何在 Quarkus 中模拟 Smallrye-graphql-client?
预先感谢您的帮助
I am having some issues trying to mock the smallrye-graphql-client in my unit tests.
I thought it would be a process similar to mocking the RestClient https://github.com/quarkusio/quarkus/issues/9630
but it doesn't work that way.
GraphQL client:
@GraphQLClientApi(configKey = "graphql-client")
public interface SomeGraphQLClient {
@Query("accounts")
List<Account> getAccounts();
}
Test:
@QuarkusTest
public final class SomeGraphQLClientTest {
@InjectMock()
SomeGraphQLClient client;
@BeforeEach
void setup() {
when(client.getAccounts()).thenReturn(... list of accounts...);
}
@Test
public void someTest() {
...
}
}
application.yaml
...
smallrye-graphql-client:
graphql-client:
url: http://localhost:8081/graphql
Error message:
Invalid use of io.quarkus.test.junit.mockito.InjectMock - the injected bean does not declare a CDI normal scope but: javax.inject.Singleton.
How can I mock the smallrye-graphql-client in Quarkus?
Thank you in advance for your help
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论