我们有一些测试会无缘无故地定期失败,主要是 JUnit 超时。我想知道我是否可以获得每个测试失败的次数。有了这个,我可以看到是否是某些测试一直存在问题,或者它与棘手的测试无关,更多的是该服务器上 Jenkins 的稳定性问题。
问问题
1083 次
1 回答
2
我遇到了同样的问题,我们制作了一个可以在最后 N 个构建中抓取失败测试的 python:
# -*- coding: utf-8 -*-
#! /usr/bin/python
import urllib
import re
import sys
project = "HERE_THE_PROJECT_NAME"
jenkin_host = "http://path.to.your.jenkins/jenkins/job/%s" % project
last_build = int(re.search("%s #(\d+)" % project, urllib.urlopen(jenkin_host + "/rssAll").read()).group(1))
start_build = last_build
nb_build = 200
REG_EXP = """All Failed Tests(.*)All Tests"""
FAILURE_REG_EXP = """javascript:hideStackTrace\(([^<]*)\)"""
all_failures = {}
last_seen = {}
print "Loading %s builds starting from build number %s" % (nb_build, start_build)
build_ok = 0
for build_id in range(start_build - nb_build, start_build + 1):
test_page = jenkin_host + "/%s/testReport/" % build_id
sys.stdout.write(".")
sys.stdout.flush()
failures = set()
for line in urllib.urlopen(test_page).readlines():
line_piece = re.search(REG_EXP, line)
if line_piece:
piece = line_piece.group(1)
match = re.search(FAILURE_REG_EXP, piece)
while (match):
failures.add(match.group(1))
match = re.search(FAILURE_REG_EXP, piece[match.start():match.end()])
if not failures:
build_ok += 1
for failure in failures:
all_failures[failure] = all_failures.get(failure, 0) + 1
last_seen[failure] = build_id
print
print "Done (found %s build OK)" % build_ok
nbs = [ x for x in list(set(all_failures.values())) if x > 1]
nbs.sort(reverse=True)
for i in nbs:
for test, nb in all_failures.iteritems():
if nb == i :
print "%d : %s (last seen : %s)" % (nb, test, last_seen[test])
我得到:
Loading 200 builds starting from build number 11032
.........................................................................................................................................................................................................
Done (found 148 build OK)
8 : 'one failing test' (last seen : 10906)
7 : 'another-failing-test' (last seen : 11019)
于 2012-11-16T16:07:16.370 回答