邮递员测试中是否可以包含软断言?

问题描述 投票:2回答:1

因此,如果任何测试失败,它就不应停止在Pipeline中的部署。

“请参阅屏幕快照以查看状态”

postman assert web-api-testing
1个回答
0
投票

不幸的是,目前在Postman测试中无法通过测试进行软断言。

但是,另一种选择是将测试简单地分为不同的测试。

此:

pm.test('Status code is 201', () => {
    pm.response.to.have.status(201);
});

const json = pm.response.json();

pm.test('Idea External Id is present', () => {
    pm.expect(json)
        .to.have.property('external_id')
        .to.have.lengthOf(16);

    pm.environment.set("idea-external-id", json.external_id);
});

pm.test('Expected Idea is returned', () => {
    pm.expect(json)
        .to.have.property('title', 'Make Bed $0.50');
    pm.expect(json)
        .to.have.property('description', 'Make your bed.');
    pm.expect(json)
        .to.have.nested.property('call_to_action.uri', 'https://youtu.be/Du0M6yVjKlA');
    pm.expect(json)
        .to.have.nested.property('call_to_action.label', 'Instructional Video');
    pm.expect(json)
        .to.have.property('key', 'chore_chart');
    pm.expect(json)
        .to.have.property('created_at');
    pm.expect(json)
        .to.have.property('updated_at');
    pm.expect(json)
        .to.have.nested.property('_links.self.href')
        .to.match(new RegExp(`.+/idea/${pm.environment.get("idea-external-id")}`));
});

成为此:

pm.test('Status code is 201', () => {
    pm.response.to.have.status(201);
});

const json = pm.response.json();

pm.test('Idea External Id is present', () => {
    pm.expect(json)
        .to.have.property('external_id')
        .to.have.lengthOf(16);

    pm.environment.set("idea-external-id", json.external_id);
});

pm.test('Expected Idea title is returned', () => {
    pm.expect(json)
        .to.have.property('title', 'Make Bed $0.50');
});

pm.test('Expected Idea description is returned', () => {
    pm.expect(json)
        .to.have.property('description', 'Make your bed.');
});

pm.test('Expected Idea call_to_action.uri is returned', () => {
    pm.expect(json)
        .to.have.nested.property('call_to_action.uri', 'https://youtu.be/Du0M6yVjKlA');
});

pm.test('Expected Idea call_to_action.uri is returned', () => {
    pm.expect(json)
        .to.have.nested.property('call_to_action.label', 'Instructional Video');
});

pm.test('Expected Idea key is returned', () => {
    pm.expect(json)
        .to.have.property('key', 'chore_chart');
});

pm.test('Idea created_at is returned', () => {
    pm.expect(json)
        .to.have.property('created_at');
});

pm.test('Idea updated_at is returned', () => {
    pm.expect(json)
        .to.have.property('updated_at');
});

pm.test('Expected Idea _links is returned', () => {
    pm.expect(json)
        .to.have.nested.property('_links.self.href')
        .to.match(new RegExp(`.+/idea/${pm.environment.get("idea-external-id")}`));
});
© www.soinside.com 2019 - 2024. All rights reserved.