使用Jenkins中的xUnit插件进行升级单元测试不起作用

Uel*_*ber 4 boost unit-testing xunit jenkins jenkins-plugins

我不是C程序员,但我必须在我的Jenkins上运行boost测试.现在我在Jenkins中安装了xUnit插件.

我添加了一个构建后的操作:"发布xUnit测试结果报告"然后,在这个构建后的步骤中,我添加了:"BoostTest-1.x(默认)"

现在我有以下选项可供设置:

https://www.dropbox.com/s/wxcny55rz2bqk6r/boost_jenkins_options.png

我设置的选项是随机的,所以请帮助我,我什么都不懂,我没有找到一些教程.

我没有使用升压单元测试,也没有使用xUnit Jenkins插件.

谁能帮我?

编辑:詹金斯这样说:

make[1]: Leaving directory `/var/lib/jenkins/workspace/southernd_test'
[xUnit] [INFO] - Starting to record.
[xUnit] [INFO] - Processing BoostTest-1.x (default)
[xUnit] [INFO] - [BoostTest-1.x (default)] - No test report file(s) were found with the pattern 'boost/*.xsl' relative to '/var/lib/jenkins/workspace/southernd_test' for the testing framework 'BoostTest-1.x (default)'.  Did you enter a pattern relative to the correct directory?  Did you generate the result report(s) for 'BoostTest-1.x (default)'?
[xUnit] [ERROR] - No test reports found for the metric 'BoostTest' with the resolved pattern 'boost/*.xsl'. Configuration error?.
[xUnit] [INFO] - Setting the build status to FAILURE
[xUnit] [INFO] - Stopping recording.
Build step 'Publish xUnit test result report' changed build result to FAILURE
Finished: FAILURE
Run Code Online (Sandbox Code Playgroud)

mar*_*ark 5

错误是因为没有生成的输出文件boost::test.需要使用正确的选项调用测试脚本:

unit_test --report_level=detailed --report_format=xml 2> xunit.xml
Run Code Online (Sandbox Code Playgroud)

不幸的是,boost :: test生成的XML输出文件的格式不正确(请参阅:使用XUnit插件转换boost :: test logsBoost Users帮助)

JUnit插件期望XML测试输出采用以下格式:

<testsuites>
  <testsuite time="0.0000" timestamp="0.000" errors="0" failures="0" tests="13" hostname="localhost" name="my_test_suite">
    <testcase id="65536" class="test" name="test_case_1" time="0.0000" />
    <testcase id="65537" class="test" name="test_case_2" time="0.0000" />
    <testcase id="65538" class="test" name="test_case_3" time="0.0000" />
  </testsuite>
</testsuites>
Run Code Online (Sandbox Code Playgroud)

有几种方法可以解决这个问题,例如:

  1. 转换XML输出 boost::test
  2. 直接自定义输出,boost::test以便生成正确的格式.

我选择了选项2 - 如果你不是'C/C++'程序员,你可以获得试图运行的测试套件的作者来遵循这种方法,下面的步骤应该有助于它们的启动:

  1. 创建一个测试访问者,以便对测试运行的结果进行后期处理.
  2. 创建一个BOOST_GLOBAL_FIXTURE类,在其析构函数中遍历测试结果,以正确的格式输出测试结果.
  3. 在主测试模块中实例化fixture类.

即:

struct JUnitVisitor : public boost::unit_test::test_tree_visitor
{
    void visit( boost::unit_test::test_case const& tc )
    {
        // output <testcase> xml in JUnit format
    }

    bool test_suite_start( boost::unit_test::test_suite const& ts )
    {
        // output <testuite> xml in JUnit format
    }

    void test_suite_finish( boost::unit_test::test_suite const& ts )
    {
        // output </testuite> xml in JUnit format
    }
};

struct MyJUnitOpFixture
{
    MyJUnitOpFixture() {}

    ~MyJUnitOpFixture()
    {
        // open results file

        /// output <testsuites> start tag

        // use a visitor to walk the test results tree       
        JUnitVisitor visitor ( out );
        boost::unit_test::traverse_test_tree(
                 boost::unit_test::framework::master_test_suite(),
                 visitor
                 );

        /// output </testsuites> end tag

    }
}
Run Code Online (Sandbox Code Playgroud)

然后通过添加以下内容在主测试文件中实例化全局fixture:

BOOST_GLOBAL_FIXTURE( MyJUnitOpFixture ); 
Run Code Online (Sandbox Code Playgroud)