TestNG没有看到所有带注释的测试

时间:2018-06-12 10:06:13

标签: annotations testng rest-assured testcase

我有2个用@Test注释的TestNG测试用例。方法的返回类型为String,它也是一个测试用例。另一个使用第一个的输出参数。当我运行两个测试时,TestNG只显示只有一个而不是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", "test@test.com");
        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"));

    }
}

这是测试的输出。它假设显示2个测试用例运行,但它显示只有一个测试用了。是因为第一次测试有返回类型而不是空白吗?我怎样才能让testng看到它们是2个测试用例?

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

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


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

1 个答案:

答案 0 :(得分:1)

@Test方法不能有返回类型,它总是应该是void。

尝试将InitiateLogin()方法的返回类型更改为void,它应该可以工作。