{"id":303,"date":"2009-06-30T15:06:13","date_gmt":"2009-06-30T14:06:13","guid":{"rendered":"http:\/\/blog.eweibel.net\/?p=303"},"modified":"2010-02-24T19:09:26","modified_gmt":"2010-02-24T18:09:26","slug":"from-nunit-to-mstest","status":"publish","type":"post","link":"https:\/\/blog.eweibel.net\/?p=303","title":{"rendered":"From NUnit to MSTest"},"content":{"rendered":"<p>Last week I migrated several projects from <a href=\"http:\/\/www.nunit.org\">NUnit<\/a> to <a href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/ms182489(VS.80).aspx\">MSTest<\/a>. The developers use the Developer version of Microsoft Visual Studio Team System, so they have integrated unit-test support for MSTest. In this post I show you all the problems and work I had to migrate the tests from NUnit to MSTest.<\/p>\n<p><strong>Less assert-methods in MSTest<\/strong><br \/>\nIn NUnit you have <a href=\"http:\/\/www.nunit.org\/index.php?p=comparisonAsserts&#038;r=2.5\">comparison assert methods<\/a>, <a href=\"http:\/\/www.nunit.org\/index.php?p=exceptionAsserts&#038;r=2.5\">exception asserts<\/a>, more <a href=\"http:\/\/www.nunit.org\/index.php?p=typeAsserts&#038;r=2.5\">type asserts<\/a>, more <a href=\"http:\/\/www.nunit.org\/index.php?p=utilityAsserts&#038;r=2.5\">utility asserts<\/a> and so on (you see what I mean). There already exist <a href=\"http:\/\/geekswithblogs.net\/sdorman\/archive\/2009\/01\/31\/adding-custom-assertions-to-mstest.aspx\">little projects<\/a> to add more assert methods for MSTest.<br \/>\nThe problem with less assert method is the following:<\/p>\n<blockquote><p>Assert.Greater(nCount, 5);<\/p><\/blockquote>\n<p>This snippet is much more readable and maintainable than the following:<\/p>\n<blockquote><p>Assert.IsTrue(nCount > 5);<\/p><\/blockquote>\n<p>But that&#8217;s just my opinion. There are for sure people who like the second snippet more than the first one.<\/p>\n<p><strong>Attribute mappings<\/strong><br \/>\nWhen you planning to migrate your NUnit Tests to MSTest you will need a mapping between the attributes of NUnit and MSTest. You&#8217;ll find on the <a href=\"http:\/\/social.msdn.microsoft.com\/Forums\/en-US\/vststest\/thread\/433e4860-b61f-44fd-bef9-a569fb32d244\">internet<\/a> mostly the following configuration:<br \/>\n[TestFixture] -> [TestClass]<br \/>\n[Test] -> [TestMethod]<br \/>\n[SetUp] -> [TestInitialize]<br \/>\n[TearDown] -> [TestCleanup]<br \/>\n[TestFixtureSetUp] -> [ClassInitialize]<br \/>\n[TestFixtureTearDown] -> [ClassCleanup]<br \/>\nThat&#8217;s fine, but wait a minute! For two of those mappings you couldn&#8217;t just use find and replace. TestFixtureSetUp and TestFixtureTearDown aren&#8217;t static methods in NUnit. Methods with the attribute ClassInitialize or ClassCleanup has to be static. The method with the attribute ClassInitialize has even a parameter Testcontext. For those two methods you have to do a little bit more work.<\/p>\n<p><strong>TestFixtureSetup vs. ClassInitialize<\/strong><br \/>\nAs I mention above the difference between the attributes TestFixtureSetup and ClassInitialize (or TestFixtureTearDown and ClassCleanup), there&#8217;s still the question which one is conceptionally correct. Or why Microsoft did it different in comparison to NUnit.<br \/>\nI found the interesting answer in the book <a href=\"http:\/\/xunitpatterns.com\/\">xUnit Test Patterns<\/a> of Gerard Meszaros (on p. 384). Microsoft implements the <a href=\"http:\/\/junit.org\/\">JUnit<\/a> approach, what means there will be for each test method a <a href=\"http:\/\/www.martinfowler.com\/bliki\/JunitNewInstance.html\">new instance of the test class<\/a>. James Newkirk (one of the authors of NUnit) <a href=\"http:\/\/blogs.msdn.com\/jamesnewkirk\/archive\/2004\/12\/04\/275172.aspx\">regret the decision<\/a> in NUnit to us the same instance for all the test methods.<\/p>\n<p><strong>Ignore-attribute, no comment<\/strong><br \/>\nThe developers used a lot the attribute ignore in NUnit to deactivate unit tests for explorating testing. In NUnit you could add a comment to justify why the test should be ignored.<br \/>\nIn MSTest the ignore attribute does also exists, but you couldn&#8217;t add a comment.<\/p>\n<p><strong>Resharper &#038; MSTest<\/strong><br \/>\nSince <a href=\"http:\/\/www.jetbrains.com\/resharper\/index.html\">Resharper<\/a> 4.5 you could also use this amazing tool with MSTest. Before the version 4.5 it was also possible to use it with MSTest, but you have to install a plug-in to do that.<br \/>\nFrom my perspective the Resharper unit test runner is much more better than the Visual Studio test runner.<\/p>\n<p><strong>ExpectedException and Visual Studio<\/strong><br \/>\nIn Visual Studio Professional and above you have an integrated unit-test runner (similar to eclipse, netbeans, etc.). There were a lot of unit-tests which expected an exception with the type Exception. That&#8217;s works fine in Resharper, on the build server (TFS) but not in the test runner of Visual Studio. Here you&#8217;ll receive the following warning:<br \/>\nUTA017: MyUnitTest has invalid ExpectedException attribute. The type must inherit from Exception.<br \/>\nThis is a bug of the test runner, as <a href=\"http:\/\/social.msdn.microsoft.com\/Forums\/en-US\/vststest\/thread\/ed891a27-272c-4938-9a93-719c149d820e\">others<\/a> already described. <\/p>\n<p><strong>Execute several assemblies<\/strong><br \/>\nOne of the projects which I migrated from NUnit to MSTest runs unit tests of different assembles. So it had a nunit-file like that:<br \/>\n[code language=&#8221;xml&#8221;]<br \/>\n&lt;NUnitProject&gt;<br \/>\n    &lt;Settings activeconfig=&quot;Web&quot;&gt;<br \/>\n    &lt;Config name=&quot;Web&quot; appbase=&quot;Web&quot; configfile=&quot;web.config&quot; binpathtype=&quot;Auto&quot;&gt;<br \/>\n        &lt;assembly path=&quot;bin\\Product.NUnit.ComponentA.dll&quot;\/&gt;<br \/>\n        &lt;assembly path=&quot;bin\\Product.NUnit.ComponentB.dll&quot;\/&gt;<br \/>\n        &lt;assembly path=&quot;bin\\Product.NUnit.ComponentC.dll&quot;\/&gt;<br \/>\n    &lt;\/Config&gt;<br \/>\n&lt;\/NUnitProject&gt;<br \/>\n[\/code]<br \/>\nI didn&#8217;t found a way to do that in MSTest.<\/p>\n<p><strong>Conclusion<\/strong><br \/>\nWith the migration the developers gain code coverage and the integration of unit-testing in Visual Studio (for those who hadn&#8217;t Resharper). On the other hand they lost readability, because they have to express an assertion with code with a primitive assert method.<br \/>\nIf I could give you an advice, it&#8217;s the following: Migrate, if you have at least one of the <a href=\"http:\/\/www.microsoft.com\/downloads\/details.aspx?FamilyID=727BCFB0-B575-47AB-9FD8-4EE067BB3A37&#038;displaylang=en\">Visual Studio Team System Editions<\/a> (Developer, Test or Suite). With Visual Studio Professional (integrates a unit-test runner) and without Resharper, it is also an option to migrate to MSTest.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Last week I migrated several projects from NUnit to MSTest. The developers use the Developer version of Microsoft Visual Studio Team System, so they have integrated unit-test support for MSTest. In this post I show you all the problems and work I had to migrate the tests from NUnit to MSTest. Less assert-methods in MSTest In NUnit you have comparison assert methods, exception asserts, more type asserts, more utility asserts and so on (you see what I mean). There already&#8230;<\/p>\n<p class=\"read-more\"><a class=\"btn btn-default\" href=\"https:\/\/blog.eweibel.net\/?p=303\"> Read More<span class=\"screen-reader-text\">  Read More<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_exactmetrics_skip_tracking":false,"_exactmetrics_sitenote_active":false,"_exactmetrics_sitenote_note":"","_exactmetrics_sitenote_category":0,"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[13,10],"tags":[],"class_list":["post-303","post","type-post","status-publish","format-standard","hentry","category-net","category-testing"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/plOV9-4T","jetpack_sharing_enabled":true,"jetpack-related-posts":[{"id":982,"url":"https:\/\/blog.eweibel.net\/?p=982","url_meta":{"origin":303,"position":0},"title":"Jenkins and .Net","author":"Patrick","date":"24. Feb 2011","format":false,"excerpt":"This week I visited the first JUG\u2019s event in Bern. The topic was Jenkins (fork of Hudson). The presentation of Dr. Simon Wiest was very entertaining. He explained continuous integration and showed how easy it is to install, configure and run Jenkins. .Net integration in Jenkins Jenkins is from the\u2026","rel":"","context":"In &quot;.NET&quot;","block_context":{"text":".NET","link":"https:\/\/blog.eweibel.net\/?cat=13"},"img":{"alt_text":"butler","src":"https:\/\/i0.wp.com\/blog.eweibel.net\/wp-content\/uploads\/butler_thumb.gif?resize=350%2C200","width":350,"height":200},"classes":[]},{"id":200,"url":"https:\/\/blog.eweibel.net\/?p=200","url_meta":{"origin":303,"position":1},"title":"How to structure code in an unit test","author":"Patrick","date":"14. Jun 2009","format":false,"excerpt":"When you create your unit tests for a method in the SUT (software under test) you will ask yourself how to structure the code in the test method.I saw two kind of syntaxes which help to structure the code in a unit test method (well, actually there are at least\u2026","rel":"","context":"In &quot;.NET&quot;","block_context":{"text":".NET","link":"https:\/\/blog.eweibel.net\/?cat=13"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":9,"url":"https:\/\/blog.eweibel.net\/?p=9","url_meta":{"origin":303,"position":2},"title":"Filtering on DataTables","author":"Patrick","date":"2. May 2007","format":false,"excerpt":"When you want to apply a filter to your datatable in your dataset, you can use the method Select on the class DataTable. In our current project we use this method very often, also for databinding. Recently I discover an unexpected behaviour. Let\u2019s assume, that our datatable has 4 datarows\u2026","rel":"","context":"In &quot;Good practices&quot;","block_context":{"text":"Good practices","link":"https:\/\/blog.eweibel.net\/?cat=5"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":376,"url":"https:\/\/blog.eweibel.net\/?p=376","url_meta":{"origin":303,"position":3},"title":"Mocking frameworks in .Net","author":"Patrick","date":"30. Mar 2010","format":false,"excerpt":"A few month ago I played with some mocking frameworks in .Net. There are already some comparisons available (here, here or here). In this blog post I want to show which frameworks are available and which one fits best for agile development. You could download the source code from github.com.\u2026","rel":"","context":"In &quot;.NET&quot;","block_context":{"text":".NET","link":"https:\/\/blog.eweibel.net\/?cat=13"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":835,"url":"https:\/\/blog.eweibel.net\/?p=835","url_meta":{"origin":303,"position":4},"title":"NTimeline project &#8211; First release","author":"Patrick","date":"27. Oct 2010","format":false,"excerpt":"I currently started on codeplex.com an open source project. It was inspired by my last project. In this project I was a lead developer and software architect and the domain was about a social assurance. I was responsible about several developers and also for a product of the assurance-suite. This\u2026","rel":"","context":"In &quot;.NET&quot;","block_context":{"text":".NET","link":"https:\/\/blog.eweibel.net\/?cat=13"},"img":{"alt_text":"NTimelineLogo","src":"https:\/\/i0.wp.com\/blog.eweibel.net\/wp-content\/uploads\/NTimelineLogo_thumb1.png?resize=350%2C200","width":350,"height":200},"classes":[]},{"id":1014,"url":"https:\/\/blog.eweibel.net\/?p=1014","url_meta":{"origin":303,"position":5},"title":"Master of Advanced Studies in Information Technology","author":"Patrick","date":"9. May 2011","format":false,"excerpt":"During the last three years I was a part-time student again because I did at the university of applied science in Berne a post-grade study. Last week I received my certificate and the new title on the CV is now \u201cMaster of Advanced Studies in Information Technology\u201d. I chose the\u2026","rel":"","context":"In &quot;Private&quot;","block_context":{"text":"Private","link":"https:\/\/blog.eweibel.net\/?cat=9"},"img":{"alt_text":"image","src":"https:\/\/i0.wp.com\/blog.eweibel.net\/wp-content\/uploads\/image_thumb16.png?resize=350%2C200","width":350,"height":200},"classes":[]}],"_links":{"self":[{"href":"https:\/\/blog.eweibel.net\/index.php?rest_route=\/wp\/v2\/posts\/303","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.eweibel.net\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.eweibel.net\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.eweibel.net\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.eweibel.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=303"}],"version-history":[{"count":61,"href":"https:\/\/blog.eweibel.net\/index.php?rest_route=\/wp\/v2\/posts\/303\/revisions"}],"predecessor-version":[{"id":618,"href":"https:\/\/blog.eweibel.net\/index.php?rest_route=\/wp\/v2\/posts\/303\/revisions\/618"}],"wp:attachment":[{"href":"https:\/\/blog.eweibel.net\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=303"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.eweibel.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=303"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.eweibel.net\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=303"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}