Search code examples
annotationstestngrest-assuredtestcase

TestNG does not see all annotated tests


I have 2 TestNG testcase annotated with @Test. A methods have a return type of String, which is as well a testcase. The other one uses the output param of the first. when I ran both test, TestNG only showed that only one ran instead of 2.

public class Login {

    private static String INITIATE = "https://login.endpoint.com/initiate";
    private static String COMPLETE = "https://login.endpoint.com/complete";

    @SuppressWarnings("unchecked")
    @Test(groups = "middleware", priority = 1)
    public String InitiateLogin() throws FileNotFoundException, UnsupportedEncodingException {
        RequestSpecification request = RestAssured.given();
        request.header("Content-Type", "application/json");
        JSONObject json = new JSONObject();
        json.put("email", "[email protected]");
        json.put("password", "111111");
        request.body(json.toJSONString());
        Response response = request.post(INITIATE);
        String OTP = response.path("OTP");

        if(OTP.matches("[0-9]{4}")) {
            response.then().body(
                    "OTP", equalTo(OTP));
        }
        return OTP;
    }

    @SuppressWarnings("unchecked")
    @Test(groups = "middleware", priority = 2)
    public void CompleteLogin() throws FileNotFoundException, UnsupportedEncodingException {

        RequestSpecification completeRequest = RestAssured.given();
        completeRequest.header("Content-Type", "application/json");
        JSONObject completeJson = new JSONObject();
        completeJson.put("Otp", InitiateDeviceRelease());
        completeRequest.body(completeJson.toJSONString());
        Response completeResponse = completeRequest.post(COMPLETE);
        completeResponse.then().body(
                "SessionToken", equalTo("ewrtw4456765v543fw3v"));

    }
}

This is the output of the test. It suppose to show that 2 testcases ran, but it obly showed that only one ran. Is it because the first test have a return type and not void? What way can I make testng see that they are 2 testcases?

{
    "OTP": "6645"
}
PASSED: CompleteLogin

===============================================
    Default test
    Tests run: 1, Failures: 0, Skips: 0
===============================================


===============================================
Default suite
Total tests run: 1, Failures: 0, Skips: 0
===============================================

Solution

  • @Test method cannot have return type, it should be void always.

    try changing return type of InitiateLogin() method to void, it should work.