Your First Test
Let's write a real test that spins up an Nginx server and verifies it responds with a 200. The whole thing takes about a minute.
Create a test file
Create a file called tests/hello.spark:
name: Hello World
tests:
- name: Nginx responds with 200
services:
- name: web
image: nginx:alpine
healthcheck:
test: "wget -q --spider http://localhost:80/"
retries: 30
execution:
executor: http
target: http://web
request:
method: GET
url: /
assertions:
- statusCode:
equals: 200
What's going on here? You're defining a test suite called "Hello World" with one test. That test starts an Nginx container, sends a GET request to its root URL, and checks that the status code is 200. The
name: web in the service definition becomes the hostname — that's why the target is http://web.Run it
spark run ./tests
Spark will:
- Find all
*.sparkfiles in./tests - Start an Nginx container in an isolated Docker network
- Wait for the health check to pass (retries up to 30 times)
- Send
GET /to the Nginx container - Assert the response status code is
200 - Clean up all containers and networks
You should see output like this:
✓ Nginx responds with 200 ........... 1.2s
1 passed (1.2s)
Generate an HTML report
spark run ./tests --html ./reports
Open reports/index.html in your browser. You'll see a dashboard with timing breakdowns, logs, and assertion results for every test. This is especially useful when you have dozens of tests running in CI.
Next up: Learn how to filter tests, run in parallel, and generate CI reports.