Typescript Templates
Although you can write test templates in Javascript, we highly recommend writing your templates in Typescript to make everything more seamless.
A Test Template has 3 Components:
- name - A name for your template
- version - The version for your template
- builder - A function that takes an endpoint and returns a TestBuilder
It’s structured like this in typescript:
Builder
A builder is a function that takes an endpoint of type GenTestEndpoint.
You can use this endpoint to generate a test with the TestBuilder class inside the function.
TestBuilder
Think of the test builder class as building up a YAML test file piece by piece by chaining the following functions:
setMeta
- Adding Metadata
Use this function to add any metadata related to your test, generally you would want to add a name and severity.
addToEnv
- Adding Environment Variables
Add any environment variables you want to use later in your test.
addTestStep
- Adding a Test Step
Use this function to add each request, along with its extractors and and assertions.
TestStepBuilder
The TestStepBuilder
builds a request along with its assertions and extractors. You instantiate a test step builder with the request that you want to create:
You can also autogenerate a request using the endpoint using:
There are many cases where you would want to generate a sample request without any authentication:
After that you can chain the following functions to create your step:
assert
- Add an Assertion
Use this function to add an assertion to your test step.
extract
- Add an Extractor
Use this function to add an extractor to your test step.