Questions tagged [mstest]

Microsoft .NET Unit Testing Framework (MSTest)

Microsoft .NET Unit Testing Framework - MSTest to integrate unit testing (also load testing, coded UI testing, etc.) into Visual Studio.

MSTestv2 contains a command-line utility that helps you run automated tests. You can run all or specific tests contained in a test assembly or event categorize them by:

  • Test Categories
  • Test Type
  • Test Lists

It also has an option to publish the test results in a Team Project on Tfs.

3252 questions
40
votes
11 answers

In MSTest, How can I verify exact error message using [ExpectedException(typeof(ApplicationException))]

Using MSTest how can I verify the exact error message coming from a test method? I know [ExpectedException(typeof(ApplicationException), error msg)] doesn't compare the error message coming from my test method, though in other unit test framework it…
Pritam Karmakar
  • 2,773
  • 5
  • 30
  • 49
39
votes
3 answers

What is the difference between MSTest.TestAdapter vs MSTest.TestFramework and when do I need which one?

What is actualy the difference between MSTest.TestAdapter vs MSTest.TestFramework and when do I need which one? In the NuGet descriptions you can read: MSTest.TestAdapter The adapter to discover and execute MSTest Framework based…
t3chb0t
  • 16,340
  • 13
  • 78
  • 118
39
votes
4 answers

Add custom message to unit test result

Is there a way I can add a custom message to the result of a test method? I want to put a stopwatch on part of the code to see how long its running. I don't need to test that it's running within a certain time frame, just want to see in the result…
Rush Frisby
  • 11,388
  • 19
  • 63
  • 83
39
votes
2 answers

Using decimal values in DataRowAttribute

I've got a c# assembly for Tests to run in Visual Studio 2017 using MSTest.TestAdaptor 1.1.17. I want to use a DataTestMethod to run a test with several datasets. My Problem is, I want to use decimal values in my DataRows but…
Sam
  • 28,421
  • 49
  • 167
  • 247
39
votes
1 answer

Difference between Microsoft.VisualStudio.TestPlatform.TestFramework and Microsoft.VisualStudio.QualityTools.UnitTestFramework

I noticed a change in one of our solutions in VS 2015 today. It seems the test projects that are generated for the solution use a different namespace than the existing test projects in the same solution. Only the test projects that…
SwissCoder
  • 2,514
  • 4
  • 28
  • 40
39
votes
2 answers

How do I verify that the expected array is the actual array in MSTest?

The following method fails: [TestMethod] public void VerifyArrays() { int[] actualArray = { 1, 3, 7 }; Assert.AreEqual(new int[] { 1, 3, 7 }, actualArray); } How do I make it pass without iterating over the collection?
Kevin Driedger
  • 51,492
  • 15
  • 48
  • 55
39
votes
1 answer

Why must a ClassInitialize method be static?

I'm curious as to why the fixture setup must be static? It seems more intuitive to me to have instance variables per fixture that share the lifetime of the fixture. Yes, these can be initialized in the constructor, but then I assume they are out of…
ProfK
  • 49,207
  • 121
  • 399
  • 775
38
votes
1 answer

Visual Studio: Run all tests in a single project?

In my Visual Studio solution, I have about a dozen projects, several of which contain unit test methods (tagged with the TestMethod attribute), with several hundred test methods spread across those projects. From within Visual Studio, I'd like to…
Jon Schneider
  • 25,758
  • 23
  • 142
  • 170
37
votes
2 answers

Is there any .runsettings documentation?

I'm looking for documentation for .runsettings files as used with vstest. Is there an xsd? I can't seem to find much except for a few example files in the msdn documentation.
haymansfield
  • 5,419
  • 4
  • 34
  • 51
36
votes
4 answers

How does Assert.AreEqual determine equality between two generic IEnumerables?

I have a unit test to check whether a method returns the correct IEnumerable. The method builds the enumerable using yield return. The class that it is an enumerable of is below: enum TokenType { NUMBER, COMMAND, …
Jason Baker
  • 192,085
  • 135
  • 376
  • 510
36
votes
7 answers

Forcing MSTest to use a single thread

Given this test fixture: [TestClass] public class MSTestThreads { [TestMethod] public void Test1() { Trace.WriteLine(Thread.CurrentThread.ManagedThreadId); } [TestMethod] public void Test2() { …
Paul Stovell
  • 32,377
  • 16
  • 80
  • 108
36
votes
2 answers

How can I get Resharper to run tests in debug, when I get debug is "Inconclusive: Test not run"

How can I get Resharper to run tests in debug, when I get debug is "Inconclusive: Test not run" Running any MsTest test in Resharper test runner is Ok, but if I try to debug, the R# test runner just displays Inconclusive: Test not run This happens…
SteveC
  • 15,808
  • 23
  • 102
  • 173
36
votes
3 answers

CollectionAssert use with generics?

It appears that CollectionAssert cannot be used with generics. This is super frustrating; the code I want to test does use generics. What am I to do? Write boilerplate to convert between the two? Manually check collection equivalence? This…
Nick Heiner
  • 119,074
  • 188
  • 476
  • 699
36
votes
12 answers

Is there anything I can do in NUnit that I can't do in MSTest?

This question has been asked in various forms in a number of different forums, but, IMHO, I haven't been able to find a place where it's really answered clearly, so I'm going to reframe it and ask it again. I work in a basically Microsoft Shop. We…
Dave Hanna
  • 2,491
  • 3
  • 32
  • 52
36
votes
7 answers

How to exclude certain tests in the Visual Studio Test Runner?

I have attributes on certain tests that I ideally don't want to run on every build. Most of my tests are normal unit tests and I do want them to run on every build. So: how can I exclude a test by category or project type? For example, I'd like to…
Fenton
  • 241,084
  • 71
  • 387
  • 401