{"id":654,"date":"2007-08-24T07:58:23","date_gmt":"2007-08-24T06:58:23","guid":{"rendered":"http:\/\/www.craigmurphy.com\/blog\/?p=654"},"modified":"2007-08-24T07:58:57","modified_gmt":"2007-08-24T06:58:57","slug":"running-nunit-tests-in-finalbuilder","status":"publish","type":"post","link":"http:\/\/www.craigmurphy.com\/blog\/?p=654","title":{"rendered":"Running NUnit Tests in FinalBuilder"},"content":{"rendered":"<p>I&#8217;m delivering a presentation at <a href=\"http:\/\/www.nrw07.de\">NRW07<\/a> &#8211; it&#8217;s a session about Automating the Build Process Using <a href=\"http:\/\/www.finalbuilder.com\">FinalBuilder.<\/a>  <\/p>\n<p>I&#8217;m demonstrating a specific product, so you might believe that it&#8217;s a &#8220;product plug&#8221; session that&#8217;s full of marketing stuff.  Thankfully, nothing could be further from the truth.  I&#8217;m an avid believer in making things simple &#8211; FinalBuilder is one of many products that help me achieve that aim.  Therefore, I am demonstrating a useful and highly configurable tool.<\/p>\n<p>FinalBuilder has built-in support for running NUnit tests, so it&#8217;s actually remarkably easy to include running tests in your automated build process.  However, since FinalBuilder is so <strong>feature-rich<\/strong>, I wanted to demonstrate just how easy it is to write some FinalBuilder Actions that run the tests and stop the build if the tests fail.  The key take-away from this post is the ease in which FinalBuilder can be customised to incorporate new and or as yet unsupported third party tools.<\/p>\n<p>NUnit has two modes of operation: via a GUI or via the command-line console.  Obviously the GUI provides nice visual feedback, red and green bars, etc.  The console version is less visually pleasing, but does appeal to the command-line fraternity (which suits me!)  Using the command-line version of NUnit (typically found here: C:\\Program Files\\NUnit 2.4.3\\bin\\Nunit-Console.exe), you&#8217;ll be pleased to know that it will run your tests on your behalf and create as output, create a nicely formatted XML document.  That XML document contains two rather useful attributes: total and failures &#8211; these indicate the number of tests that were run and the number of failures.<\/p>\n<p>[code lang=&#8221;XML&#8221;]<br \/>\n<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"no\"?><br \/>\n<!--This file represents the results of running a test suite--><br \/>\n<test-results name=\"...testroman11.dll\" total=\"12\" failures=\"0\" not-run=\"0\" date=\"2007-08-18\" time=\"16:05:18\"><br \/>\n  <environment nunit-version=\"2.4.3.0\" clr-version=\"2.0.50727.312\" os-version=\"Microsoft Windows NT 6.0.6000.0\" platform=\"Win32NT\" cwd=\"...\\TestRoman11\\bin\\Debug\" machine-name=\"VISTA\" user=\"Craig\" user-domain=\"Vista\" \/><br \/>\n  <culture-info current-culture=\"en-GB\" current-uiculture=\"en-US\" \/><br \/>\n  <test-suite name=\"...testroman11.dll\" success=\"True\" time=\"0.108\" asserts=\"0\"><br \/>\n    <results><br \/>\n      <test-suite name=\"TestRoman11\" success=\"True\" time=\"0.100\" asserts=\"0\"><br \/>\n        <results><br \/>\n          <test-suite name=\"TestRoman11\" success=\"True\" time=\"0.064\" asserts=\"0\"><br \/>\n            <results><br \/>\n              <test-case name=\"TestRoman11.TestRoman11.Roman1\" \n                              executed=\"True\" success=\"True\" time=\"0.010\" asserts=\"1\" \/><br \/>\n<snip><br \/>\n            <\/results><br \/>\n          <\/test-suite><br \/>\n        <\/results><br \/>\n      <\/test-suite><br \/>\n    <\/results><br \/>\n  <\/test-suite><br \/>\n<\/test-results><br \/>\n[\/code]<\/p>\n<p>Clearly we can make use of the failures attribute to our advantage.  If it&#8217;s zero, then the automated build process can continue on.  However, if it has a value of one or more, clearly we have a problem, the build is broken.<\/p>\n<p>Without using FinalBuilder&#8217;s built-in NUnit Action, how might we go about incorporating NUnit into our FinalBuilder build process?  Thanks to the power of FinalBuilder, it&#8217;s actually remarkably easy.  Assuming that you have a new, clean FinalBuilder project, here&#8217;s what you do:<\/p>\n<p>1. Goto the <strong>Tools -> Edit Variables<\/strong> menu, add a new variable called <strong>TestFailures<\/strong>.<\/p>\n<p><img decoding=\"async\" src=\"http:\/\/www.craigmurphy.com\/blog\/wp-content\/uploads\/2007\/08\/fb1.jpg\" \/><\/p>\n<p>2.  Add a new <strong>Execute Program<\/strong> action (from the <strong>Windows OS<\/strong> action group).  Set the Program File input box to point to nunit-console.exe.  In the Parameters input box, enter the name of the DLL that contains your NUnit tests.  In the Start In input box, enter the full path to the directory where the DLL that contains your tests can be found.<\/p>\n<p><img decoding=\"async\" src=\"http:\/\/www.craigmurphy.com\/blog\/wp-content\/uploads\/2007\/08\/fb2.jpg\" \/><\/p>\n<p>3.  Add a new <strong>Define XML Document<\/strong> action (from the <strong>XML<\/strong> action group).  Call the XML document TestResults.  Set the Load document from file input box &#8211; set it to the TestResults.xml file that sits alongside the DLL that contains your tests.  This assumes that you have either places an empty TestResults.xml file in that folder or you have run your tests through the NUnit Console prior to this exercise.<\/p>\n<p><img decoding=\"async\" src=\"http:\/\/www.craigmurphy.com\/blog\/wp-content\/uploads\/2007\/08\/fb3.jpg\" \/><\/p>\n<p>4.  Add a new <strong>Read XML Value to Variable<\/strong> action.  Set the XPath to Node equal to <strong>\/\/test-results<\/strong>.  Put a tick in the Read attribute check-box, set it equal to <strong>failures<\/strong>.  From the Variable to Set drop-down menu, set it to <strong>TestFailures<\/strong>.<\/p>\n<p><img decoding=\"async\" src=\"http:\/\/www.craigmurphy.com\/blog\/wp-content\/uploads\/2007\/08\/fb4.jpg\" \/><\/p>\n<p>5.  Add an <strong>If..Then<\/strong> action (from the <strong>Flow Control<\/strong> action group).  Set the Left-hand Term equal to %TestFailures% &#8211; there is code completion to help you.  Set the operator equal to &#8220;greater than&#8221;, i.e. ><\/p>\n<p><img decoding=\"async\" src=\"http:\/\/www.craigmurphy.com\/blog\/wp-content\/uploads\/2007\/08\/fb5.jpg\" \/><\/p>\n<p>6.  Run your FinalBuilder project.  If all goes well, i.e. the tests pass, the screenshots below should look familiar.  Otherwise, if the tests fail, the whole build process fails.<\/p>\n<p><img decoding=\"async\" src=\"http:\/\/www.craigmurphy.com\/blog\/wp-content\/uploads\/2007\/08\/fb6.jpg\" \/><\/p>\n<p><img decoding=\"async\" src=\"http:\/\/www.craigmurphy.com\/blog\/wp-content\/uploads\/2007\/08\/fb7.jpg\" \/><\/p>\n<p>This short example demonstrates the power of FinalBuilder &#8211; whilst there is a built-in action for running NUnit projects, this example has served to demonstrate how easy it is to integrate a third party tool into the FinalBuilder build process.  Hopefully this short example has been enough to convince you that FinalBuilder can be used to integrate virtually any &#8220;build activity&#8221; that you may have in your process.<\/p>\n<p>How are you carrying out your build process at the moment?  Is it automated?  Harness the power of the fully automated build!<\/p>\n<p>Resources<br \/>\n<a href=\"http:\/\/www.finalbuilder.com\">http:\/\/www.finalbuilder.com<\/a><br \/>\n<a href=\"http:\/\/www.nunit.org\">http:\/\/www.nunit.org<\/a><\/p>\n<p>Technorati Tags: <a href=\"http:\/\/technorati.com\/tag\/FinalBuilder\" rel=\"tag\">FinalBuilder<\/a>, <a href=\"http:\/\/technorati.com\/tag\/TDD\" rel=\"tag\">TDD<\/a>, <a href=\"http:\/\/technorati.com\/tag\/NUnit\" rel=\"tag\">NUnit<\/a>, <a href=\"http:\/\/technorati.com\/tag\/automating+the+build+process\" rel=\"tag\">automating the build process<\/a>, <a href=\"http:\/\/technorati.com\/tag\/automated+builds\" rel=\"tag\">automated builds<\/a>, <a href=\"http:\/\/technorati.com\/tag\/VSoft\" rel=\"tag\">VSoft<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>I&#8217;m delivering a presentation at NRW07 &#8211; it&#8217;s a session about Automating the Build Process Using FinalBuilder. I&#8217;m demonstrating a specific product, so you might believe that it&#8217;s a &#8220;product plug&#8221; session that&#8217;s full of marketing stuff. Thankfully, nothing could be further from the truth. I&#8217;m an avid believer in making things simple &#8211; FinalBuilder &hellip; <a href=\"http:\/\/www.craigmurphy.com\/blog\/?p=654\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">Running NUnit Tests in FinalBuilder<\/span> <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[15,33,3,6],"tags":[],"class_list":["post-654","post","type-post","status-publish","format-standard","hentry","category-net","category-automated-builds","category-development","category-tdd"],"_links":{"self":[{"href":"http:\/\/www.craigmurphy.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/654","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/www.craigmurphy.com\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.craigmurphy.com\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.craigmurphy.com\/blog\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.craigmurphy.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=654"}],"version-history":[{"count":0,"href":"http:\/\/www.craigmurphy.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/654\/revisions"}],"wp:attachment":[{"href":"http:\/\/www.craigmurphy.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=654"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.craigmurphy.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=654"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.craigmurphy.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=654"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}