2017-01-09 1 views
0

나는 미치겠다. 내게 곰이 ... Fitnesse (DbFit 프레임 워크/FIT 기반)를 사용하여 일부 셸 명령을 실행하는 일부 테스트를 자동화하고 있습니다. 우리는 리눅스 서버에 연결하는 고정이 명령을 실행하고 결과가 내가 기대하고있어 그래서DoFixture의 점검 기능은 입력으로 무엇을 기대합니까?

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; 
}} 

(우는 소리 참조) 반환 가지고 같은 어떤 GET의 반환 명령을 실행 한 후 쉘에 표시 (문자열) 및 fitnesse에서 내 테스트가 요구하는 것과 비교됩니다.

Fitnesse 결과를 잡는다하지만 항상 비교를 실패하고 (나는 단지 공백을 제거하는 SED 명령을 추가 한 이유는 모르겠지만, 여전히 비교 내가 Fitnesse 같은 느낌!

나를 조롱한다 실패 .? 나에게 예상, 실제와 DIFF에 대해 동일한 값을 보여주는 하면 인코딩 문제입니다 그것은 자바 유형의 문제 일을 확인 않습니다 어떻게

enter image description here

편집 :? 나는 시도조차 쉘 명령을 실행 두 번 결과를 처음으로 저장 한 다음 예상 된 결과. 그것은 여전히 ​​실패합니다.

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

확인 문제가 해결

enter image description here

+0

더 나아가, 나는 심지어 쉘 명령을 두 번 실행하여 결과를 변수에 처음 저장 한 다음 예상 결과로 설정하려고했습니다. IT가 여전히 실패! | 설정 | VarAddress | 명령 실행 | cat AddressNoSpaces.txt | | 수표 | 명령 실행 | cat AddressNoSpaces.txt | @ {VarAddress} | – tester

답변

0

, 쉘 명령 출력 fitnesse이 마음에 들지 않은 새 라인 문자를 추가 한 것으로 보인다. 그 자바 클래스에서 반환 값을 제거하기 위해 마지막 숯을 변경하고 작동합니다.