{"id":71,"date":"2009-04-01T14:01:47","date_gmt":"2009-04-01T14:01:47","guid":{"rendered":"http:\/\/andypalmer.com\/?p=71"},"modified":"2009-05-22T13:03:52","modified_gmt":"2009-05-22T13:03:52","slug":"showing-fitnesse-test-results-in-hudson","status":"publish","type":"post","link":"https:\/\/andypalmer.com\/2009\/04\/showing-fitnesse-test-results-in-hudson\/","title":{"rendered":"Showing FitNesse Test Results in Hudson"},"content":{"rendered":"

Have you tried to get your FitNesse<\/a> reports into Hudson<\/a>?<\/p>\n

Although it’s simple to get an Ant task to run the tests, and fail the build, it would be nice to see the results in Hudson’s junit report.
\nUnfortunately FitNesse outputs it’s results in a format that Hudson doesn’t understand. But that’s OK, because it’s all XML.<\/p>\n

I knocked together a really quick Proof of Concept xsl<\/abbr> and ant script that allow you to run the FitNesse tests and convert the output to the Ant junit format that Hudson understands.<\/p>\n

It’s a work in progress, but it should be enough to get you going. Watch this space.
\nI ran it against one suite and Hudson picked up the tests (and failure) ok.<\/p>\n

This is the build.xml that I found on Naresh Jain’s blog about integrating FitNesse with CruiseControl<\/a>, with the convert target added<\/p>\n

\r\n<?xml version=\"1.0\" encoding=\"UTF-8\"?>\r\n<project name=\"Acceptance_Tests-Common\" default=\"test\">\r\n  <target name=\"smoke\" description=\"Run fitnesse acceptance tests.\">\r\n    <property name=\"fitnesse.output.dir\" value=\"build\" \/>\r\n    <property name=\"fitnesse.output.file\" value=\"${fitnesse.output.dir}\/fitnesse-test-results\" \/>\r\n    <property name=\"fitnesse.port\" value=\"8765\" \/>\r\n    <path id=\"fitpath\">\r\n      <fileset dir=\".\">\r\n        <include name=\"fit*.jar\" \/>\r\n        <include name=\"lib\/fitnesse-20070619\/fitnesse-20070619.jar\" \/>\r\n      <\/fileset>\r\n    <\/path>\r\n    <echo message=\"About to run fitnesse server\" level=\"info\" \/>\r\n    <parallel>\r\n      <daemons>\r\n        <java classname=\"fitnesse.FitNesse\" classpath=\"${toString:fitpath};${ant.home}\/lib\/xercesImpl.jar\">\r\n          <arg value=\"-p\" \/>\r\n          <arg value=\"${fitnesse.port}\" \/>\r\n          <arg value=\"-e\" \/>\r\n          <arg value=\"0\" \/>\r\n          <arg value=\"-d\" \/>\r\n          <arg value=\"content\" \/>\r\n          <arg value=\"-r\" \/>\r\n          <arg value=\"FitnesseRoot\" \/>\r\n        <\/java>\r\n      <\/daemons>\r\n      <sequential>\r\n        <echo message=\"sleeping for 10 seconds to let FitNesse server start\" level=\"info\" \/>\r\n        <sleep seconds=\"10\" \/>\r\n        <java classpathref=\"fitpath\" classname=\"fitnesse.runner.TestRunner\" fork=\"true\" resultproperty=\"fit.test.failures\">\r\n          <arg value=\"-debug\" \/>\r\n          <arg value=\"-xml\" \/>\r\n          <arg value=\"${fitnesse.output.file}.xml\" \/>\r\n          <arg value=\"-html\" \/>\r\n          <arg value=\"${fitnesse.output.file}.html\" \/>\r\n          <arg value=\"localhost\" \/>\r\n          <arg value=\"${fitnesse.port}\" \/>\r\n          <arg value=\"UserStories.FooterStory\" \/>\r\n        <\/java>\r\n        <replace file=\"${fitnesse.output.file}.html\" token=\"<base href="http:\/\/localhost:${fitnesse.port}\/"\/>\" \/>\r\n        <echo message=\"Finished FIT tests: ${fit.test.failures} failures\/exceptions\" level=\"info\" \/>\r\n        <!--\r\n\t  <fail message=\"FIT test failures\/exceptions: ${fit.test.failures}\">\r\n\t    <condition>\r\n\t      <not>\r\n\t        <equals arg1=\"${fit.test.failures}\" arg2=\"0\" \/>\r\n\t      <\/not>\r\n            <\/condition>\r\n\t  <\/fail>\r\n\t  -->\r\n      <\/sequential>\r\n    <\/parallel>\r\n  <\/target>\r\n\r\n  <target name=\"convert-fitnesse-results-to-junit\">\r\n    <xslt style=\"fitnesse2junit.xsl\" in=\"build\/fitnesse-test-results.xml\" out=\"build\/TEST-fitnesse.xml\" \/>\r\n  <\/target>\r\n\r\n  <target name=\"test\" depends=\"smoke, convert-fitnesse-results-to-junit\" \/>\r\n<\/project>\r\n<\/pre>\n

A slight update on the XSL. This one creates the correct nodes for exceptions and errors (although it appears to make no difference to Hudson)<\/p>\n

\r\n<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\r\n<xsl:stylesheet version=\"1.0\" xmlns:xsl=\"http:\/\/www.w3.org\/1999\/XSL\/Transform\">\r\n<xsl:template match=\"\/\">\r\n  <xsl:element name=\"testsuite\">\r\n    <xsl:attribute name=\"tests\">\r\n      <xsl:value-of select=\"sum(testResults\/finalCounts\/*)\" \/>\r\n    <\/xsl:attribute>\r\n    <xsl:attribute name=\"failures\">\r\n      <xsl:value-of select=\"testResults\/finalCounts\/wrong\" \/>\r\n    <\/xsl:attribute>\r\n    <xsl:attribute name=\"disabled\">\r\n      <xsl:value-of select=\"testResults\/finalCounts\/ignores\" \/>\r\n    <\/xsl:attribute>\r\n    <xsl:attribute name=\"errors\">\r\n      <xsl:value-of select=\"testResults\/finalCounts\/exceptions\" \/>\r\n    <\/xsl:attribute>\r\n    <xsl:attribute name=\"name\">AcceptanceTests<\/xsl:attribute>\r\n  <xsl:for-each select=\"testResults\/result\">\r\n    <xsl:element name=\"testcase\">\r\n      <xsl:attribute name=\"classname\">\r\n        <xsl:value-of select=\"\/testResults\/rootPath\" \/>\r\n      <\/xsl:attribute>\r\n      <xsl:attribute name=\"name\">\r\n        <xsl:value-of select=\"relativePageName\" \/>\r\n      <\/xsl:attribute>\r\n      <xsl:choose>\r\n        <xsl:when test=\"counts\/exceptions > 0\">\r\n          <xsl:element name=\"error\">\r\n            <xsl:attribute name=\"message\">\r\n              <xsl:value-of select=\"counts\/exceptions\" \/>\r\n              <xsl:text> exceptions thrown<\/xsl:text>\r\n              <xsl:if test=\"counts\/wrong > 0\">\r\n                <xsl:text> and <\/xsl:text>\r\n                <xsl:value-of select=\"counts\/wrong\" \/>\r\n                <xsl:text> assertions failed<\/xsl:text>\r\n              <\/xsl:if> \r\n            <\/xsl:attribute>\r\n          <\/xsl:element>\r\n        <\/xsl:when>\r\n        <xsl:when test=\"counts\/wrong > 0\">\r\n          <xsl:element name=\"failure\">\r\n            <xsl:attribute name=\"message\">\r\n              <xsl:value-of select=\"counts\/wrong\" \/>\r\n              <xsl:text> assertions failed<\/xsl:text>\r\n            <\/xsl:attribute>\r\n          <\/xsl:element>\r\n        <\/xsl:when>\r\n      <\/xsl:choose>\r\n    <\/xsl:element>\r\n  <\/xsl:for-each>\r\n  <\/xsl:element>\r\n<\/xsl:template>\r\n<\/xsl:stylesheet>\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"

Have you tried to get your FitNesse reports into Hudson? Although it’s simple to get an Ant task to run the tests, and fail the build, it would be nice to see the results in Hudson’s junit report. Unfortunately FitNesse outputs it’s results in a format that Hudson doesn’t understand. But that’s OK, because it’s […]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[11,10,8,9,12],"_links":{"self":[{"href":"https:\/\/andypalmer.com\/wp-json\/wp\/v2\/posts\/71"}],"collection":[{"href":"https:\/\/andypalmer.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/andypalmer.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/andypalmer.com\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/andypalmer.com\/wp-json\/wp\/v2\/comments?post=71"}],"version-history":[{"count":18,"href":"https:\/\/andypalmer.com\/wp-json\/wp\/v2\/posts\/71\/revisions"}],"predecessor-version":[{"id":87,"href":"https:\/\/andypalmer.com\/wp-json\/wp\/v2\/posts\/71\/revisions\/87"}],"wp:attachment":[{"href":"https:\/\/andypalmer.com\/wp-json\/wp\/v2\/media?parent=71"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/andypalmer.com\/wp-json\/wp\/v2\/categories?post=71"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/andypalmer.com\/wp-json\/wp\/v2\/tags?post=71"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}