使用Rest Assured在Jira中创建测试

时间:2018-06-17 10:02:05

标签: gson jira rest-assured jira-rest-api jira-rest-java-api

我是Rest Assured的新手,目前正尝试使用Rest Assured创建一个JSON消息,用于在Jira中发布类型为TEST的问题。但是,我无法在消息中正确创建测试步骤。下面是我得到的代码和消息结构。

TestStepMap teststep = new TestStepMap();
List<TestStepMap> s = new ArrayList<TestStepMap>();

for (int i=0; i<4; i++)
{
    int index = i;
    String step = "Step " + (i+1);
    String data = "Data " + (i+1);
    String result = "Result " + (i+1);

    teststep.setIndex(index);
    teststep.setStep(step);
    teststep.setData(data);
    teststep.setResult(result);

    s.add(i, teststep);
}

CustomField10011Map customfield_10011 = new CustomField10011Map();
customfield_10011.setSteps(s);

这是我得到的输出。

{
    "fields": {
        "project": {
            "key": "RT"
        },
        "summary": "Sum of two numbers",
        "description": "example of manual test",
        "issuetype": {
            "name": "Test"
        },
        "customfield_10007": {
            "value": "Manual"
        },
        "customfield_10011": {
            "steps": [
                {
                    "index": 3,
                    "step": "Step 4",
                    "data": "Data 4",
                    "result": "Result 4"
                },
                {
                    "index": 3,
                    "step": "Step 4",
                    "data": "Data 4",
                    "result": "Result 4"
                },
                {
                    "index": 3,
                    "step": "Step 4",
                    "data": "Data 4",
                    "result": "Result 4"
                },
                {
                    "index": 3,
                    "step": "Step 4",
                    "data": "Data 4",
                    "result": "Result 4"
                }
            ]
        }
    }
}

最后一步将覆盖测试步骤1,2和3。我该如何解决这个问题?任何建议都非常受欢迎。

提前致谢。

1 个答案:

答案 0 :(得分:0)

您每次将相同 teststep实例添加到列表s

您想要的是在每次迭代中创建并添加一个新的TestStepMap对象,否则,您将始终覆盖该循环的早期迭代中对该对象的更新。

List<TestStepMap> s = new ArrayList<TestStepMap>();

for (int i=0; i<4; i++)
{
    int index = i;
    String step = "Step " + (i+1);
    String data = "Data " + (i+1);
    String result = "Result " + (i+1);

    TestStepMap teststep = new TestStepMap();
    teststep.setIndex(index);
    teststep.setStep(step);
    teststep.setData(data);
    teststep.setResult(result);

    s.add(i, teststep);
}