Bamboo 失败测试无法解析 junit

7 投票
2 回答
3713 浏览
提问于 2025-04-18 12:39

我在用Bamboo作为我的Django项目的持续集成(CI)服务器。为了一个好的开始,我写了一个简单的脚本,想看看Bamboo是怎么显示成功和失败的测试结果的。

我用py.test这样来运行测试:

py.test test.py --junitxml=junitresults/results.xml

我的test.py文件里大概是这样的:

def test_that_fails():
    assert 1 == 2

所以这个测试应该是会失败的,Bamboo应该能告诉我名为“test_that_fails”的测试确实失败了。但实际上,它显示的是没有找到失败的测试,可能发生了编译错误。在Bamboo的“测试”标签下,我看到这个构建没有失败的测试

这是py.test生成的jUnit XML文件:

<?xml version="1.0" encoding="utf-8"?>
<testsuite errors="0" failures="1" name="pytest" skips="0" tests="12" time="1.317">
    <testcase classname="test" name="test_that_fails" time="0.000378847122192">
        <failure message="test failure">def test_that_fails():
        # fail pour tester bamboo
&gt;       assert 1 == 2
E       assert 1 == 2

test.py:7: AssertionError</failure>
    </testcase>
    <testcase classname="test" name="test_engage_front" time="0.149123907089"/>
    <testcase classname="test" name="test_engage_front_ffm" time="0.444163799286"/>
    <testcase classname="test" name="test_engage_manage" time="0.15494799614"/>
    <testcase classname="test" name="test_engage_organisateur" time="0.1144759655"/>
    <testcase classname="test" name="test_engage_admin" time="0.122771978378"/>
    <testcase classname="test" name="test_engage_adminffm" time="0.0980911254883"/>
    <testcase classname="test" name="test_engage_motoball" time="0.0341689586639"/>
    <testcase classname="test" name="test_engage_api" time="0.0104990005493"/>
    <testcase classname="test" name="test_jira" time="0.0974311828613"/>
    <testcase classname="test" name="test_monitoring" time="0.00897479057312"/>
    <testcase classname="test" name="test_static" time="0.00422883033752"/>
</testsuite>

如果构建成功,Bamboo会给我显示所有测试的详细信息,包括测试的持续时间……我在Bamboo的文档、Bamboo的跟踪器和这里找过所有可能的资源,但没有看到有人遇到过这个问题。

如果你有任何想法,请分享一下!谢谢。

2 个回答

0

这可能和一个关于竹子的(Bamboo)问题有关,测试结果找不到,但却出现了你看到的错误。

https://jira.atlassian.com/browse/BAM-2165

我遇到过类似的问题,通过在junit任务中修改“指定自定义结果目录”的选项,使用更广泛的搜索模式,问题就解决了。

我使用的是 **/test-results.xml

12

我只是想分享一下我发现的事情。 我之前忽略了一点,那就是如果Bamboo中的某个任务失败了,它会停止后面的任务链。 所以如果python manage.py test因为测试用例中的错误而失败,Bamboo就会停止,并且不会解析junit的结果。

解决办法是把junit解析器放在最后的任务中,放在“最终任务”这一部分。

现在一切都运行得很好。

撰写回答