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
49
votes
4 answers

Microsoft unit testing. Is it possible to skip test from test method body?

So I have situation when I need skip current test from test method body. Simplest way is to write something like this in test method. if (something) return; But I have a lot complicated tests and I need a way to skip test from methods which I…
DrunkCoder
  • 8,215
  • 3
  • 19
  • 14
48
votes
5 answers

Visual Studio 2012 MSTest vs NUnit pros and cons

We have to decide which technology to use for our unit testing. Currently we use Visual Studio 2010 and not happy with MSTest that came with that. It is buggy, poor in deployment (E.g the test setting output directory is not recognized correctly),…
Sriwantha Attanayake
  • 7,694
  • 5
  • 42
  • 44
47
votes
2 answers

Why does Assert.IsInstanceOfType(0.GetType(), typeof(int)) fail?

I'm kind of new to unit testing, using Microsoft.VisualStudio.TestTools.UnitTesting; The 0.GetType() is actually System.RuntimeType, so what kind of test do I need to write to pass Assert.IsInstanceOfType(0.GetType(), typeof(int))? --- following up,…
David
  • 19,389
  • 12
  • 63
  • 87
46
votes
5 answers

Understanding the MSTest TestContext

Using MSTest, I needed to obtain the name of the current test from within the [TestInitialize] method. You can get this from the TestContext.TestName property. I found an unexpected difference in behaviour between a static TestContext that is passed…
Richard Ev
  • 52,939
  • 59
  • 191
  • 278
46
votes
6 answers

How to set test category for all tests in the class

I am using MSTest, and I want to set the same test category for all methods in test class at once, without setting TestCategory attribute to each method individually. How can this be done? The most convenient and obvious way would be to set…
alex
  • 12,464
  • 3
  • 46
  • 67
45
votes
9 answers

Error when changing to (plural) in .NET Core csproj file

I was following a tutorial on Pluralsight about having an MSTest project target both .net core 2.2 AND .NET 4.7.2. This required going to my .csproj file for my test project and editing it so that the following:
David
  • 4,665
  • 4
  • 34
  • 60
45
votes
3 answers

Classes marked with TestInitialize and TestCleanup not executing

I have been struggling with this one, hopefully it will help someone else. Whilst creating unit tests using MsTest I discovered I was repeating the same code in each test, and found a couple of handy attributes (TestInitialize, TestCleanup,…
Stefan de Kok
  • 2,018
  • 2
  • 15
  • 19
44
votes
5 answers

MsTest - executing method before each test in an assembly

Is it possible to run specific method before each test in an assembly? I know about TestInitialize attribute but this attribute has "class scope". If it's defined in a Test class it will be executed before each test from this class. I want to…
brzozow
  • 821
  • 1
  • 6
  • 11
44
votes
13 answers

Running unit tests with .NET Core MSTest: "The following TestContainer was not found..."

I've searched high and low and can't find answer to this Exception. This question is the main one to come up when I search, but it doesn't address this issue. [7/8/2018 6:22:22 PM Informational] Executing test method…
Josh Withee
  • 9,922
  • 3
  • 44
  • 62
44
votes
4 answers

Visual Studio 2010 does not discover new unit tests

I am writing some unit tests in Visual Studio 2010. I can run all tests by using "Run all Tests in Current Context". However, if I write a new unit test, it does not get picked up by the environment - in other words, I am not able to find it in Test…
driis
  • 161,458
  • 45
  • 265
  • 341
42
votes
6 answers

How to RowTest with MSTest?

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…
dr. evil
  • 26,944
  • 33
  • 131
  • 201
42
votes
6 answers

Are multiple asserts bad in a unit test? Even if chaining?

Is there anything wrong with checking so many things in this unit test?: ActualModel = ActualResult.AssertViewRendered() // check 1 .ForView("Index") // check 2 …
Michael Haren
  • 105,752
  • 40
  • 168
  • 205
42
votes
4 answers

Explicitly call static constructor

I want to write unit test for below class. If name is other than "MyEntity" then mgr should be blank. Negative Unit test Using Manager private accessor I want to change name to "Test" so that mgr should be null. And then will verify the mgr…
meetjaydeep
  • 1,752
  • 4
  • 25
  • 39
41
votes
4 answers

Guidance for running tests using MSTest v1 in Visual Studio 2017 15.8.1

I upgraded to Visual Studio 2017 last week. A solution with several test projects using MSTest v1 seemed to be fine at first. Most test projects execute tests fine. This is .NET Framework, not .NET Core. However, there is one project where I am…
SvenAelterman
  • 1,532
  • 1
  • 15
  • 26
40
votes
8 answers

NUnit vs Visual Studio 2010's MSTest?

I realise that there are many older questions addressing the general question of NUnit v MSTest for versions of Visual Studio up to 2008 (such as this one). Microsoft have a history of getting things right in their 3rd version. For MSTest, that is…