Wednesday, May 27, 2009

Using nUnit AND Mstest (Visual Studio Unit Testing) together in perfect harmony

I like mstest. I like the integration. I like right clicking on a method and adding a unit test SNAP done.
It works great for me. nUnit is 'ok' to me. Integration is poor without third party tools. You have to change things around to get it to work. Sometimes I get strange errors I just dont get using mstest.
You have to set config files up to be named the same as the project. Not intuitive at first since nothing actually tells you this - you expect to be able to tell it your assembly and voila. Now.. you can use a different sequence of events to prevent this, such as add assembly before creating a project in nUnit, but thats not obvious to anyone first using it.

however.. to use nUnit on a build server I dont need to install Visual Studio. In order to use Microsoft's unit testing, you need to either install Visual Studio on the build server or go through a hack to get the components on there. Its not pretty. So nUnit shines here. But.. why not use mstest in the IDE and nUnit on your build server? They have different namespaces - but you can change the aliases around to do this successfully.

At the top of your classes in your unit test projects define the following to default to microsoft testing unless a build constant is defined called NUNIT


#if !NUNIT
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Category = Microsoft.VisualStudio.TestTools.UnitTesting.DescriptionAttribute;
#else
using NUnit.Framework;
using TestInitialize = NUnit.Framework.SetUpAttribute;
using TestContext = System.Object;
using TestProperty = NUnit.Framework.PropertyAttribute;
using TestClass = NUnit.Framework.TestFixtureAttribute;
using TestMethod = NUnit.Framework.TestAttribute;
using TestCleanup = NUnit.Framework.TearDownAttribute;
#endif



Go into Visual Studio, choose the Build menu and select "Configuration Manager"
Select "new" and name this build Nunit (or mstest or whatever you want to NOT be your debug/release build). Personally.. I use a build name called MsTest since my debug builds are what get automatically tested every night with cruisecontrol.net/nant/nUnit so I want my default builds to compile with nUnit, but when I want to add/debug unit tests in the IDE I simply change my build to MsTest.

Once you create a new build name, go into each of your projects once you select the build, and go to prokect properties. In the Build tab under "Conditional Compilation Symbols" type in MSTEST or NUNIT.
Use NUNIT if you call your build nUnit and use the code above. This will assume you want your default debug/release build to default to Microsoft. Case DOES matter for the conditional compilation constants.. make sure you use all uppercase.. its easier.

If you want to create a separate build configuration for testing Microsoft unit tets, but want to keep the default debug/release for nUnit then your headers would look like this:


#if MSTEST
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Category = Microsoft.VisualStudio.TestTools.UnitTesting.DescriptionAttribute;
#else
using NUnit.Framework;
using TestInitialize = NUnit.Framework.SetUpAttribute;
using TestContext = System.Object;
using TestProperty = NUnit.Framework.PropertyAttribute;
using TestClass = NUnit.Framework.TestFixtureAttribute;
using TestMethod = NUnit.Framework.TestAttribute;
using TestCleanup = NUnit.Framework.TearDownAttribute;
#endif



hope this helps : )

