Skip to content

πŸš€ [NEW] Support for .tp Files (Combining Init, HTTP, and Test Files into One)Β #64

@Burgyn

Description

@Burgyn

🫴 Proposal

Addition of new .tp file format for defining test cases combining init script, http requests, and test script.

Structure:

Introduce a new .tp file format, where one file can contain multiple test cases. Each test case can have the following sections:

  • ### TESTCASE <Name>: starts a new test case.
  • ### INIT: optional section for initialization scripts.
  • ### HTTP: mandatory section for defining HTTP requests.
  • ### TEST: optional section for writing validation scripts.
  • ### END: marks the end of a test case.

Each section belongs only to the current test case. HTTP section is the only mandatory one. Multiple test cases can be placed within the same .tp file by repeating these section markers.

Example of one .tp file:

### TESTCASE Add New Car

### INIT
#load "$teapie/Definitions/GenerateNewCar.csx"
var car = GenerateCar();
tp.SetVariable("NewCar", car.ToJsonString(), "cars");

### HTTP
# @name AddCarRequest
POST {{ApiBaseUrl}}{{ApiCarsSection}}
Content-Type: application/json

{{NewCar}}

# @name GetNewCarRequest
GET {{ApiBaseUrl}}{{ApiCarsSection}}/{{AddCarRequest.request.body.$.Id}}

### TEST
tp.Test("Status code should be 201", () => {
    Equal(201, tp.Responses["AddCarRequest"].StatusCode());
});

### END

### TESTCASE Health Check

### HTTP
GET {{ApiBaseUrl}}/health

### END

✨ Motivation

Currently, test cases are spread into multiple files (-init.csx, -req.http, -test.csx). For simple test cases this feels unnecessary and makes the setup more verbose than needed.
Introducing a single-file format would:

  • Speed up development of small and simple test cases.
  • Reduce cognitive overhead when navigating between test scripts.
  • Improve maintainability when multiple related tests live together.

Make structure of tests more explicit and easier to read.

πŸ”€ Alternatives

Keep the current system where test cases are separated into multiple files.
Introduce different markup (e.g. markdown format, ...).

πŸ’‘ Possible implementation

The implementation should not be a big obstacle in this one. What is definitely needed is:

  • Update structure explorer(s) to consider .tp files as base of the test case similarly to how .http files are recognized now.
  • Update TestCase and TestCaseExecutionContext allowing them to be represented also by .tp files
  • Add new step ParseTestCaseFileStep, which will be automatically generated within InitializeTestCaseStep for each test case represented by .tp file. This step would work with new TestCaseParser, which will be able to divide this special file into one or more related files (pre-request, request, post-response file) to support current structure. From this point, all the following steps should work as nothing changed.

βž• Additional context

This new .tp format is meant to complement, not fully replace the current system.
More complex test cases can still be organized into multiple dedicated files when needed.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requestproposalProposal of some functionality

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions