Testify is a Go-based testing framework designed to automate testing of interactive CLI applications. It provides a simple way to define input/output test scenarios using JSON and execute them against your CLI applications.
- Test interactive CLI applications with defined input/output sequences
- JSON-based test case definitions
- Support for compile and run commands
- Configurable timeouts for both compilation and execution
- Detailed test results output
go get github.com/0xPiyush/testify
Create a tests.json
file with your test cases. Each test case should specify:
- Name of the test
- Run command
- Sequence of input/output lines
Example tests.json
:
[
{
"name": "Test Case Name",
"runCmd": "python your_script.py",
"runTimeout": 10000,
"lines": [
{
"lineType": "output",
"line": "Expected output",
"endLine": true
},
{
"lineType": "input",
"line": "User input",
"endLine": true
}
]
}
]
package main
import (
testrunner "github.com/0xPiyush/testify/TestRunner"
"github.com/0xPiyush/testify/models"
)
func main() {
tests, _ := models.ParseTestCases("./tests.json")
config := testrunner.TestRunnerConfig{
UseTempEnv: true,
PreserveTempEnv: false,
}
runner := testrunner.New(config, tests)
results, _ := runner.RunAll()
}
The repository includes an example interactive Python script (test.py
) and its corresponding test cases in tests.json
.
The example Python script prompts for a user's first and last name, then performs a simulated long-running task:
# test.py
fname = input("Enter your first name: ")
lname = input("Enter your last name: ")
print(f"Hello, {fname} {lname}!")
The corresponding test cases in tests.json
verify different name combinations and the expected output.
Each test case in tests.json
consists of:
name
: Identifier for the test casecompileCmd
: (Optional) Command to compile the programcompileTimeout
: (Optional) Maximum time allowed for compilationrunCmd
: Command to run the programrunTimeout
: Maximum time allowed for executionlines
: Array of input/output sequenceslineType
: Either "input" or "output"line
: The actual contentendLine
: Boolean to define if the line is a newline
[MIT License]
Contributions are welcome! Please feel free to submit a Pull Request.