使用 Rest Assured 在 Jira 中创建测试

Creating Test in Jira using Rest Assured

我是 Rest Assured 的新手,目前正在尝试创建 JSON 消息以使用 Rest Assured 在 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 正在被最后一步覆盖。我该如何解决这个问题?非常欢迎任何建议。

提前致谢。

您每次都将 相同 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);
}