使用 Jenkins 测试自动化 +机器人框架

发布于 2024-12-14 13:55:15 字数 540 浏览 1 评论 0 原文

经过长时间的互联网搜索,我想问您以下问题。

我们使用 Jenkins 来构建和单元测试用 C++ 编写的模拟代码。

这非常有效。在研究了 Fitnesse 和 RobotFramework 之后,我仍然无法运行以下测试问题。

我的程序是一个命令行程序,它读取一些输入文件并计算一些输出数据。 (例如 simcode.exe -j input##.inp --> output.dat)

我正在寻找一种可以通过 Web 界面创建测试套件的方法。这意味着我为每个测试用例提供一个输入文件和一些参考输出数据,然后在成功构建 Jenkins 后执行测试套件。根据输出数据和参考输出数据之间的差异结果,应创建一个可提供给 Jenkins 的 xml 文件。此 xml 文件应包含有关所有测试用例结果的信息(例如成功或失败)。

xml文件的信息应该会再次显示在Jenkins中。

我正在寻找一种不需要将任何库编译到我的程序中的方法。

我将非常感谢任何解释如何使用 RobotFramework 实现这一目标的提示。 (这可能吗?)

提前致谢!

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!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

时常饿 2024-12-21 13:55:15

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

我不太明白您通过 Web 界面使用测试套件的意思...但总的来说,您描述的功能似乎是可以使用 RobotFramework 完成...

简而言之,

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

操作系统内置库有关键字 Run,您可以使用它,或者如果您远程运行命令,您可以使用可选 SSHLibrary

对于每个测试用例您可以创建一个运行该命令的步骤,以及另一个根据您的预期验证输出文件的步骤。如果它们匹配,则测试用例被标记为“通过”,否则被标记为“失败”...

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

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

Robot Framework is a test automation tool... you can do many different things with that...

I don't really understand what you mean with the test suite via a web interface... but in general the functionality you describe seems that can be done with RobotFramework...

In Brief

You can create a Test Suite that can have many Test Cases for example you could have onef or every input file you want to check!

The OperatingSystem Build In Library has the Keyword Run, that you can probably use or if you are running the commands remotely you can use the Execute Command from the optional SSHLibrary

For Every Test Case you could create a step that runs the command and another one that verifies the output file against what you expected. If they match the Test Case is marked as Pass, else it is marked as Fail...

RobotFramework can produce for every Test Suite that you run a log and report file that are in html format.

Jenkins and Hudson have a plugin for RobotFramework that you can use to display these output files in a very nice way!
i.e. How many Test Cases have Passed/Failed

泪冰清 2024-12-21 13:55:15

你想要的似乎是灵丹妙药。
这是可行的,你不需要编译任何东西,但你仍然需要围绕机器人框架编写一些逻辑。

  1. 据我了解,您需要在 CLI 中调用某些内容 - 这是微不足道的,机器人已经做到了这一点
  2. 它有一个输入文件和一些输出数据 - 微不足道的, - 机器人已经做到了这一点
  3. 您需要将实际输出数据与预期输出进行比较数据——这里你需要一些苦劳。
  4. 打包日志 - 机器人已经这样做了。
  5. 将它们呈现在 Jenkins 中 - 微不足道 - 机器人已经做到了这一点。

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

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

    <前><代码>*** 设置 ***
    图书馆操作系统

    *** 测试用例 ***
    基础测试
    运行命令 simcode.exe -j input01.inp

    *** 关键词 ***
    运行命令
    [参数] ${命令}
    ${rc} ${output} = 运行并返回 RC 和输出 ${command}
    记录${输出}
    应等于整数 ${rc} 0

    不应包含 ${output} 失败

  2. 如果您想要一种灵活的方法来输入内容

    <前><代码>*** 设置 ***
    图书馆操作系统

    *** 测试用例 ***
    组合
    [模板] 基本测试
    输入01.inp
    输入02.inp
    输入03.inp

    *** 关键词 ***
    基础测试
    [参数] ${输入}
    运行命令 simcode.exe -j ${input}

    运行命令
    [参数] ${命令}
    ${rc} ${output} = 运行并返回 RC 和输出 ${command}
    记录${输出}
    应等于整数 ${rc} 0

    不应包含 ${output} 失败

  3. 接下来,我们需要比较两个文件的内容......
    假设您将文件移动到一个方便的位置,您可以自己编写一个关键字来比较内容

    <前><代码>*** 设置 ***
    图书馆操作系统

    *** 测试用例 ***
    组合
    [模板] 基本测试
    ../资源/input01.inp ../资源/expectedoutput01.out
    ../资源/input02.inp ../资源/expectedoutput02.out
    ../资源/input03.inp ../资源/expectedoutput03.out

    *** 关键词 ***
    基础测试
    [参数] ${输入} ${expected_output}
    运行命令 simcode.exe -j ${input}
    日志文件输出.data
    比较文件 ${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。运行后,您可以使用发布工件和发布机器人结果插件来传递詹金斯的格式良好的输出。

瞧!

PS:代码可能无法运行 - 我在一个简单的编辑器中自由编写了它,没有语法突出显示,并且我没有测试它。

What you want seems like a silver bullet.
It is feasible, you don't need to compile a thing, but you still need to write some logic around robot framework.

  1. As far as I understood you need to call something in CLI - this is trivial, robot already does this
  2. It has an input file and some output data - trivial, - robot already does this
  3. You need to compare the actual output data with the expected output data - here you need some elbow grease.
  4. Package the logs - robot already does this.
  5. Present them in Jenkins - trivial - robot already does this.

So all the heavy lifting is already done.

  1. Calling CLI - use OperatingSystem

    *** 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. If you want a flexible approach to inputting stuff

    *** 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. Next, we need to compare the content of two files...
      Assuming that you moved your files around to a convenient location you can write yourself a keyword to compare the content

      *** 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
      

Let's assume that the content is a list of parameters, in the ini format.
For example let's assume that you calculate the square root for the numbers present in the input file

How do we store the expected data?
Let's assume we have a file called expected.dat

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

And we have an output.data

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

Then we need to write ourselves a file comparator.
Either you go with diff and the OperatingSystem library, if you are confident that the files should be identical or you can write a simple comparator like:

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 and 5. After you run, you use the publish artefact and publish robot results plugins to pass the nicely formatted output to Jenkins.

Voila!

PS: The code might not run - I wrote it freestyle in a simple editor without syntax highlighting and I did not tested it.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文