我在这里疯了所以忍受我... 我们使用Fitnesse(使用DbFit框架/基于FIT)自动执行一些测试,我们在其中运行一些shell命令。我们有一个连接到linux服务器的fixture,运行命令并返回结果(见下文)
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;
}}
所以我希望在运行要返回的命令(作为字符串)后,在shell上显示任何内容,并与我在fitnesse中所需的测试进行比较。
Fitnesse捕获结果但总是无法比较,我不知道为什么(我只添加了sed命令来删除空格,但仍然比较失败!!
我觉得Fitnesse嘲笑我向我展示了预期,实际和差异的相同价值。 是和编码问题?这是一个java类型的问题吗?检查如何运作?
编辑:我甚至尝试两次运行shell命令并在第一次保存结果,然后将其设置为预期结果。它仍然失败。
|set | VarAddress | run command | cat AddressNoSpaces.txt |
|check| run command | cat AddressNoSpaces.txt | @{VarAddress} |
答案 0 :(得分:0)