Reputation: 771
One feature I've wanted to see in MSTest for a long time has been Parameterized Unit Tests (PUTs). I was excited to hear that Intellitest would be capable of creating said tests. I've started playing with Intellitest, however, and I'm thinking my definition of PUTs is different than Microsoft's.
When I think "PUT", I think TestCases in NUnit, or Theories in xUnit. People much smarter than me seem to use the same terminology.
Can someone tell me if Intellitest is actually capable of creating a PUT in the same way NUnit or xUnit might, or is this an issue of an overloaded term meaning one thing in Intellitest, and another to most other testing frameworks? Thanks.
Upvotes: 8
Views: 8812
Reputation: 7594
As of June 2016, this feature has been added to "MSTest V2", which can be installed via NuGet by adding the MSTest.TestAdapter
and MSTest.TestFramework
packages:
Install-Package MSTest.TestAdapter
Install-Package MSTest.TestFramework
Be aware that these are different than the version of the test framework that ships with e.g. Visual Studio 2017. To use them, you'll likely need to remove the reference(s) to
Microsoft.VisualStudio.QualityTools.UnitTestFramework
.
Once these are installed, you can simply use the RowDataAttribute
, as demonstrated in the following example:
[TestMethod]
[DataRow(1, 1, 2)]
[DataRow(3, 3, 6)]
[DataRow(9, -4, 5)]
public void AdditionTest(int first, int second, int expected) {
var sum = first+second;
Assert.AreEqual<int>(expected, sum);
}
Obviously, you aren't restricted to
int
here. You can also usestring
,float
,bool
, or any other primitive value type.
This is identical to the implementation previously available to Windows Store App projects, if you're familiar with that.
Upvotes: 8
Reputation: 771
A Parameterized Unit Test generated by Intellitest is not the same as a PUT typically found in other testing frameworks.
In the MSTest/Intellitest world, PUTs are used to intelligently generate other unit tests.
In order to execute a test multiple times with different sets of data in MSTest, we still need to wrestle with Data-Driven Unit Tests or use MSTestHacks as suggested in How to RowTest with MSTest?.
Upvotes: 6
Reputation: 1385
A parameterized unit test (PUT) is the straightforward generalization of a unit test through the use of parameters. A PUT makes statements about the code’s behavior for an entire set of possible input values, instead of just a single exemplary input value. To that extent, it is similar to the links you provide. Where it differs is when it comes to generating the data to feed in to the parameterized unit test - IntelliTest can automatically generate input data for the PUT. I request you please refer the following: http://blogs.msdn.com/b/visualstudioalm/archive/2015/07/05/intellitest-one-test-to-rule-them-all.aspx for context.
Upvotes: 1