CLI testing
SHAFT provides terminal, Docker, SSH, and file actions with the same reporting model used by browser and API tests.
Prerequisites
- A SHAFT Maven project. Install SHAFT walks through generating one.
- The command you test available to the user that runs Maven. For Docker actions, a running Docker daemon. For SSH actions, a reachable host, user, and key, with secrets injected by CI rather than committed.
Open the terminal actions reference for executable examples and result handling.
First useful command test
Use CLI actions when the product behavior depends on a process, file, Docker command, deployment script, or remote shell state. Start with a harmless local command and assert on the captured output:
SHAFT.CLI terminal = new SHAFT.CLI();
String output = terminal.performTerminalCommand("echo Hello SHAFT");
SHAFT.Validations.assertThat().object(output).contains("Hello SHAFT");
Run the test with Maven:
mvn test
The command, output, and validation status are attached to the same Allure evidence flow as the rest of the suite.
Verify
- Maven reports the test as run and passed.
- The Allure report shows the command, its captured output, and the
contains("Hello SHAFT")validation. - To prove the assertion is live, change the expected text and rerun. The validation fails with the captured output attached.
Troubleshooting
| Symptom | Check |
|---|---|
| Command works locally but fails in CI | Use absolute paths or set the working directory explicitly. |
| Docker command times out | Verify Docker is running before tuning command timeout properties. |
| SSH command cannot connect | Validate host, user, key, network route, and CI secret injection. |
| File assertion fails on Windows | Prefer forward slashes in Java paths; Java resolves them on Windows. |