在buildbot中显示测试计数

时间:2014-08-23 13:41:20

标签: buildbot

我对stats that Buildbot provides并不特别高兴。我理解它是用于构建而不是测试 - 这就是为什么它有步骤的概念,但没有测试的概念。当您需要构建结果中的测试统计信息时,仍有许多情况。例如,在比较不同平台上的跳过和失败测试时,估计更改的影响。

那么,需要什么来使Buildbot在结果中显示测试计数? 什么是最简单的方法,以便一个对Buildbot一无所知的人可以在15分钟内做到这一点?

1 个答案:

答案 0 :(得分:5)

根据您希望如何处理测试结果以及测试结果的呈现方式,Buildbot确实提供了Test步骤,buildbot.steps.shell.Test

我如何在构建环境中使用它的示例:

from buildbot.steps import shell

class CustomStepResult(shell.Test):
    description = 'Analyzing results'
    descriptionDone = 'Results analyzed'

    def __init__(self, log_file = None, *args, **kwargs):
        self._log_file = log_file
        shell.Test.__init__(self, *args, **kwargs)
        self.addFactoryArguments(log_file = log_file)

    def start(self):
        if not os.path.exists(self._log_file):
            self.finished(results.FAILURE)
            self.step_status.setText('TestResult XML file not found !')
        else:
            import xml.etree.ElementTree as etree
            tree = etree.parse(self._log_file)
            root = tree.getroot()

            passing = len(root.findall('./testsuite/testcase/success'))
            skipped = len(root.findall('./testsuite/testcase/skip'))
            fails = len(root.findall('./testsuite/error')) + len(root.findall('./testsuite/testcase/error')) + len(root.findall('./testsuite/testcase/failure'))

            self.setTestResults(total = fails+passing+skipped, failed = fails, passed = passing)
            ## the final status for WARNINGS is green but the step itself will be orange
            self.finished(results.SUCCESS if fails == 0 else results.WARNINGS)
            self.step_status.setText(self.describe(True))

在配置工厂中,我创建了如下步骤:

factory.addStep(CustomStepResult(log_file = log_file))

基本上我覆盖默认的Test shell步骤并传递包含我的测试结果的自定义XML文件。然后我查找pass/fail/skip结果节点,并相应地在瀑布中显示结果。

Sample Test step with the statistics