【问题标题】:What does the DoFixture's check function expect as input?DoFixture 的检查功能期望输入什么?
【发布时间】:2017-01-09 08:30:34
【问题描述】:

我在这里发疯了,所以请耐心等待... 我们正在使用 Fitnesse(使用 DbFit 框架/基于 FIT)来自动化一些运行一些 shell 命令的测试。我们有一个连接到 linux 服务器的夹具,运行命令并返回结果(见下文)

class SSHConnection {

private static final String DEFAULT_KEY = "~/.ssh/id_rsa";
private String host;
private String password;
private int port;
private String privateKey;
private Session session;
private String user;

/** Creates a JSch object and open a connection with a remote server using the values set in the class variables.
 */
public void connect() {.........}


/**
 * Executes a command in the remote server using the connection opened by connect().
 * @param command command to execute in the remote server
 * @return the output result of the command as String
 */
public String execute(String command) {
    logger.info("Executing command: " + command);

    String result;

    try {
        ChannelExec channelExec = (ChannelExec) session.openChannel("exec");
        channelExec.setCommand(command);

        // Open exec channel
        channelExec.connect();

        InputStream stream = channelExec.getInputStream();
        BufferedReader reader = new BufferedReader(new InputStreamReader(stream));

        StringBuilder output = new StringBuilder();

        String line;
        while ((line = reader.readLine()) != null) {
            output.append(line).append("\n");
        }

        result = output.toString();

        // Close exec channel
        channelExec.disconnect();

        logger.debug("Command executed successfully: " + result);

    } catch (JSchException | IOException e) {
        logger.error("Error executing command: " + e.getMessage());
        e.printStackTrace();
        return "";
    }
    return result;
}}

所以我希望在运行命令后返回(作为字符串)并与我在 Fitnesse 中的测试所需的任何内容进行比较后,shell 上显示的任何内容。

Fitnesse 捕捉到结果但总是比较失败,我不知道为什么(我只添加了 sed 命令来删除空格,但仍然比较失败!!

我觉得 Fitnesse 是在嘲笑我,向我展示了预期、实际和差异的相同值。 是和编码问题吗?是java类型的问题吗?检查是如何工作的?

编辑:我什至尝试运行两次 shell 命令并第一次保存结果,然后将其设置为预期结果。它仍然失败。

 |set | VarAddress | run command | cat AddressNoSpaces.txt |
 |check| run command | cat AddressNoSpaces.txt | @{VarAddress} |

【问题讨论】:

  • 此外,我什至尝试两次运行 shell 命令,第一次将结果保存在变量中,然后将其设置为预期结果。它仍然失败! |设置 |变量地址 |运行命令 | cat AddressNoSpaces.txt | |检查|运行命令 | cat AddressNoSpaces.txt | @{VarAddress} |

标签: fitnesse dbfit


【解决方案1】:

OK 问题解决了,似乎 shell 命令输出添加了一个新的 line char,fitnesse 不喜欢。我更改了该 java 类以从它的最后一个字符中删除返回值并且它正在工作。

【讨论】:

    猜你喜欢
    • 2015-02-28
    • 2020-04-07
    • 2020-06-20
    • 2017-06-08
    • 2015-08-29
    • 1970-01-01
    • 1970-01-01
    • 2018-10-10
    • 1970-01-01
    相关资源
    最近更新 更多