Skip to content

0xPiyush/testify

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Testify

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.

Features

  • 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

Installation

go get github.com/0xPiyush/testify

Usage

1. Define Your Test Cases

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
      }
    ]
  }
]

2. Run the Tests

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()
}

Example

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.

Test Case Format

Each test case in tests.json consists of:

  • name: Identifier for the test case
  • compileCmd: (Optional) Command to compile the program
  • compileTimeout: (Optional) Maximum time allowed for compilation
  • runCmd: Command to run the program
  • runTimeout: Maximum time allowed for execution
  • lines: Array of input/output sequences
    • lineType: Either "input" or "output"
    • line: The actual content
    • endLine: Boolean to define if the line is a newline

License

[MIT License]

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published