Writing Your First Test
Writing your first test with Condor involves setting up a directory structure, initializing a collection, defining resources, and writing assertions to validate behavior. Follow these steps to get started:
Typical Directory Structure
A Condor collection is typically organized as follows:
Directorycollection
Directoryenvironments
- production.condor
Directoryresources
Directoryusers
- get_user.condor
Directoryblog
- get_blog.condor
Directorytests
Directorye2e
- users.condor
Directoryload
- baseline.condor
environments/
: Contains environment-specific configurations (e.g.,base_url
).resources/
: Defines reusable resources such as HTTP requests.tests/
: Contains test files organized by type (e.g., E2E, load, security).
Step 1: Initialize a New Collection
To set up this structure in your codebase, use the condor init
command:
condor init collection/
This creates a basic directory structure under collection/
with empty files and folders. You can modify and expand it as needed.
Step 2: Define a Resource
Create an HTTP resource that represents the service endpoint you want to test. For example, add the following to collection/resources/users/get_user.condor
:
http "get_user" { method = "get" path = "/user/${var.id}"
headers { Authorization = "Bearer ${var.auth_token}" }
query { expand = "details" }}
Explanation:
method
: HTTP method (GET
,POST
, etc.).path
: Endpoint path, supporting placeholders like{id}
.headers
: Configurable headers, such asAuthorization
.query
: Optional query parameters.
Step 3: Write a Test
Create a test file under collection/tests/e2e/users_test.condor
to validate the endpoint:
test "get_user" { name = "Fetch user details" request = http.get_user
variables { auth_token = "your-auth-token" id = "12345" }
assert { condition = resp.status == 200 error = "Expected status 200, got ${resp.status}." }
assert { condition = json::decode(resp.body).name != "" error = "Expected a non-empty name in the response." }}
Explanation:
request
: Refers to thehttp
resource.variables
: Defines dynamic values such asauth_token
andid
.assert
: Adds conditions to validate the response.
Step 4: Run the Test
Run your test using the Condor CLI:
condor run collection/tests/e2e/users_test.condor
Condor will execute the test and display the results in your terminal.
Next Steps
- Explore advanced testing capabilities, such as parameterized tests and CI/CD integration.
- Review the Examples & Templates for inspiration on organizing your tests.