您可以通过验证退出代码并将程序的输出验证为标准输出流和标准错误流来进行黑盒测试。
您可以通过保留对应用程序的引用并在为应用程序提供各种命令行输入后断言应用程序的状态来进行白盒测试。
例如:
MyApp app = new MyApp();
StringWriter sw = new StringWriter();
CommandLine cmd = new CommandLine(app);
cmd.setOut(new PrintWriter(sw));
// black box testing
int exitCode = cmd.execute("-x", "-y=123");
assertEquals(0, exitCode);
assertEquals("Your output is abc...", sw.toString());
// white box testing
assertEquals("expectedValue1", app.getState1());
assertEquals("expectedValue2", app.getState2());