我已经编写了一个Restful Web服务,并且必须使用JUnit4对其进行测试。我已经使用Jersey Client编写了一个客户端。但是我想知道我是否只能用junit4测试我的服务。至少有人能帮我拿样品吧。
我的rest服务有一个身份验证方法,它接受用户名、密码并返回一个令牌。
我已经为authenticate方法编写了测试用例。但我不确定如何使用url进行测试。
public class TestAuthenticate {
Service service = new Service();
String username = "user";
String password = "password";
String token;
@Test(expected = Exception.class)
public final void testAuthenticateInputs() {
password = "pass";
service.authenticate(username, password);
}
@Test(expected = Exception.class)
public final void testAuthenticateException(){
username = null;
String token = service.authenticate(username, password);
assertNotNull(token);
}
@Test
public final void testAuthenticateResult() {
String token = service.authenticate(username, password);
assertNotNull(token);
}
}
https://stackoverflow.com/questions/29358940
复制相似问题