首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >GraphQL测试返回404未找到

GraphQL测试返回404未找到
EN

Stack Overflow用户
提问于 2020-11-09 21:44:38
回答 1查看 556关注 0票数 3

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

代码语言:javascript
复制
@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"));
  }
}

我得到了以下响应:

代码语言:javascript
复制
<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

任何帮助我们都很感激。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2021-04-14 05:02:34

我也有同样的问题。删除@GraphQLTest并添加以下内容。虽然GraphQLTest接口有@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT),但我不确定为什么会这样

代码语言:javascript
复制
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"));
  }
}
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/64752857

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档