最佳答案
您可以通过验证退出代码以及程序到标准输出流和标准错误流的输出来进行黑盒测试。
您可以通过保留对应用程序的引用并在提供各种命令行输入后断言应用程序的状态来进行白盒测试。
例如:
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());
Update: the picocli user manual now has a separate section about Testing.
关于java - 测试 pico cli 命令,Java,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59661608/