Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

多场景下的参数化如何进行? #1

Open
sunskblue opened this issue Sep 3, 2020 · 3 comments
Open

多场景下的参数化如何进行? #1

sunskblue opened this issue Sep 3, 2020 · 3 comments

Comments

@sunskblue
Copy link

sunskblue commented Sep 3, 2020

我看了企业微信创建部门的 demo。如下代码,应该是只支持创建某一部门,如果我需要测试各个字段在不同类型下部门创建是否成功,应该怎么做呢?
是不是需要重新创建一个createDepartmentRequest 2,然后在body 中编辑一份另外的数据。如果需要测试各种场景,是不是需要重新创建createDepartmentRequest 3、createDepartmentRequest 4、createDepartmentRequest .....?

/**
     * 企业微信创建部门
     *
     * @return Response
     */
    public Response createDepartment() {
        return given().when()
                .contentType("application/json")
                .body(createDepartmentRequest.get("body"))
                .post(hostUrl + createDepartmentRequest.get("api") + "?access_token=" + token)
                .then().log().body()
                .extract().response();
    }
/**
     * 创建部门接口
     */
    public final static Map<String, String> createDepartmentRequest = new HashMap<String, String>() {
        {
            put("api", "/cgi-bin/department/create");
            put("body",
                    "    {\n" +
                            "       \"name\": \"广州研发中心\",\n" +
                            "       \"name_en\": \"RDGZ\",\n" +
                            "       \"parentid\": 1,\n" +
                            "       \"order\": 1,\n" +
                            "       \"id\": 2\n" +
                            "    }");
        }
    };
@abcnull
Copy link
Owner

abcnull commented Sep 3, 2020

你好,没必要创建多个createDepartmentRequest方法,因为首先是多场景测这个功能,也就是说测试用例是多个,createDepartmentRequest可以公用一个,不过测试数据你要写多个,因此你只用自己加数据就行,然后可以结合testng多参数运行case即可

@abcnull
Copy link
Owner

abcnull commented Sep 5, 2020

public class DemoTest {
    @DateProvider(name = "xxx")
    public Object[][] fun() {
        return new Object[][] {
            {"参数列表1", 0, 1},
            {"参数列表2", 2, 3}
        };
    }
    
    @Test(dataProvider = "xxx")
    public void TestCreateDepartment(String param1, int param2, int param3) {
        
    }
}

@sunskblue
Copy link
Author

public class DemoTest {
    @DateProvider(name = "xxx")
    public Object[][] fun() {
        return new Object[][] {
            {"参数列表1", 0, 1},
            {"参数列表2", 2, 3}
        };
    }
    
    @Test(dataProvider = "xxx")
    public void TestCreateDepartment(String param1, int param2, int param3) {
        
    }
}

你的代码里没有找到这种方式,所以我以为createDepartmentRequest需要创建多个方法。
上面这种方式,我之前用过。感谢您的回复

@abcnull abcnull reopened this Sep 18, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants