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
129
votes
11 answers

How can I get "Copy to Output Directory" to work with Unit Tests?

When I build a unit test project before the tests are executed the test output is copied to a TestResults folder and then the tests are executed. The issue I'm having is that not all the files in the Debug/bin directory are copied to the…
Eric Schoonover
  • 47,184
  • 49
  • 157
  • 202
119
votes
7 answers

How can I reset an EF7 InMemory provider between unit tests?

I am trying to use the EF7 InMemory provider for unit tests, but the persistent nature of the InMemory database between tests is causing me problems. The following code demonstrates my issue. One test will work and the other test will always fail.…
Sailing Judo
  • 11,083
  • 20
  • 66
  • 97
114
votes
8 answers

Can I use mstest.exe without installing Visual Studio?

I want to use mstest.exe to run my unit test on build server, but I don't want to install Visual Studio on the build server. Can I just install MSTest without Visual Studio?
yang-qu
  • 2,144
  • 4
  • 20
  • 26
112
votes
6 answers

MSTest copy file to test run folder

I've got a test which requires an XML file to be read in and then parsed. How can I have this file copied into the test run folder each time? The XML file is set to "Copy if newer" and a compile mode of "none" (since it's not really a compile-able…
Aaron Powell
  • 24,927
  • 18
  • 98
  • 150
108
votes
9 answers

How do I check "no exception occurred" in my MSTest unit test?

I'm writing a unit test for this one method which returns "void". I would like to have one case that the test passes when there is no exception thrown. How do I write that in C#? Assert.IsTrue(????) (My guess is this is how I should check, but…
CuriousGeorge
  • 1,105
  • 2
  • 7
  • 6
101
votes
19 answers

VS 2010 Test Runner error "The agent process was stopped while the test was running."

In Visual Studio 2010, I have a number of unit tests. When I run multiple tests at one time using test lists, I sometimes reveive the following error for one or more of the tests: The agent process was stopped while the test was running. It is…
driis
  • 161,458
  • 45
  • 265
  • 341
101
votes
2 answers

Visual Studio Unit Testing: SetUp and TearDown

Instead of [SetUp] and [TearDown] in Nunit what is the alternative in Visual Studio Ultimate 2010 Unit Testing. In Nunit you can imagine setup and teardown methods are as constructors and destructors for the tests in our class.
Etibar - a tea bar
  • 1,912
  • 3
  • 17
  • 30
100
votes
20 answers

Problems with DeploymentItem attribute

I'm currently maintaining an "old" system written in C#.net, removing some obsolete features and doing some refactoring. Thanks god, the previous guy wrote some unit tests (MSTests). I quite comfortable with JUnit tests, but didn't do yet much with…
Juri
  • 32,424
  • 20
  • 102
  • 136
94
votes
4 answers

Why does this assert throw a format exception when comparing structures?

I'm trying to assert the equality of two System.Drawing.Size structures, and I'm getting a format exception instead of the expected assert failure. [TestMethod] public void AssertStructs() { var struct1 = new Size(0, 0); var struct2 = new…
Kyle
  • 3,170
  • 1
  • 17
  • 20
85
votes
2 answers

TestInitialize vs ClassInitialize

What is the difference between TestInitialize vs ClassInitialize in MSTest? What are the pros cons of each? I'm under the impression that TestInitialze should run with EACH test, every time? Is that correct? And that ClassInitialize will run…
snowmom475
  • 967
  • 1
  • 6
  • 7
84
votes
5 answers

MsTest ClassInitialize and Inheritance

I have a base class for my tests which is composed in the following way: [TestClass] public abstract class MyBaseTest { protected static string myField = ""; [ClassInitialize] public static void ClassInitialize(TestContext context) { …
Raffaeu
  • 6,694
  • 13
  • 68
  • 110
79
votes
11 answers

Do you use TestInitialize or the test class constructor to prepare each test? and why?

This question regards unit testing in Visual Studio using MSTest (this is important, because of MSTest's execution order). Both the method marked [TestInitialize] and the test class constructor will run before each test method. So, the question is,…
Anthony Mastrean
  • 21,850
  • 21
  • 110
  • 188
77
votes
8 answers

Unit test exception messages with xUnit

I'm currently converting my MsTest unit tests to xUnit. With xUnit, is there a way to test exception messages? Is it correct to test exception messages as opposed just the exception type?
sduplooy
  • 14,340
  • 9
  • 41
  • 60
77
votes
7 answers

Do MSTest deployment items only work when present in the project test settings file?

I can't seem to grasp how MSTest deployment items are supposed to be configured. I have been able to get them working properly by modifying the project's test settings file, but this is less then ideal -- the deployment item configuration is…
arathorn
  • 2,098
  • 3
  • 20
  • 29
76
votes
3 answers

Global test initialize method for MSTest

Quick question, how do I create a method that is run only once before all tests in the solution are run.
mglmnc
  • 1,400
  • 2
  • 14
  • 15