GraphQL 测试 returns 404 未找到

GraphQL Test returns 404 not found

我有一个使用 GraphQL 的 Spring 引导应用程序。我想使用 Spring Boot GraphQL 测试库添加集成测试。我正在尝试以下测试:

@GraphQLTest
public class UserTest {
  @Autowired
  private GraphQLTestTemplate graphQLTestTemplate;

  @Test
  public void createUser() throws IOException {
    GraphQLResponse response = graphQLTestTemplate.postForResource("graphql/register.graphql");
    assertNotNull(response);
    assertTrue(response.isOk());
    assertEquals("1", response.get("$.data.post.id"));
  }
}

我得到以下回复:

<404,<!doctype html><html lang="en"><head><title>HTTP Status 404 – Not Found</title><style type="text/css">body {font-family:Tahoma,Arial,sans-serif;} h1, h2, h3, b {color:white;background-color:#525D76;} h1 {font-size:22px;} h2 {font-size:16px;} h3 {font-size:14px;} p {font-size:12px;} a {color:black;} .line {height:1px;background-color:#525D76;border:none;}</style></head><body><h1>HTTP Status 404 – Not Found</h1><hr class="line" /><p><b>Type</b> Status Report</p><p><b>Message</b> The requested resource [&#47;api&#47;graphql] is not available</p><p><b>Description</b> The origin server did not find a current representation for the target resource or is not willing to disclose that one exists.</p><hr class="line" /><h3>Apache Tomcat/9.0.37</h3></body></html>,[Content-Type:"text/html;charset=utf-8", Content-Language:"en", Content-Length:"766", Date:"Sun, 08 Nov 2020 00:18:11 GMT", Keep-Alive:"timeout=60", Connection:"keep-alive"]>

这是相关的 GitHub 问题: https://github.com/graphql-java-kickstart/graphql-spring-boot/issues/267

感谢任何帮助...

我遇到了同样的问题。删除 @GraphQLTest 并添加以下内容。虽然 GraphQLTest 接口有 @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)

,但我不确定为什么会这样
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;

@ExtendWith(SpringExtension.class)
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
class UserTest {
  @Autowired
  private GraphQLTestTemplate graphQLTestTemplate;

  @Test
  public void createUser() throws IOException {
    GraphQLResponse response = graphQLTestTemplate.postForResource("graphql/register.graphql");
    assertNotNull(response);
    assertTrue(response.isOk());
    assertEquals("1", response.get("$.data.post.id"));
  }
}