Login or Sign Up to become a member!
LessThanDot Sit Logo

LessThanDot

Enterprise Developer

Less Than Dot is a community of passionate IT professionals and enthusiasts dedicated to sharing technical knowledge, experience, and assistance. Inside you will find reference materials, interesting technical discussions, and expert tips and commentary. Once you register for an account you will have immediate access to the forums and all past articles and commentaries.

LTD Social Sitings

Lessthandot twitter Lessthandot Linkedin Lessthandot friendfeed Lessthandot facebook Lessthandot rss

Note: Watch for social icons on posts by your favorite authors to follow their postings on these and other social sites.

Your profile

    Search

    XML Feeds

    Google Ads

    « Continuous Delivery Project - Deploy and Smoke TestContinuous Delivery Project - Making MVCMusicStore Testable »
    comments

    The purpose of the integration build is to bring potential issues to the surface as quickly as possible. Unit tests run quickly and adding them to the continuous integration build helps flush out defects as close to the beginning of the process as possible. Generally build engines will support unit test framework by directly integrating with them or by providing an ability to execute the test framework and import their results.


    Delivery Pipeline - Focus of Current Post

    This is the fourth post in a multi-part series on my Continuous Delivery pipeline project. The previous post followed the changes necessary to add unit testing to the MVC Music Store project, a process that ended in the creation of unit tests for the Checkout process. In this post I will configure the CI build job to run the unit test suite, including extra steps necessary to get the MS Test framework runnable on the build server.

    Run the Build

    With the automated build already polling changes from the source code repository, this process actually started while I was still writing the initial unit tests for the prior post. With the little red "failed build" dot as my guide, and the ever present twitter bot reminding me on each broken commit, I ended up working on both the unit tests and the server configuration in overlapping steps.


    Failing Unit Test Build

    The initial build failure was due to the addition of the MS Test project to the solution. This test project includes necessary references for the MS Test libraries, but unfortunately those libraries are not included in the project or as part of the .Net framework installation. This causes the build to fail with missing reference errors.

    There are several blogs and methods outlined to get MS Test running on a build server, including some registry hacks and other unsupported trickery. After spending some time exploring that route, I eventually gave up and installed Visual Studio on the test server.

    This is an area that Microsoft could definitely use some improvement in (MS Test integration), but what's interesting is that many experts on continuous delivery (of which I am definitely not one) actually suggest using the same software on the build server as the developers use to minimize differences in the builds. Whatever the case, the choice of MS Test generally ends with us having Visual Studio on our build server.

    Once the install was completed and I had patched Visual Studio up to date, I was able to run successful builds again.

    Run the Tests in the Build

    At this point I am building the test project every time the build runs, but I'm not actually running any of the tests. In order to run the tests, I am going to drop to the command line and run the MS Test executable directly. To execute a command directly as a build step, I'll add a "Windows Batch Command" step to the "Build" section of my CI Build job.


    Jenkins Configuration - New Windows Batch Command

    The MS Test executable is located in the Visual Studio folder at C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\mstest.exe. I'll execute this against the compiled assembly from the MVCMusicStoreTests project and configure the results file to land somewhere obvious so i can import it later.

    Jenkins provides a list of variables we can use in commands, in this case I'll use the %WORKSPACE% variable to locate the assembly:
    "C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\mstest.exe" /resultsfile:"%WORKSPACE%\MvcMusicStoreTests\bin\Release\MyTests.Results.xml" /testcontainer:"%WORKSPACE%\MvcMusicStoreTests\bin\Release\MvcMusicStoreTests.dll" /nologo

    At this point, I can run the build again but it doesn't show anything different than before until I open the command log. Inside the command log I can see that the tests ran successfully as part of the build. I also can manually verify the results file was published to the location I specified above.

    Integrating the Test Run

    To integrate the MS Test results into Jenkins, I'll use a plugin to map the MS Test format to a format that Jenkins natively understands (Junit XML results). A plugin is available from the "Manage Plugins" screen (Jenkins, Manage Jenkins, Manage Plugins, Click the Available Tab) to do this work for me.

    After the plugin installs successfully, there is a new entry in the "Post-Build Actions" section of the job configuration. All I need to do is check the new "Publish MSTest test result report" checkbox and enter the path I used above for the result files.


    Jenkins Configuration - New Windows Batch Command

    Now when I run the build again, a new section shows up on the run summary screen that indicates I don't have any failing tests. Clicking that link for more details, I can see that Jenkins has parsed that results file from MS Test and provided information on all of the running tests and their execution times.


    Jenkins Configuration - Successful Job w/ Unit Tests

    In addition to the test information, there is also a new menu item on the left side named "History". Clicking this will show historical information on the test runs, including a graph of the execution times and test counts.


    Jenkins Configuration - Unit Test History

    Note: If, like me, you didn't bother to define a server name in the Jenkins configuration panel, you will find that some of these links will not work from a remote server because they are defined with the full server name instead of relative links.

    I am naturally paranoid when things work right away, so at this point I purposefully broke a unit test and reran the build to verify it would report it correctly.


    Failed Unit Test Run

    And my twitter bot is, of course, more than happy to broadcast that failure far and wide.


    Failed Unit Test Run

    Next Steps

    With unit tests integrated into the build job, I am nearly done with the Continuous Integration stage of this pipeline. The last thing step will be to verify the packaged code can actually be deployed and to build in the ability to smoke test that deployed code.

    About the Author

    User bio imageEli delivers software and technology solutions for a living. His roles have included lone developer, accidental DBA, team lead, and even unintentional Solaris consultant once. With experience in adhoc, Lean, and Agile environments across NSF grants, SaaS products, and in-house IT groups, he is just as willing to chat about the principles of Lean or Continuous Delivery as he is to dive into Azure, SQL Server, or the last ATDD project he created.
    Social SitingsTwitterLinkedInHomePagedeliciousLTD RSS Feed
    InstapaperVote on HN

    1 comment

    Comment from: adrian hedley [Visitor] · http://www.adrianhedley.com
    adrian hedley Hi Eli,

    Thanks for the excellent article. I was able to integrate Visual Studio Unit Test with Jenkins Build Server and look forward to reading further articles on the subject.

    Unfortunately there are not a lot of good resources on the internet and the book I have on Jenkins is even worse. Your article made a positive difference.

    I see you are interested in Lean and Agile. 2 books I read recently make a very good read if you are business minded: Lean Start-up by Eric Ries and Running Lean by Ash Muraya.

    I am a newbie were CI in concerned but I am currently reading Ship It from The pragmatic Bookshelf which got me inspired. I am currently building a Build Machine with Jenkins which I am planning to use as well as other members of my team. After having implemented subversion version control last year this is the next step .

    I am also building a commercial software product with a partner and want to automate things as much as possible, including the packaging (creating an installer).

    Regards,

    Adrian
    12/28/12 @ 06:33

    Leave a comment


    Your email address will not be revealed on this site.

    To mislead the spambots.

    Your URL will be displayed.
    (Line breaks become <br />)
    (Name, email & website)
    (Allow users to contact you through a message form (your email will not be revealed.)