为Go CLI编写集成测试,询问Windows的一系列问题/答案

时间:2018-12-18 00:13:37

标签: go lua command-line-interface

我有一个用Golang开发的Windows命令行应用程序(通过命令行询问一系列问题),我想为此应用程序编写集成测试。我看着https://github.com/zetamatta/expect。它可以模拟每个问题的输出。示例:

expect("Enter installer name")
send("xxx\r")
expect("Execute it?")
send("y\r")
..
..
..

golang应用程序根据提出的各种问题及其答案进行一些处理。它确实安装了一些东西。如果我要使用此软件包编写集成测试,它如何表明是通过测试还是失败测试?

我的lua脚本如下:

echo(true)
if spawn([[C:\test.exe]]) then
    expect("Enter installer name?")
    echo(true)
    send("xxx\r")
    expect("Install it?")
    send("y\r")
    expect("~]$")
    echo(true)
    send("exit\r")
end

我执行为:

expect.exe sample.lua

它可以正常工作,并自动接受以上输入的问题,而无需手动输入任何内容。但是,最后,我该如何组织它作为测试,以显示一切都成功或失败。最终,我需要针对所有可能和负面的情况编写一些测试。

0 个答案:

没有答案