/unit-test-stdin-stdout

A framework to unit / junit test a stdin stdout based program

Primary LanguageJavaApache License 2.0Apache-2.0

Unit testing a stdin / stdout based program

The class FakeApp implements a CLI program using stdin and stdout for all it's interaction with the user.

This is unit-tested via the code:

@Test
public void lineByLineTests() {

    try (TestCase testCase = TestCase.build()
            .input("add-user oli glimmer").expect("user added")
            .input("add-user heiner test").expect("user added")
            .input("list-users").expect("user:", "1,oli,glimmer", "2,heiner,test")
            .input("del-user 1").expect("user deleted")
            .input("list-users").expect("user:", "2,heiner,test")
            .input("quit")) {

        FakeApp.main(null);

    }
}

(as seen in class UnitTest).

If you think this isn't unit testing and more component or even end-to-end testing - fair enough.