I know that MSTest doesn't support RowTest
and similar tests.
What do MSTests
users do? How is it possible to live without RowTest
support?
I've seen DataDriven
test features but sounds like too much overhead, is there any 3rd party patch or tool which allow me to do RowTest
similar tests in MSTest
?
To run MSTest unit tests, specify the full path to the MSTest executable (mstest.exe) in the Unit Testing Options dialog. To call this dialog directly from the editor, right-click somewhere in the editor and then click Options.
In this article, I will explain about the unit test in asp.net core using MSTest. There are three different test frameworks which are supported by the unit test with asp.net core: MSTest, xUnit, and NUnit, which allow us to test our code in a consistent way.
[TestMethod] Test1Row1 { Test1(1,4,5); } [TestMethod] Test1Row2 { Test1(1,7,8); } private Test1(int i, int j, int k) { //all code and assertions in here }
I know this is a late answer but hopefully it helps others out.
I looked everywhere for an elegant solution and ended up writing one myself. We use it in over 20 projects with thousands of unit tests and hundreds of thousands of iterations. Never once missed a beat.
https://github.com/Thwaitesy/MSTestHacks
1) Install the NuGet package.
2) Inherit your test class from TestBase
public class UnitTest1 : TestBase { }
3) Create a Property, Field or Method, that returns IEnumerable
public class UnitTest1 : TestBase { private IEnumerable<int> Stuff { get { //This could do anything, get a dynamic list from anywhere.... return new List<int> { 1, 2, 3 }; } } }
4) Add the MSTest DataSource attribute to your test method, pointing back to the IEnumerable name above. This needs to be fully qualified.
[DataSource("Namespace.UnitTest1.Stuff")] public void TestMethod1() { var number = this.TestContext.GetRuntimeDataSourceObject<int>(); Assert.IsNotNull(number); }
End Result: 3 iterations just like the normal DataSource :)
using Microsoft.VisualStudio.TestTools.UnitTesting; using MSTestHacks; namespace Namespace { public class UnitTest1 : TestBase { private IEnumerable<int> Stuff { get { //This could do anything, get a dynamic list from anywhere.... return new List<int> { 1, 2, 3 }; } } [DataSource("Namespace.UnitTest1.Stuff")] public void TestMethod1() { var number = this.TestContext.GetRuntimeDataSourceObject<int>(); Assert.IsNotNull(number); } } }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With