Set
testfor thepostmanAPI.
Multiple rules are allowed.
test configurationpostman.test=```
pm.test("Body is correct", function () {
pm.response.to.have.body("response_body_string");
});
pm.test("Content-Type is present", function () {
pm.response.to.have.header("Content-Type");
});
pm.test("Response time is less than 200ms", function () {
pm.expect(pm.response.responseTime).to.be.below(200);
});
pm.test("Successful POST request", function () {
pm.expect(pm.response.code).to.be.oneOf([201,202]);
});
pm.test("Status code name has string", function () {
pm.response.to.have.status("Created");
});
var jsonObject = xml2Json(responseBody);
var schema = {
"items": {
"type": "boolean"
}
};
var data1 = [true, false];
var data2 = [true, 123];
pm.test('Schema is valid', function() {
pm.expect(tv4.validate(data1, schema)).to.be.true;
pm.expect(tv4.validate(data2, schema)).to.be.true;
});
```
test for APIs with specified annotationpostman.test[@com.itangcent.common.annotation.RequiredLogin]=```
pm.test("Body is correct", function () {
pm.response.to.have.body("response_body_string");
});
pm.test("Content-Type is present", function () {
pm.response.to.have.header("Content-Type");
});
pm.test("Response time is less than 200ms", function () {
pm.expect(pm.response.responseTime).to.be.below(200);
});
pm.test("Successful POST request", function () {
pm.expect(pm.response.code).to.be.oneOf([201,202]);
});
pm.test("Status code name has string", function () {
pm.response.to.have.status("Created");
});
var jsonObject = xml2Json(responseBody);
var schema = {
"items": {
"type": "boolean"
}
};
var data1 = [true, false];
var data2 = [true, 123];
pm.test('Schema is valid', function() {
pm.expect(tv4.validate(data1, schema)).to.be.true;
pm.expect(tv4.validate(data2, schema)).to.be.true;
});
```
test for APIs without specified annotationpostman.test[!@com.itangcent.common.annotation.Public]=```
pm.test("Body is correct", function () {
pm.response.to.have.body("response_body_string");
});
pm.test("Content-Type is present", function () {
pm.response.to.have.header("Content-Type");
});
pm.test("Response time is less than 200ms", function () {
pm.expect(pm.response.responseTime).to.be.below(200);
});
pm.test("Successful POST request", function () {
pm.expect(pm.response.code).to.be.oneOf([201,202]);
});
pm.test("Status code name has string", function () {
pm.response.to.have.status("Created");
});
var jsonObject = xml2Json(responseBody);
var schema = {
"items": {
"type": "boolean"
}
};
var data1 = [true, false];
var data2 = [true, 123];
pm.test('Schema is valid', function() {
pm.expect(tv4.validate(data1, schema)).to.be.true;
pm.expect(tv4.validate(data2, schema)).to.be.true;
});
```
test in the configuration and choose which one to use based on code commentspostman.test.groupA=```pm.test("Body is correct", function () {
pm.response.to.have.body("response_body_string");
});
```
postman.test.groupB=```
pm.test("Content-Type is present", function () {
pm.response.to.have.header("Content-Type");
});
```
postman.test.groupC=```
pm.test("Response time is less than 200ms", function () {
pm.expect(pm.response.responseTime).to.be.below(200);
});
```
postman.test.groupD=```
pm.test("Successful POST request", function () {
pm.expect(pm.response.code).to.be.oneOf([201,202]);
});
```
postman.test[#test]=groovy:config.get("postman.test."+it.doc("test"))
Usage:
/**
* Get a list of users
*
* @param type User type {@link com.itangcent.common.constant.UserType}
* @test groupA
*/
@RequestMapping(value = "/list", method = RequestMethod.GET)
public IResult list(Integer type) {
...
return Result.success(Collections.singletonList(userInfo));
}
Set test for the folder on the class.
Multiple rules are allowed.
The context is class.
Set test for the collection.
Multiple rules are allowed.
Note that collection.postman.test does not have a context, meaning it is null.