有没有办法创建一个将值返回给另一个方法的 JUnit 测试?我意识到它应该是一个void返回类型,但我希望有另一种方法 - 通过 Jmeter,在将 JSON 字符串返回到 JMeter 之前自动运行测试。
@RequestMapping(value = "/testGetPlayer", produces = "application/json",
method = RequestMethod.POST)
@ResponseBody
public Response getPlayer(final HttpServletRequest req){
this.response = new Response();
String newPlayer = req.getParameter("player");
this.response = pServ.checkPlayer(newPlayer);
if(this.testGetPlayer()){
System.out.println("woohoo");
}
//assert that incoming response string will
//contain "created player" or somesuch
return response;
}
@Test
public void testGetPlayer(){
for(String m : response.getMessages()){
if(m.equals("PLS_M001: Player does not exist")){
assertTrue(m.equals("PLS_M001: Player does not exist"));
}
else{
assertTrue(m.equals("PLS_M002: Player exists"));
}
}
}
我想要这样的东西:
@Test
public boolean testGetPlayer(){
boolean allgood = false;
for(String m : response.getMessages()){
if(m.equals("PLS_M001: Player does not exist")){
assertTrue(m.equals("PLS_M001: Player does not exist"));
allgood = true;
}
else{
assertTrue(m.equals("PLS_M002: Player exists"));
allgood = true;
}
}
return allgood;
}
抱歉,如果这是一个明显的禁忌,但我仍在学习 Junit 和 Jmeter,并想看看我能把它们推到多远。
谢谢