T
T
thewizardplusplus2016-06-24 16:15:28
Unit testing
thewizardplusplus, 2016-06-24 16:15:28

What tools are there for black box testing via stdin/stdout?

I need a tool to perform unit testing of the same program written in different languages. Writing test code for it every time in each of the languages, firstly, is long, and secondly, which is worse, is fraught with errors in the tests themselves. I need a guarantee that all versions of the program work identically, and if the tests are different, this cannot be guaranteed.
My idea is to make the tests in groups of:

  • program keys;
  • input data read by the program from stdin;
  • output written by the program to stdout.

For example, some tests for the wc utility:
[test of words]
options=-w
input=one two three
output=3

[test of characters]
options=-c
input=one two three
output=13

And calling these tests: Yes, I understand that writing the most similar utility is as easy as shelling pears. However, it is better to use an already existing, debugged and supported solution than to create another bicycle.
$ some-utility --tests=wc_tests.ini --command=wc

Answer the question

In order to leave comments, you need to log in

1 answer(s)
T
thewizardplusplus, 2016-06-26
@thewizardplusplus

Found this solution: Bats (Bash Automated Testing System) . It is a unit testing system for bash scripts and console utilities. Allows you to do what I wanted, as well as much more.
The example given in the question would look like this on Bats (test.bats file):

#!/usr/bin/env bats

@test "test of words" {
  result="`printf 'one two three' | wc -w`"
  
}

@test "test of characters" {
  result="`printf 'one two three' | wc -c`"
  
}

Run:
Output:
✓ test of words
✓ test of characters

2 tests, 0 failures

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question