Is it possible to write custom validation for tests?

A lot of validation can be done based on schema, and we’re currently evaluating APIDog for this.

There is more to testing however than just, does the API return the correct data structure.

For example, is it possible to test the validity of the content of a response? A really simple (and somewhat silly) example would be “is the returned timestamp recent?”.

This requirement can be implemented through a custom script approach. You can write a script to perform testing, similar to what you would do in Postman. This script can be set at the directory level, which will automatically take effect for all APIs within the directory.

Ah check, but also the post processors for example can include checks that can succeed and fail?

yes. tests can be written in scripts. the grammar is the same with postman tests.

ah thanks! sorry never worked with the pm scripts hence the questions (and couldn’t find anything in the docs).

maybe we need to optimize the documentation😅

oh wait, there’s actual assertions in there, sorry. I’m blind apparently :laughing:.

Yukio Ikeda thanks! I’m testing a couple of things, and most stuff is pretty easy to do with the assertions which is great! Is something I mentioned in the OP like checking whether a date is recent possible too? I mean in an assertion I can add a custom expression but it’s still doing an equals isn’t it? Or should I do something like extract the data into a unix epoch (it’s an ISO string date now) and do a less than or greater than check or something?

Also PM seems to include Moment.js for date manipulation but APIDog doesn’t?

PS some feedback on the docs, it might make sense to link or mention the Scripts segment of the Docs in the Automated Testing part. I was looking for testing functionality and it wasn’t clear to me that these preprocessors were available for testing.

Ignore the Moment.js remark, I need to require it it seems.

If you use the assertion, you can switch to the condition you need to use at the condition section, as shown in the screenshot. Maybe could solve your issue?


Your suggestion about docs makes a lot of sense! Perhaps we should add a description about the script under the chapter on test scenarios, or at the very least, a link.

Thanks Joe! They’re already up and running for a couple of endpoints. Looking good so far!