0

我在单元测试中尝试模拟 smallrye-graphql-client 时遇到了一些问题。我认为这将是一个类似于模拟 RestClient https://github.com/quarkusio/quarkus/issues/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() {
        ...
    }
}

应用程序.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?

预先感谢您的帮助

4

0 回答 0