Edgewall Software

Changes between Initial Version and Version 1 of Boost Test


Ignore:
Timestamp:
Sep 29, 2006, 2:12:48 PM (18 years ago)
Author:
staffan
Comment:

Instructions on how to integrate Boost.Test with bitten (needs work)

Legend:

Unmodified
Added
Removed
Modified
  • Boost Test

    v1 v1  
     1= Using Boost.Test =
     2
     3If you're developing with C++ [http://www.boost.org boost] is probably a familiar library. As it so happends, it's also a good match for being paired, quite easily, with bitten!
     4
     5By digging around some (here: DataStorage) you can gather how bitten stores reports, and how `test` reports in particular are stored and used. For each test case a number of properties are stored, such as status and the fixture/test suite it belongs to.
     6This data is few to bitten by the `<report>` recipe command (RecipeCommands). We just have to make sure it receives it in a format that it understands.
     7
     8== Gathering the report ==
     9
     10Fortunately for us, Boost.Test outputs test reports in XML format, if instructed to do so. Thus, the amount of work we have to carry out is reduced to specifying and applying a simple XSL transform!
     11
     12But before we proceed to the needed transform we have to actually gather the XML data from boost. Suppose the program that runs your tests is called {{{run_tests}}}, then we can get an XML report by running that program as:
     13
     14{{{
     15run_tests --report_format=xml --report_level=detailed
     16}}}
     17
     18The detailed report level is needed for the XSL transform provided in the next section. Furthermore, you have to somehow store this in a file, `test_results.xml` - there are several to do this, which I leave up to you to figure out (hint: redirect stderr/cerr or read the boost docs).
     19
     20== Making it bitten-friendly ==
     21
     22Now we need to apply the following transform on the report to make it understandable by bitten:
     23
     24{{{
     25<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
     26<xsl:output method="xml" indent="yes"/>
     27 <xsl:template match="/">
     28    <unit_tests>
     29       <xsl:apply-templates/>
     30    </unit_tests>
     31 </xsl:template>
     32 <xsl:template match="TestSuite/TestCase">
     33     <test>
     34        <status>
     35          <xsl:if test="@result = 'passed'">success</xsl:if>
     36          <xsl:if test="@result != 'passed'">failure</xsl:if>
     37        </status>
     38        <fixture>
     39          <xsl:value-of select="../@name" />
     40        </fixture>
     41        <type>test</type>
     42        <name>
     43          <xsl:value-of select="@name" />
     44        </name>
     45     </test>
     46  </xsl:template>
     47</xsl:stylesheet>
     48}}}
     49
     50Use the `<x:transform>` recipe command to do this. I'll give an example below.
     51
     52== Cooking up your build recipe ==
     53
     54Here's a template for how to put all of this together in your build recipe:
     55
     56{{{
     57<build xmlns:sh="http://bitten.cmlenz.net/tools/sh" xmlns:x="http://bitten.cmlenz.net/tools/xml">
     58  <step id="test" description="Test - run automated tests">
     59    <sh:exec executable="run_tests" output="test_results.xml" args="--log_level=nothing --report_format=xml --report_level=detailed" />
     60    <x:transform src="test_results.xml" dest="test_report.xml" stylesheet="test_results.xslt" />
     61    <report category="test" file="test_report.xml"/>
     62  </step>
     63</build>
     64}}}
     65
     66Using this approach (using `<sh:exec>` to redirect the output to a file) your test log won't be very nice looking. You probably want to tweak this teample to generate the XML data by other means and instruct it to ouput nice log-message.