1

自动化测试的执行策略

绝大多数集成/系统测试框架都支持失败重运行的执行策略,从实现上来讲,大概分为2类:

  1. 就地重运行失败测试用例
  2. 执行完后,重新运行所有失败的测试用例

比如TestNG框架支持上述两种执行策略,pytest框架通过rerunfailures插件支持第1种执行策略。RF的rerunfailed参数支持第2种执行策略

RF的rerunfailed执行策略

RF的rerunfailed可以从第一次跑过的结果中,筛选出失败的用例重新执行,结合rebot的--merge功能,可以重新输出output.xml,在Jenkins上展示出最后的测试结果。

\> pybot
-R --rerunfailed output Select failed tests from an earlier output file to be re-executed. Equivalent to selecting same tests individually using --test option.

\> rebot
-R --merge When combining results, merge outputs together instead of putting them under a new top level suite. Example: rebot --merge orig.xml rerun.xml

与Jenkins结合使用(windows)

  1. Jenkins中添加构建步骤:Execute Windows batch command
  2. rfrerun mysuite.robot

与Jenkins结合使用(Linux)

Linux下shell脚本rfrerun

#!/bin/bash
rm -f output/output.xml
rm -f output/rerun.xml
rm -f output/first_run_log.html
rm -f output/second_run_log.html

echo
echo "#######################################"
echo "# First Run                                #"
echo "#######################################"
echo
pybot --outputdir output $@

#  Stop the script here if all the tests were OK
if [ $? -eq 0 ]; then
    exit 0  
fi

# backup the first log file
cp output/log.html  output/first_run_log.html

echo
echo "#######################################"
echo "# Rerun  Failed Tests      #"
echo "#######################################"
echo
pybot --outputdir output --nostatusrc --rerunfailed output/output.xml --output rerun.xml $@

# backup the second log file
cp output/log.html  output/second_run_log.html

echo
echo "########################"
echo "# Merge output files #"
echo "########################"
echo
rebot --nostatusrc --outputdir output --output output.xml --merge output/output.xml  output/rerun.xml
# Robot Framework generates a new output.xml

使用方式:

  1. Jenkins中添加构建步骤:Execute Linux shell command
  2. rfrerun mysuite.robot

执行结果

在log日志中,第一次失败的用例会显示2条message


testerq
11 声望0 粉丝