mardi 31 mars 2015

junit 4 test case to test rest web service

I have written a Restful Web service and have to test it using JUnit4. I have already written a Client using Jersey Client. But want to know if I can test my service only with junit4. Can someone help me with sample at least.


My rest service has authenticate method that takes user name, password and returns a token.


I have written test case for authenticate method. But I am not sure how to test using 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);
}


}


Aucun commentaire:

Enregistrer un commentaire