123 comments:

  1. Hello,

    your blog post was mentioned here: http://stackoverflow.com/questions/5053557/using-both-mstest-and-nunit

    Thanks!

    ReplyDelete
    Replies

    1. I have read your blog its very attractive and impressive. I like it your blog.

      Dot Net Training in Chennai Dot Net Training in Chennai .Net Online Training .Net Online Training Dot Net Training in Chennai Dot Net Training in Chennai


      Dot Net Online Training Dot Net Online Training LINQ Online Training LINQ Online Training ASP.NET Online Training ASP.NET Online Training

      Delete
  2. Thanks for sharing use interview questions on .Net technology. While preparing for my job interview, your article helped me a lot to sharpen my skills and do well in my interview. One of trainer from leading dot net training institutes in Chennai suggests me about your site.

    ReplyDelete
  3. Thanks for sharing such informative guide on .Net technology. This post gives me detailed information about the .net technology. I am working as trainer in leading IT training academy offering Dot Net Training in Chennai and i use your guide to educate my students.

    ReplyDelete
  4. TechnoSoftwar having several years experience working with global customers, connecting our professionals to their business needs, as their IT Development & Support Partner. TechnoSoftwar having a team of dedicated and experienced softwares developers that works for your all business needs. TechnoSoftwar deals in web design and development, Customized ERPs, CRMs, Web & Mobile Applications, eCommerce platforms etc

    ReplyDelete
  5. Hi Dude,
    Awesome Post!!! With unique content, I really get reading interest when I am following your article, I hope I ll help many of them who looking this pretty information.
    Regards,
    Angular training in chennai|Node JS training|Angularjs training in chennai

    ReplyDelete
  6. SAP having set of modules, Industry specific modules with a deep insight. So that scope in this technology is more in recent days, I really gathered some useful information through your post, keep sharing…
    SAS Training in Chennai

    ReplyDelete
  7. Thanks for sharing this informative blog. If you are interested in taking .net in professional carrier visit this website.Dot Net Training in Chennai

    ReplyDelete
  8. Thank you for your post. This was really an appreciating one. You done a good job. Keep on blogging like this unique information with us.

    SAS Training in Chennai

    ReplyDelete
  9. this website are very important site to your in this site WP IVR Plugin or even your home and Simple Autoinstall plugin for WordPress ,click this sit e

    ReplyDelete
  10. On my current project I found it useful to use both NUnit and MsTest for unit testing. R Programming Training | DataStage Training | SQL Training | SAS Training | Android Training | SharePoint Training

    ReplyDelete
  11. Selenium is an open source automation tool where anyone can learn to automate in faster way. We offer SELENIUM Training in practical way to ensure our participant gets most of this training.
    Node.js Training | WebSphere Training | LoadRunner Training | Pentaho Training | Python Training | Selenium Training

    ReplyDelete
  12. Excellent post!!!. The strategy you have posted on this technology helped me to get into the next level and had lot of information in it.
    salesforce training in chennai | salesforce training institute in chennai

    ReplyDelete
  13. nice and really helpful article to everyone... thanks for sharing.
    mvc training in chennai

    ReplyDelete
  14. • Thanks for all your information, Website is very nice and informative content.
    sas training in chennai

    ReplyDelete
  15. • Very good effort in collecting information.........
    tib co training in chennai

    ReplyDelete
  16. Professional Expert level Android Training in chennai, Android App Development
    Android Training | Android App Development | Training in chennai

    ReplyDelete
  17. A debt of gratitude is in order for requiring some serious energy share this post. It is truly useful. I propose to visit this site to my group members. Please continue posting this way.
    Regards,
    SAS Training in Chennai | SAS Courses in Chennai | SAS Training center in Chennai

    ReplyDelete
  18. This comment has been removed by the author.

    ReplyDelete
  19. Wonderful blog.. Thanks for sharing informative blog.. its very useful to me..

    iOS Training in Chennai

    ReplyDelete
  20. I have been reading out a lot of your articles and that i ought to say pretty nice stuff. Software Testing Training Institute in Chennai | Software Testing Training Institute in Velachery.

    ReplyDelete
  21. Thank you for this valuable information. I have got some important suggestions from it. Get your business to the next level in simple steps.
    erp software solutions in chennai.

    ReplyDelete
  22. Nice blog. Thank you for sharing. The information you shared is very effective for learners I have got some important suggestions from it. erp providers in chennai.

    ReplyDelete
  23. Nice post. Very interesting to read. Thank you for Sharing.
    erp software in chennai

    ReplyDelete
  24. I really appreciate information shared above. It’s of great help. If someone want to learn Online (Virtual) instructor lead live training in Nunit, kindly contact us http://www.maxmunus.com/contact
    MaxMunus Offer World Class Virtual Instructor led training Nunit . We have industry expert trainer. We provide Training Material and Software Support. MaxMunus has successfully conducted 100000+ trainings in India, USA, UK, Australlia, Switzerland, Qatar, Saudi Arabia, Bangladesh, Bahrain and UAE etc.
    For Demo Contact us:
    Name : Arunkumar U
    Email : arun@maxmunus.com
    Skype id: training_maxmunus
    Contact No.-+91-9738507310
    Company Website –http://www.maxmunus.com



    ReplyDelete
  25. I really got more information from your blog post. Continue sharing more like this.
    Regards,
    SAS Training in Chennai | SAS course in Chennai

    ReplyDelete
  26. Impressive blog with lovely information. really very useful article for us thanks for sharing such a wonderful blog... 
    No.1 IOS Training Institute in Chennai | Best Android Training Institute in Chennai | Java Training Institute in Chennai

    ReplyDelete
  27. It is a one of the great discussion which is very essential for me as well. I must follow the handy discussion and sure that the content will be very useful to me as well. Keep it up. 
    No.1 Software Testing Training Institute in Chennai | Best Selenium Training Institute in Chennai | ISTQB Certification Center in Velachery

    ReplyDelete
  28. This is excellent information. It is amazing and wonderful to visit your site.Thanks for sharing this information,this is useful to me...
    Final Year Project Center in Chennai | IEEE Project Center in Chennai | Diploma Project Center in Chennai

    ReplyDelete
  29. Impressive blog with lovely information. really very useful article for us thanks for sharing such a wonderful blog... 
    Software Testing Training Center in Chennai | | Best Selenium Training Institute in Chennai | Six Sigma Certification Training in Chennai

    ReplyDelete
  30. Interesting post! This is really helpful for me. I like it! Thanks for sharing!
    office 2016 professional plus deutsch download

    ReplyDelete
  31. Learned a lot of new things from your post! Good creation and HATS OFF to the creativity of your mind. Very interesting and useful blog!
    SAS Training in Chennai
    SAS Course in Chennai
    SAS Training Institutes in Chennai

    ReplyDelete
  32. Thank you for your post. This is excellent information. It is amazing and wonderful to visit your site.
    Online sas certification training
    big data training services
    tail spend management

    ReplyDelete
  33. It has been simply incredibly generous with you to provide openly what exactly many individuals would’ve marketed for an eBook to end up making some cash for their end, primarily given that you could have tried it in the event you wanted.

    Selenium Training in Chennai

    Selenium Training in Bangalore

    ReplyDelete
  34. Great content thanks for sharing this informative blog which provided me technical information keep posting.
    ME/M.Tech Project Center in Chennai | ME/M.Tech Project Center in Velachery

    ReplyDelete
  35. Good Post! Thank you so much for sharing this pretty post, it was so good to read and useful to improve my knowledge as updated one, keep blogging…Python Training Institute in Chennai | Python Training in Velachery | Python Training Center in Chennai

    ReplyDelete
  36. Amazing and excellent! Amazing and excellent! My tutors were wonderful, knowledgeable, helpful and patient. An intense course, though very much fruitful.
    Graphic designing Training Institute in Chennai | Photoshop Training Institute in Chennai | Corel Draw Training Institute in Chennai

    ReplyDelete
  37. This is exactly what I was looking for. Thanks for sharing this great article! That is very interesting Smile.
    CorelDraw Training Institute in Chennai | CorelDraw Training Institute in Velachery

    ReplyDelete
  38. Awesome Post! I like writing style, the way you described the topics throughout the post. I hope many web reader will keep reading your post at the end, Thanks for sharing your view.
    MSC Project Center in Chennai | MSC Project Center in Velachery

    ReplyDelete
  39. Needed to compose you a very little word to thank you yet again regarding the nice suggestions you’ve contributed here.
    digital marketing training in chennai

    ReplyDelete
  40. Nice blog..The information you shared is very effective for learners I have got some important suggestions from it. RPA Training Institute in Chennai | UI Path Training Institute in Chennai | Blue Prism Training Institute in Chennai

    ReplyDelete
  41. Your Blog is really amazing with useful content..thank you for sharing such an informative article..
    No.1 Image Processing Project Center in Chennai | Best Image Processing Project Center in Velachery

    ReplyDelete
  42. Thanks a lot very much for the high quality and results-oriented help. I won’t think twice to endorse your blog post to anybody who wants and needs support about this area.


    Data Science Training in Rajajinagar

    Data Science Training in porur

    ReplyDelete

  43. Nice blog.thank you for sharing such a wonderful concept... its really useful for learning about visual studio testing...keep updating....
    Best AWS Training Institute in Chennai | Best AWS Training Institute in Velachery

    ReplyDelete
  44. Thank you for this post. Funny how the universe gives you what you need. I was looking for new direction and came to your site. You continue to be a source of inspiration.
    Photoshop Training Institute in Chennai | Graphics Designing Training Institute in Chennai | Photoshop Training Institute in Velachery

    ReplyDelete
  45. I like this article.I was searching over search engines and found your blog site.I like your good blog site..keep doing it..
    Graphics Designing Training Institute in Chennai | Graphics Designing Training Institute in Velachery

    ReplyDelete
  46. This information is very useful. thanks you for sharing. and I will also share information about health through the website
    CorelDraw Training Institute in Chennai | CorelDraw Training Institute in Velachery

    ReplyDelete
  47. Nice post.Thank you for the introduction of information that is very interesting to see in this article.keep sharing..
    Best VMware Training Institute in Chennai| Best VMware Training Institute in Velachery

    ReplyDelete
  48. Nice Post. Thank you for sharing...it was really very useful and informative. Keep updating..
    Best AWS Training Institute in Chennai | Best AWS Training Institute in Velachery

    ReplyDelete
  49. i gained more information from your post..Keep sharing your post.
    white label website builder

    ReplyDelete
  50. Thanks For Sharing the great tips Adam....Very Useful Development Tips...Thanks For Posting
    Thanks@Selenium Online Training

    ReplyDelete
  51. You made some good points there. I did a search on the topic and found most people will agree with your blog.
    CorelDraw Training Institute in Chennai | CorelDraw Training Institute in Velachery

    ReplyDelete
  52. Great post! I read about our article step by step useful post there.It's helpful for me my friend. Also great blog here with all of the valuable information you have.
    Best Adobe Photoshop Training Institute in Chennai | No.1 CorelDraw Training Institute in Chennai

    ReplyDelete
  53. I really enjoyed while reading your article, the information you have delivered in this post was damn good. Keep sharing your post with efficient news.
    Excellent Graphics Designing Training Institute in Chennai | No.1 CorelDraw Training Institute in Chennai | Perfect Photoshop Training Institute in Velachery

    ReplyDelete
  54. exciting blog posting! Simply put your blog post to my favorite blog list and will look forward for additional updates. Excellent Photoshop Training Institute in Chennai | Perfect CorelDraw Training Institute in Velachery

    ReplyDelete
  55. really you have posted an informative blog. it will be really helpful to many peoples. thank you for sharing this blog. so keep on sharing such kind of useful blogs.
    Excellent Photoshop Training Institute in Chennai | Best Multimedia Training Institute in Velachery

    ReplyDelete
  56. This is a wonderful article, Given so much info in it, These type of articles keeps the users interest in the website, and keep on sharing....
    Excellent Vacation Courses in Chennai | Good Summer Course in Guindy

    ReplyDelete
  57. This is very useful article!!really superb..

    software testing training online

    ReplyDelete
  58. Thanks for sharing this informative content which provided me the required information about the latest technology.
    Best Summer Courses for Hardware Networking in Chennai | No.1 Summer Course in Guindy

    ReplyDelete
  59. Nice and informative article. Thanks for sharing such nice article, keep on updating..
    Best IT Training Institute in Chennai |Best IT Training Institute in Velachery

    ReplyDelete
  60. The information shared was very much useful My sincere thanks for sharing this post Please Continue to share this post....
    Best Photoshop Summer Courses in Guindy | No.1 Technical Boot Camp in Chennai

    ReplyDelete
  61. Awesome blog. Your articles really impressed for me, because of all information so nice and unique. SAS Training in Chennai

    ReplyDelete
  62. Good Post! Thank you so much for sharing this pretty post, it was so good to read and useful to improve my knowledge as updated one, keep blogging…
    CorelDraw Training Institute in Chennai | CorelDraw Courses in Velachery

    ReplyDelete
  63. You rock particularly for the high caliber and results-arranged offer assistance. I won't reconsider to embrace your blog entry to anyone who needs and needs bolster about this region.
    Good AWS Training in Tambaram | AWS Courses in Adyar | AWS Institute in Besant Nagar

    ReplyDelete
  64. The postings on your site are always excellent. i really loved the content in it Thanks for the share and keep up this great work! All the best to you. please keep updating.
    Good AWS Training in Tambaram | AWS Courses in Adyar | AWS Institute in Besant Nagar

    ReplyDelete
  65. I Just Love to read Your Articles Because they are very easy to understand.Very Helpful Post And Explained Very Clearly About All the things.Very Helpful. Coming To Our Self We Provide Restaurant Equipment Parts Through Out US At Very Affordable Prices And Also We Offer Same Day Shipping In US.We Offer Only Genuine Products.Thanks For Posting.HAve a Nice Day!

    ReplyDelete
  66. This Blog is very helpful and useful,came to know that i should be strong in my basics and this blog helps me to improve it,Urgent Care Services Provided by Us.Thanks For Posting.I Am refereed by my friend to this blog and i also want to refer my other friends to this blog.

    ReplyDelete
  67. Thanks for good post. It’s most attractive topics for everybody. Here I would like to appreciate your work for good accuracy and got informative knowledge from here. Nice effort, very informative,
    CorelDraw Certification Training in Chennai | Advance CorelDraw Training in Madipakkam

    ReplyDelete
  68. Updating with the latest technology and implementing it is the only way to survive in our niche. Thanks for making me this article. You have done a great job by sharing this content in here.
    Android Exam Certification Training in Chennai | No.1 Android Exam in Velachery

    ReplyDelete
  69. Excellent post!!!. The strategy you have posted on this technology helped me to get into the next level and had lot of information in it.CorelDraw Training Institute in Chennai | CorelDraw Training Institute in Velachery

    ReplyDelete
  70. The information you provided in the article is useful and beneficial USMLE Really Thankful For the blogger providing such a great information. Thank you. Have a Nice Day.

    ReplyDelete
  71. I like your writing style, it was very clear to understanding the concept well; I hope you ll keep your blog as updated.
    Regards,

    Final Year Iot Project Centers Chennai | ME Projects Chennai

    ReplyDelete
  72. Great post! Thanks for sharing this valuable information.

    Selenium Training in Chennai

    ReplyDelete
  73. This article is very much helpful and i hope this will be an useful information for the needed one. Keep on updating these kinds of informative things.

    IEEE Electrical Projects in Chennai | IEEE Php Projects in Chennai.

    ReplyDelete
  74. Thanks For Sharing Valuable Information, Very Useful For U Medical Residency in USA

    ReplyDelete
  75. Really Thanks For Sharing Such an Informative Article.....

    Plots For Sale in Vizag

    ReplyDelete
  76. Thank you for sharing such valuable information and tips. This can give insights and inspirations for us; very helpful and informative! Would love to see more updates from you in the future.
    Selenium Training in Chennai
    selenium testing training in chennai
    iOS Training in Chennai
    Digital Marketing Training in Chennai
    Future of testing professional
    SEO Training in Adyar
    SEO Training in Velachery

    ReplyDelete