3

after a long Internet search I would like to ask you the following question.

We are using Jenkins for building and unit testing of a simulation code which is written in C++.

This works very well. After looking into fitnesse and robotframework I am still not able to run the following test problems.

My program is a command line program which reads some input file and computes some output data. (e.g. simcode.exe -j input##.inp --> output.dat)

I am looking for a way that I can create a test suite via a web interface. Meaning I provide for each test case a input file and some reference output data and the test suite is than executed after a successful build out of Jenkins. Based on the results of the difference between output data and reference output data, a xml file should be created which can be given to Jenkins. This xml file should hold information about all the test case results (e.g. successful or not).

The information of the xml file should be displayed in Jenkins again.

I looking for an approach where I do not need to compile any library to my program.

I would be very thankful for any hint which explains how to achieve that with the RobotFramework. (Is it even possible ?)

Thanks in advance!

4

2 回答 2

1

Robot Framework 是一个测试自动化工具……你可以用它做很多不同的事情……

我真的不明白你通过网络界面对测试套件的意思......但总的来说,你描述的功能似乎可以用 RobotFramework 来完成......

简单来说

您可以创建一个可以包含许多测试用例的测试套件,例如您可以拥有一个或每个要检查的输入文件!

OperatingSystem Build In Library有关键字 Run,您可能可以使用它,或者如果您正在远程运行命令,您可以使用可选 SSHLibrary 中的Execute命令

对于每个测试用例,您可以创建一个运行命令的步骤和另一个验证输出文件是否符合您预期的步骤。如果它们匹配,则将测试用例标记为通过,否则将其标记为失败...

RobotFramework 可以为您运行的每个测试套件生成 html 格式的日志和报告文件。

Jenkins 和 Hudson 有一个 RobotFramework 插件,您可以使用它以非常好的方式显示这些输出文件!即有多少测试用例通过/失败

于 2011-11-11T17:11:03.120 回答
0

你想要的似乎是一颗银弹。这是可行的,你不需要编译一个东西,但你仍然需要围绕机器人框架编写一些逻辑。

  1. 据我了解,您需要在 CLI 中调用一些东西 - 这很简单,机器人已经这样做了
  2. 它有一个输入文件和一些输出数据 - 微不足道, - 机器人已经这样做了
  3. 您需要将实际输出数据与预期输出数据进行比较 - 在​​这里您需要一些麻烦。
  4. 打包日志 - 机器人已经这样做了。
  5. 在 Jenkins 中展示它们 - 微不足道 - 机器人已经这样做了。

所以所有繁重的工作已经完成。

  1. 调用 CLI - 使用操作系统

    *** Settings ***
     Library  OperatingSystem
    
    *** Test Cases ***
    Basic test
        Run Me A Command  simcode.exe -j input01.inp
    
    *** keywords ***
    Run Me A Command 
        [Arguments]  ${command} 
        ${rc}   ${output} =     Run and Return RC and Output    ${command}
        Log  ${output}
        Should Be Equal As Integers  ${rc}  0   
    
        Should Not Contain  ${output}  FAIL
    
  2. 如果您想要一种灵活的方法来输入内容

    *** settings ***
    Library  OperatingSystem
    
    *** Test Cases ***
    Combinations
        [Template]  Basic test
        input01.inp
        input02.inp
        input03.inp
    
    *** keywords ***
    Basic test
        [Arguments]  ${input}
        Run Me A Command  simcode.exe -j ${input}
    
    
    Run Me A Command 
        [Arguments]  ${command} 
        ${rc}   ${output} =     Run and Return RC and Output    ${command}
       Log  ${output}
       Should Be Equal As Integers  ${rc}  0    
    
        Should Not Contain  ${output}  FAIL
    
    1. 接下来,我们需要比较两个文件的内容...假设您将文件移动到一个方便的位置,您可以给自己写一个关键字来比较内容

      *** settings ***
      Library  OperatingSystem
      
      *** Test Cases ***
      Combinations
          [Template]  Basic test
          ../resources/input01.inp  ../resources/expectedoutput01.out
          ../resources/input02.inp  ../resources/expectedoutput02.out
          ../resources/input03.inp  ../resources/expectedoutput03.out
      
      *** keywords ***
      Basic test
          [Arguments]  ${input}  ${expected_output}
          Run Me A Command  simcode.exe -j ${input}
          Log File  output.data
          Compare Files  ${expected_output}  output.data
      

假设内容是 ini 格式的参数列表。例如,假设您计算输入文件中存在的数字的平方根

我们如何存储预期的数据?假设我们有一个名为 expected.dat 的文件

[defaults]
n_1=1
n_4=2
n_9=3

我们有一个 output.data

[defaults]
n_1=1
n_4=2
n_9=2

然后我们需要给自己写一个文件比较器。如果您确信文件应该相同,或者您可以使用 diff 和 OperatingSystem 库,或者您可以编写一个简单的比较器,例如:

def get_param(self,theFile)
    config = ConfigParser.RawConfigParser()
    config.read(theFile)
    return config.items("defaults")


def compareMyDict(self, expected, actual):  #There are better ways of doing this 
    for k, v in actual:
        if v != expected[k]:
            print("error message")
            print(k)
            print(v)
            print(expected[v])
            #print whatever you deem fit
            return
        print("Matched OK " + str(k))
        print(k)
        print(v)
        print(expected[v])

def compare_files(self, expectedFile, actualFile):
    '''
    From sourceFile formatted
    [defaults]
    key=value
    '''

    d1 = get_param(expectedFile)
    d1 = get_param(actualFile)

    compareMyDict(d1,d2)
    checkLenghts(d1,d2)
    criteria2(d1,d2)    
    #etc.

4 和 5. 运行后,您使用发布工件和发布机器人结果插件将格式良好的输出传递给 Jenkins。

瞧!

PS:代码可能无法运行——我在一个没有语法高亮的简单编辑器中自由地编写了它,我没有测试它。

于 2015-04-20T11:31:59.940 回答