3

In NUnit we can run a test-fixture multiple times with varying parameters simply by specifying multiple [TestFixture] attributes, each one causing the class to be instantiated with the specified attribute parameter.

Here is an example:

[TestFixture("A")]
[TestFixture("B")]
[TestFixture("C")]
public class MyTestClass
{
    public MyTestClass(string str)
    {
        ...

So the fixture would be instantiated 3 times: with str="A", then str="B" and finally str="C".

I'm trying to find the equivalent for the Visual Studio testing tools but the [TestClass] attribute can be specified only once.

I've read the doc but found no clue.

I can think of a simple workaround by using inheritance but I'm sure there is a simpler way.

jessehouwing
  • 106,458
  • 22
  • 256
  • 341
Pragmateek
  • 13,174
  • 9
  • 74
  • 108
  • There is no real equivalent. Closest I think is the Data Driven unit test: http://msdn.microsoft.com/en-us/library/ms182527.aspx – jessehouwing Jun 29 '14 at 21:06
  • Thanks Jesse for the information. Really a shame such a basic feature is not yet available. :/ I was used to the best of breed tools (NUnit + TestDriven) but I must make my tests work for the Express version and wanted to demonstrate the integrated tools. Using a DataSource is really heavy and hacky, so I will go with my first idea which is quite elegant but I would have prefered an integrated solution because for me conciseness is better than elegance. :) – Pragmateek Jun 29 '14 at 21:51
  • I'm not sure whether it's "yet" or just "on purpose". Having 3 distinct scenario's might be easier to read when one would have 3 distinct tests (using inheritance you'd have that). But I don't know the exact reasons here. – jessehouwing Jun 30 '14 at 05:53
  • I fear the exact reasons are always the same: cost, cost and cost. :) Concerning your edit AFAIK MSTest is obsolete since the new VS integrated tools... – Pragmateek Jun 30 '14 at 09:23
  • Not really. The test framework is still called MsTest. But the runner is now encapsulated in the new VS Test Runner. – jessehouwing Jun 30 '14 at 09:43

1 Answers1

1

There is no real equivalent. Closest I think is the Data Driven unit test.

jessehouwing
  • 106,458
  • 22
  • 256
  • 341
  • 1
    MS Test 2 does have a similar feature see this questions https://stackoverflow.com/questions/1010685/does-mstest-have-an-equivalent-to-nunits-testcase – NoseBagUK Jul 22 '22 at 10:19