Skip to main content

Parameterized Unit Tests with MSTest (Metro)

I spent a long time looking for this last night as I was trying to decide if I should use MSTest, NUnit, XUnit, or something else on the Windows Store app that I've been developing.

One of the things I've used in the past with NUnit was the ability to create test cases like so:

  1. [TestCase(12,3,4)]
  2. [TestCase(12,2,6)]
  3. [TestCase(12,4,3)]
  4. public void DivideTest(int n, int d, int q)
  5. {
  6.   Assert.AreEqual( q, n / d );
  7. }

(example taken directly from the NUnit documentation here)

However, since I'd used NUnit before and since this was a side-project (no time/budget restrictions) I decided to learn some MSTest. In adding the test project and a reference to my application as well as watching a video from build on Unit Testing Windows 8 store apps I found it nice, easy, and clean. So I went looking for where this feature which to me is a huge, necessary feature and I couldn't find it... So I googled, and I googled, and I googled...

and the only thing I found was that it couldn't be done.

In giving up and going with NUnit, I installed it, changed my attributes on my classes to the NUnit TestFixture, Test, and TestCase and tried to run but it wouldn't run. It took checking the output window to realize that the nunittestexecutor wasn't being found.

Could not find test executor with URI 'executor://nunittestexecutor/'. [...]

After a bit more of looking around here and a few other places I came to the realization that with the Windows 8 store apps the NUnit extension wouldn't work due to the different .NET targets. I realized that the project type itself also was not a "Testing" project type, but a "Windows Store" specific unit testing project. The extension to run XUnit wouldn't even install for that project.

Further googling on doing parameterized "TestCase-like" unit testing with MSTest involves creating databases and "Data-driven" testing that I just did NOT want to mess with - especially since I didn't think it would work (can't use sql server compact on Windows Store Apps at this time).

But wait! I finally found it! Tucked away in a single forum post that was done quite recently I found that MSTest actually now implements a test attribute called [DataTestMethod] followed up by the [DataRow] attribute as a new feature in Visual Studio 2012 Update 1. Thus, we can rewrite the same test that was done above in NUnit, now with the equivalent in MSTest:

  1. [DataTestMethod]
  2. [DataRow(12,3,4)]
  3. [DataRow(12,2,6)]
  4. [DataRow(12,4,3)]
  5. public void DivideTest(int n, int d, int q)
  6. {
  7.   Assert.AreEqual( q, n / d );
  8. }

And additionally to help with discerning which of those cases are failing the [DataRow] attribute also has a "DisplayName" property that will be reflected in the Test Explorer pane.

Comments

Good to learn you you didn't

Good to learn you you didn't think it would work (can't use sql server compact on Windows Store Apps at this time).

dark knight slot machine online

Nice find

Interesting. I didn't know about the DataTestMethodAttribute yet. Unfortunately it currently only works for Windows Store apps.

I ran into this UserVoice suggestion to add support to .NET unit test projects as well. For readers interested in this feature, vote for it: http://visualstudio.uservoice.com/forums/121579-visual-studio/suggestion...

Re: Nice find

Thanks for the UserVoice link. I voted.

MSTest

I was not aware that the windows8 accpet MSTest module for application testing. I did my my assignment on the topic, but have not known of such things ever. This is like a revelation to me and indicates that I need to study more to become professional like you guys.

Good post..Zellmeonline

Good post..Zellmeonline

Useful info

I have gone through your post and got some idea about parameterized unit test. I think this information will be useful to all computer science students those who are doing projects on this topic. Please update some sample source codes. pre manufactured homes

For developing some android

For developing some android applications it is very necessary to have proper knowledge about parameterized unit tests with MStest. You have provided some code that is very useful for the successful implementation of the project. I request the students to refer this site to get the required data. sling tv com

do soy isoflavones work like clomid

qbx clomid injectables and iui pink discharge after clomid

RE

Without SEO tools, the optimization of websites is very much hard. Here are some the tools which are free of cost and can be readily applied to your websites in order to achieve high quality results. 

