Parameterized Unit Tests with Visual Studio 2015 Intellitest

One of the features that I would like to see in MSTest for a long time was parametric unit check (PUT). I was glad to hear that Intellitest would be able to create these tests . However, I started playing with Intellitest, and I think my definition of PUT is different from Microsoft.

When I think "PUT", I think TestCases in NUnit or Theory in xUnit . People seem much smarter than me , they use the same terminology .

Can someone tell me if Intellitest can create a PUT just like NUnit or xUnit, or is it a problem of an overloaded term meaning one in Intellitest and the other for most other testing systems? Thanks.

+5
source share
3 answers

A The parameterized Unit Test generated by Intellitest does not match the PUT that is commonly found in other testing structures.

In the world of MSTest / Intellitest, PUTs are used to intelligently generate other unit tests .

To run a test several times with different datasets in MSTest, we still need to deal with Data-driven Tests or use MSTestHacks , as suggested in How to RowTest with MSTest? .

+5
source

A parameterized unit test (PUT) is a simple generalization of unit test using parameters. PUT makes statements about the behavior of codes for the entire set of possible input values, and not just one exemplary input value. To such an extent, it is similar to the links you provide. Where it differs when it comes to creating data to feed into a parameterized unit test - IntelliTest can automatically generate input for the PUT. Please refer to the following: http://blogs.msdn.com/b/visualstudioalm/archive/2015/07/05/intellitest-one-test-to-rule-them-all.aspx for context.

+1
source

Since June 2016, this feature has been added to " MSTest V2 ", which can be installed via NuGet by adding MSTest.TestAdapter and MSTest.TestFramework packages:

 Install-Package MSTest.TestAdapter Install-Package MSTest.TestFramework 

Keep in mind that they are different from the version of the test framework that comes with, for example, Visual Studio 2017. To use them, you probably need to remove the link (s) to Microsoft.VisualStudio.QualityTools.UnitTestFramework .

After installing them, you can simply use RowDataAttribute , as shown 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, here you are not limited to int . You can also use string , float , bool or any other type of primitive value .

This is similar to the implementation previously available for Windows Store app projects if you are familiar with this implementation.

0
source

All Articles