Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/spring-boot/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java spring boot中的集成测试方法_Java_Spring Boot_Integration Testing - Fatal编程技术网

Java spring boot中的集成测试方法

Java spring boot中的集成测试方法,java,spring-boot,integration-testing,Java,Spring Boot,Integration Testing,我对集成测试有问题,因为一个元素不工作。当我加上 JSONAssert.assertEquals(expected, response.getBody(),false); 我有红色的错误和信息:未处理的异常:org.json.JSONException。 我向您展示我的所有集成测试代码: @RunWith(SpringRunner.class) @SpringBootTest(classes = TeamService.class, webEnvironment = SpringBootTes

我对集成测试有问题,因为一个元素不工作。当我加上

JSONAssert.assertEquals(expected, response.getBody(),false);
我有红色的错误和信息:未处理的异常:org.json.JSONException。 我向您展示我的所有集成测试代码:

@RunWith(SpringRunner.class)
@SpringBootTest(classes = TeamService.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
public class TeamIntegrationTest {

    @LocalServerPort
    private int port;

    TestRestTemplate restTemplate = new TestRestTemplate();

    HttpHeaders headers = new HttpHeaders();

    @Test
    public void integrationTeamTest(){

        HttpEntity<String> entity = new HttpEntity<String>(null,headers);

        HttpEntity<String> response = restTemplate.exchange(
                createURLWithPort("/teams"),
                HttpMethod.GET,entity,String.class);

        String expected = "{\"id\":1,\"name\":\"Apacze\",\"description\":\"grupa programistow\",\"city\":\"Włocławek\",\"headcount\":null},{\"id\":2,\"name\":\"Apacze\",\"description\":\"grupa programistow\",\"city\":\"Radom\",\"headcount\":null},{\"id\":3,\"name\":\"Apacze\",\"description\":\"grupa programistow\",\"city\":\"Warszawa\",\"headcount\":null},{\"id\":4,\"name\":\"Apacze\",\"description\":\"grupa programistow\",\"city\":\"Kraków\",\"headcount\":null}";

        JSONAssert.assertEquals(expected, response.getBody(),false); -> this line throw exception
    }

    private String createURLWithPort(String uri){
        return "http://localhost:" + port + uri;
    }
}
@RunWith(SpringRunner.class)
@SpringBootTest(classes=TeamService.class,webEnvironment=SpringBootTest.webEnvironment.RANDOM\u端口)
公共类TeamIntegrationTest{
@本地服务器端口
专用int端口;
TestRestTemplate restTemplate=新的TestRestTemplate();
HttpHeaders=新的HttpHeaders();
@试验
public void integrationTeamTest(){
HttpEntity=新的HttpEntity(空,标题);
HttpEntity响应=restTemplate.exchange(
createURLWithPort(“/teams”),
获取、实体、字符串、类);
“描述”描述:“:“Gru帕编程者”的,”城市“,“城市”城市“:“城市”城市”城市“:“W\3222OC-322冬冬冬冬威威克”的,”城市城市城市城市“:“W\3222瓦瓦瓦克”的,”城市城市城市“::“W\322222瓦瓦瓦克克”的,”,”人头计数\,,,“人头人数人数”倒倒倒倒倒倒倒倒倒倒倒倒倒倒倒是,”,”,”,”,”,”,”,”,”若若若若若若,”,”,”,”,”,”,”人头人数人数倒倒倒倒倒倒倒倒倒倒倒倒倒倒倒倒倒倒倒倒倒倒倒倒倒倒倒倒倒倒倒倒倒倒倒倒倒倒倒倒倒倒倒倒倒倒倒倒倒倒是,”,”,”,”,”,”,”,”,”倒倒倒倒倒倒倒倒倒倒倒倒倒倒倒是,”,”,”,”,”,”,”,”,”,”,”,”,”,”,”,”“,\”总人数\“:null},{\'id\':4,\'name\':\'Apacze\',\'description\':\'grupa programistow\',\'city\':\'Kraków\',\'headcount\':null}”;
assertEquals(预期为response.getBody(),false);->此行引发异常
}
私有字符串createURLWithPort(字符串uri){
返回“http://localhost:“+端口+uri;
}
}

放置堆栈跟踪,或指明获取异常的行。这是在编译时还是在运行时?可能与