Automated Testing
instruqt lab test plays a lab for you. It starts a real session and works through the lab the way a user would: it opens every page, checks and solves every task, and answers every quiz from the answers in the lab’s own configuration. It stops at the first thing that misbehaves and exits non-zero, so you can run it by hand before sharing a lab or in CI on every change.
Unlike instruqt lab validate, which reads your HCL on disk, this runs the lab on the platform. It tests the version the platform has, not the files in your working directory.
Prerequisites
Section titled “Prerequisites”- The Instruqt CLI installed
- Authentication:
instruqt auth login, orINSTRUQT_TOKENfor CI - A lab on the platform, synced from your repository
The lab command group does not appear in root instruqt --help, but the subcommands work when you invoke them as instruqt lab ….
Run a test
Section titled “Run a test”# A lab in your configured teaminstruqt lab test my-first-lab
# A lab in another teaminstruqt lab test acmecorp/my-first-labWith a bare lab slug, the team is the one you chose at instruqt auth login. Pass <team>/<lab> to test a lab in any team you have access to.
Interrupting the CLI with Ctrl-C stops the CLI, not the run. The run finishes on the platform and stops its own session, and the command prints the session and run IDs so you can follow it with instruqt lab logs.
What a run does
Section titled “What a run does”A run starts a session of your lab, waits for the sandbox to come up, and loads the lab. Then it works through the content from the first page to the last, doing what a user would do:
- Opens each page, and confirms the running lab has the tasks and quizzes your configuration says belong there.
- Checks each task before solving it. The check is expected to fail here.
- Solves each task, which runs its solve scripts and unlocks whatever comes next.
- Answers each quiz using the answers in your configuration.
When it reaches the end — or stops early because something misbehaved — it shuts the session down.
Reading the report
Section titled “Reading the report”The run reports each step as it happens. In a terminal, the step in progress shows a spinner, which is replaced by its result when the step finishes.
instruqt lab test acmecorp/http-basics==> Testing lab: acmecorp/http-basicsStarting session OK session hfwc8re245hcWaiting for sandbox OK 2m3sLoading lab OKMaking HTTP Requests and Reading Headers with curlPage 1 of 4: Send a GET RequestVisiting page OKChecking task "fetch-homepage" OKSolving task "fetch-homepage" OKPage 2 of 4: Inspect Response HeadersVisiting page OKChecking task "save-headers" OKSolving task "save-headers" OKAnswering quiz "header-knowledge-check" OK==> Lab test passed4 pages, 4 tasks, 2 quizzes in 2m13s
- Chapters and pages are the titles a user sees, and tasks and quizzes are named as you named them in your configuration.
- The session ID appears next to the step that created it. Use it with
instruqt lab logs --sessionwhile the run is going or after it ends. - A step that takes longer than a few seconds shows how long it took.
- When output is not a terminal — a pipe, a CI log — each line is printed once, when the step finishes, with no spinner and no redrawing.
Testing a branch
Section titled “Testing a branch”By default the run tests the lab’s default branch. Point it at another branch or a tag with --ref:
instruqt lab test my-first-lab --ref my-feature-branchWhen a test fails
Section titled “When a test fails”The failing step is the last line of the report, with the reason underneath it. The command exits 1.
instruqt lab test acmecorp/http-basics==> Testing lab: acmecorp/http-basicsStarting session OK session warhjw01eg4gWaiting for sandbox OK 1m53sLoading lab OKYour First curl RequestPage 1 of 4: Send a GET RequestVisiting page OKChecking task "fetch-homepage" OKSolving task "fetch-homepage" FAILits solve scripts failed: cannot reach the target server[ERROR] Solving task "fetch-homepage" on Send a GET Request: its solve scripts failed: cannot reach the target serverLogs: instruqt lab logs --session warhjw01eg4gRun: labtest-0eb8931f-b4c5-473e-8d82-7395f0712f5a
The message under the failing step is what the lab itself reported, so start there. For anything a script printed, follow the session ID into lab logs.
Running in CI
Section titled “Running in CI”Set INSTRUQT_TOKEN in the environment and run the command; the exit code is the result.
instruqt lab test acmecorp/http-basics --ref "$GIT_BRANCH"- Exit
0when the run passed,1when it failed or could not start. - Output has no spinner or escape sequences when stdout is not a terminal.
- A run takes as long as the lab does — mostly the sandbox coming up — so allow several minutes.
What it does not test
Section titled “What it does not test”- That a check can pass. The check runs only before the task is solved, and solving marks the task done without running the check again. A check that can never pass is not caught.
- That a wrong answer is rejected. Quizzes are only ever answered correctly.
- Cleanup scripts, and anything that only happens when a user does something unexpected.
- Your local files. The run tests what the platform has for the branch or tag you named. Push your changes first.
Related
Section titled “Related”- Testing & Validation — format, validate, and read lab logs
- Interactive Tasks — check and solve scripts
- Task reference — task and condition configuration
- Quiz reference — quiz and question configuration
