Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
277 views
in Technique[技术] by (71.8m points)

api - Is it possible to have several pm.test() inside a pm.test()

Is it possible to have several pm.test() inside a pm.test()? In such a way that if any of the inner pm.test() fails, the outer pm.test() will also fail. And if no inner pm.test() fails, the outer pm.test() passes.

My requirement is similar to how pm.expect() works. But i want to use pm.test() instead so i can the status of each test in the Test Results tab.

My code is below.

var response = pm.response.json()
pm.test("Test scenario 1", ()=> {
    
    pm.test("Checking response code", ()=> {
        pm.expect(response.code).to.eql(200);
    });
    
    pm.test("Checking response message", ()=> {
        pm.expect(response.message).to.eql('OK');
    });
   
    //more pm test
});

Thanks a lot.

question from:https://stackoverflow.com/questions/65882337/is-it-possible-to-have-several-pm-test-inside-a-pm-test

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
pm.test("Test scenario 1", ()=> {
    
    pm.test("Checking response code", ()=> {
        pm.expect(pm.response.code).to.eql(200);
    });
    
    pm.test("Checking response message", ()=> {
        pm.expect(pm.response.status).to.eql('5OK');
    });
   
    //more pm test
});

you can have but the output will show this as three tests only and result of internal test won't affect the out side abstraction

enter image description here

so in short you can but it won't give the behavior as you except


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...