Test Case
| Definition | The fundamental unit representing a single test scenario that can be executed independently. It consists of either a .http file with optional supporting scripts (multi-file format) or a .tp file (single-file format) that define setup, execution, and validation of API tests. Test cases can be grouped into a collection. |
| Purpose | Encapsulates a single test scenario (not only) for isolated execution. |
| Example Usage | Request File of a Complete Test Case |
Structure
Request File
Each test case is represented by a .http file, referred to as the Request File.
It must contain at least one HTTP request, following these conventions.
Optional Scripts
For more complex test cases, these additional scripts can be included:
- Pre-Request Script – A
.csxscript for data setup and initialization before executing HTTP requests. - Post-Response Script – A
.csxscript for validating API responses and performing assertions - testing.
Additional Optional Files
When running a test case, you can also reference:
- Environment File – Defines environmental variables.
- Initialization Script – Runs before executing the test case.
Alternative: Single-File Format (.tp)
TeaPie supports two equivalent ways to define test cases. Use whichever fits your project better.
The Single-File Format (.tp) combines HTTP requests and C# scripts in one file using section markers. It is an optional alternative to the multi-file format. Both formats are fully supported and can co-exist in the same project; choose based on test case complexity and how you prefer to structure tests.
Running a Test Case
To execute a test case, run:
teapie <path-to-request-file>
To try it out, you can run a test case from the demo collection.
The following examples demonstrate both formats:
# Multi-file format
teapie "./Tests/002-Cars/002-Edit-Car-req.http"
# Single-file format (.tp)
teapie "./Tests/002-Cars/004-Car-Operations.tp"
For advanced usage, here’s the full command specification:
teapie test <path-to-test-case> [--temp-path <path-to-temporary-folder>] [-d|--debug] [-v|--verbose] [-q|--quiet] [--log-level <minimal-log-level>] [--log-file <path-to-log-file>] [--log-file-log-level <minimal-log-level-for-log-file>] [-e|--env|--environment <environment-name>] [--env-file|--environment-file <path-to-environment-file>] [-r|--report-file <path-to-report-file>] [-i|--init-script|--initialization-script <path-to-initialization-script>] [--no-cache-vars|--no-cache-variables]
💡 Tip: You can use the alias
tor omit the command name entirely, sincetestis the default command when launching TeaPie.
To view detailed information about each argument and option, run:
teapie --help
Scaffolding
To create a new test case, use:
teapie generate <test-case-name> [path] [-i|--init|--pre-request] [-t|--test|--post-response]
💡 Shortcut: You can use aliases
genorginstead ofgenerate.
This command generates the multi-file format in the specified path (or the current directory if no path is provided):
- Pre-Request Script:
<test-case-name>-init.csx - Request File:
<test-case-name>-req.http - Post-Response Script:
<test-case-name>-test.csx
To disable pre-request or post-response script generation, set the -i and -t options to false.
To generate a single-file test case (.tp) instead, use the --single-file (or -s) flag:
teapie generate <test-case-name> [path] -s [-i] [-t]
This creates a <test-case-name>.tp file with --- HTTP section (and --- INIT/--- TEST if -i/-t are set). See Single-File Format (.tp) for details.
Exploring Test Case Structure
To inspect the structure of a test case without executing it, run:
teapie explore <path-to-test-case> [-d|--debug] [-v|--verbose] [-q|--quiet] [--log-level <minimal-log-level>] [--log-file <path-to-log-file>] [--log-file-log-level <minimal-log-level-for-log-file>] [--env-file|--environment-file <path-to-environment-file>] [-i|--init-script|--initialization-script <path-to-initialization-script>]
The path can point to a request file (.http) or a single-file test case (.tp).
💡 Shortcut: You can use aliases
exporeinstead ofexplore.