nice topic

tour packages

nice topic

I think a topic like this needs more clarification than this. Anyways I appreciate your efforts to post something this topic here. If possible try to include more examples and test cases. I am eagerly waiting for next update.garage door in my area

Useful info

Your post helped me to know about parameterized unit test with MSTest. I think this information will be useful to all students those who are doing project based on this topic. Please provide some sample source codes for executing it. Tablet PC Wholesale

Great Post... Nice share for

Great Post... Nice share for me, maybe nice for all reader of your post.. thanks. Top Engineering college in Chandigarh

good

Tests like this will be very helpful for getting a detailed idea of the various status levels of the system in a good way. I have been looking for a similar application to use in my system and this looks quite good for the purpose. rent dance floor gems parties

its quality

Apple products are revered for its quality, precision and great design. SRSG started its operations as Apple technology partners in the year 1997.
System Integration service providers
Apple service center Kolkata
Apple product dealers in Delhi
ipad dealers in kolkata
Apple iphone 6S dealers in delhi

I have followed this website

I have followed this website to know many interesting things about software. I have gain more knowledge here and also clarify my doubts regarding coding.

summary of Hamlet

Solutions

Solutions Middle East, works to Envision, Execute and Empower our clients by offerings design, implementation and on-going support services.
Vmware partners
Enterprise Messaging Solutions
SMS Alert Solutions
Enterprise Data center
Mobility Solutions

RE

Excellent writing. This write-up has effects on many critical troubles your contemporary society. Most of us cannot be uninvolved to help most of these troubles. That write-up allows good ideas in addition to methods. Free SEO Tools

The Fairdeal Group of

The Fairdeal Group of Companies is a fast-growing group with the ambition of helping people across Kenya build their dream homes and offices.
Dealers in office chairs

Moonlight Films and Theatre

Moonlight Films and Theatre Studio operates under the Moonlight Films and Theatre Society , a non-profit association whose goals are to spread knowledge of and interest in theatrical and media arts through education.
Acting institute in Delhi
Filmmaking workshop in Delhi

VIGYAN DHARA is the first

VIGYAN DHARA is the first Indian IIT-JEE/ NEET/AIIMS coaching Institute which is purely based on Historical Indian Education System that is the Gurukul Tradition of Education where students leave their homes during their studies.
IIT/PMT coaching institute in hisar
Best IIT coaching institute in hisar

SCS is focused on providing

SCS is focused on providing the most comprehensive, heterogeneous, integrated IT Software solutions to enterprises around the world.
SCS India
Nutanix Data Center
Systrack for VDI Assessment
Print control software in india
Print Management Solution in India

over the counter domperidone uk

where to buy inhaler order domperidone very low blood pressure

domperidone over the counter usa

medicine for man breast domperidone-mugijie29.tumblr what to do for nausea during pregnancy

Take One School of Mass

Take One School of Mass Communication considered as a part of the Top Mass Communication Colleges in India. It was set up in the year 2003 by honing media experts who met with a mutual vision of giving a stage to the adolescent of the nation.
Best mass communication colleges in Delhi

good article

I have gone through your site and seen the information which you have uploaded here. But it is very difficult for me. I think I need more clarification on the topic. Hope you will upload it soon.van gogh museum tour

domperidone maleate generic name

firma zahlt nichtrauchern 100 euro mugijie29-domperidone is fescue grass good for horses

Post new comment

The content of this field is kept private and will not be shown publicly.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.
  • You can enable syntax highlighting of source code with the following tags: <asp>, <c>, <cpp>, <cs>, <css>, <drupal5>, <drupal6>, <html4strict>, <java>, <javascript>, <jquery>, <php>, <python>, <ruby>, <sql>, <xml>. The supported tag styles are: <foo>, [foo]. PHP source code can also be enclosed in <?php ... ?> or <% ... %>.

More information about formatting options

By submitting this form, you accept the Mollom privacy policy.