相关疑难解决方法(0)

如何测试Jersey REST Web服务?

我编写了一个Restful Web服务,必须使用JUnit4进行测试.我已经使用Jersey Client编写了一个客户端.但是想知道我是否只能使用junit4来测试我的服务.至少有人可以帮我提供样品.

我的休息服务具有验证方法,该方法获取用户名,密码并返回令牌.

我已经为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);
    }
}
Run Code Online (Sandbox Code Playgroud)

java rest junit unit-testing jersey

17
推荐指数
1
解决办法
4万
查看次数

标签 统计

java ×1

jersey ×1

junit ×1

rest ×1

unit-testing ×1