Questions tagged [mstest]

Microsoft .NET Unit Testing Framework (MSTest)

mstest
Filter by
Sorted by
Tagged with
965 votes
25 answers
804k views

How do I use Assert to verify that an exception has been thrown with MSTest?

How do I use Assert (or other Test class) to verify that an exception has been thrown when using MSTest/Microsoft.VisualStudio.TestTools.UnitTesting?
Alex's user avatar
  • 76.7k
454 votes
34 answers
314k views

Entity Framework Provider type could not be loaded?

I am trying to run my tests on TeamCity which is currently installed on my machine. System.InvalidOperationException: The Entity Framework provider type 'System.Data.Entity.SqlServer....
ashutosh raina's user avatar
421 votes
19 answers
380k views

Unit testing private methods in C#

Visual Studio allows unit testing of private methods via an automatically generated accessor class. I have written a test of a private method that compiles successfully, but it fails at runtime. A ...
junichiro's user avatar
  • 5,392
414 votes
7 answers
142k views

NUnit vs. MbUnit vs. MSTest vs. xUnit.net [closed]

There are quite a lot of unittesting frameworks out there for .NET. I found this little feature comparison: http://xunit.github.io/docs/comparisons.html Now I am to choose the best one for us. But how?...
bitbonk's user avatar
  • 49.2k
316 votes
17 answers
130k views

Your project does not reference ".NETFramework,Version=v4.6.2" framework. Add a reference to ".NETFramework,Version=v4.6.2" in the "TargetFrameworks"

I can't run my unit tests. I have the next error: Your project does not reference ".NETFramework,Version=v4.6.2" framework. Add a reference to ".NETFramework,Version=v4.6.2" in the "...
Василь Ткачук's user avatar
269 votes
4 answers
99k views

What would be an alternate to [TearDown] and [SetUp] in MSTest?

When I use MSTest Framework, and copy the code that Selenium IDE generated for me, MSTest doesn't recognize [TearDown] and [SetUp]. What is the alternative to this?
Maya's user avatar
  • 7,153
231 votes
7 answers
148k views

How to compare Lists in Unit Testing

How can this test fail? [TestMethod] public void Get_Code() { var expected = new List<int>(); expected.AddRange(new [] { 100, 400, 200, 900, 2300, 1900 }); var actual = new List<...
Ray Cheng's user avatar
  • 12.4k
216 votes
25 answers
204k views

Unit Testing: DateTime.Now

I have some unit tests that expects the 'current time' to be different than DateTime.Now and I don't want to change the computer's time, obviously. What's the best strategy to achieve this?
Pedro's user avatar
  • 11.7k
187 votes
11 answers
218k views

How can we run a test method with multiple parameters in MSTest?

NUnit has a feature called Values, like below: [Test] public void MyTest( [Values(1,2,3)] int x, [Values("A","B")] string s) { // ... } This means that the test method ...
The Light's user avatar
  • 26.7k
176 votes
4 answers
86k views

Why does TestInitialize get fired for every test in my Visual Studio unit tests?

I'm using Visual Studio 2010 Beta 2. I've got a single [TestClass], which has a [TestInitialize], [TestCleanup] and a few [TestMethods]. Every time a test method is run, the initialize and cleanup ...
Pure.Krome's user avatar
  • 85.7k
171 votes
17 answers
192k views

How can I write output from a unit test?

Any call in my unit tests to either Debug.Write(line) or Console.Write(Line) simply gets skipped over while debugging and the output is never printed. Calls to these functions from within classes I'm ...
Chris's user avatar
  • 2,401
155 votes
9 answers
74k views

Where is the "Create Unit Tests" selection?

I have installed the new Visual Studio 2012 Ultimate. I have created a Test Project with my solution and it contains some default unit tests. However right clicking on new Methods doesn't show the "...
Houman's user avatar
  • 65.1k
152 votes
6 answers
58k views

Does MSTest have an equivalent to NUnit's TestCase?

I find the TestCase feature in NUnit quite useful as a quick way to specify test parameters without needing a separate method for each test. Is there anything similar in MSTest? [TestFixture] ...
tjjjohnson's user avatar
  • 3,340
134 votes
6 answers
146k views

How to write to Console.Out during execution of an MSTest test

Context: We have some users reporting issues with a file upload feature in our web application. It only happens occasionally and without any special pattern. We have been trying to figure it out for a ...
Julian's user avatar
  • 20.2k
131 votes
3 answers
57k views

Is it possible to execute code once before all tests run?

Basically I would like to tell MSTest to execute a bit of code before launching into a series of test runs, essentially what I would like to do is the same thing as sticking some code in Main(). The ...
George Mauer's user avatar
129 votes
11 answers
78k views

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 ...
Eric Schoonover's user avatar
123 votes
7 answers
32k views

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 ...
Sailing Judo's user avatar
  • 11.1k
115 votes
8 answers
61k views

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's user avatar
  • 2,154
113 votes
6 answers
40k views

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 ...
Aaron Powell's user avatar
109 votes
9 answers
104k views

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(????)...
CuriousGeorge's user avatar
102 votes
2 answers
52k views

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 ...
Etibar - a tea bar's user avatar
101 votes
19 answers
34k views

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 ...
driis's user avatar
  • 163k
100 votes
20 answers
90k views

Problems with DeploymentItem attribute

I'm currently maintaining an "old" system written in C# .NET, removing some obsolete features and doing some refactoring. The previous guy wrote some unit tests (MSTests). I quite ...
Juri's user avatar
  • 32.6k
94 votes
4 answers
5k views

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 ...
Kyle's user avatar
  • 3,230
87 votes
5 answers
48k views

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 ...
Raffaeu's user avatar
  • 6,822
86 votes
2 answers
48k views

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 ...
snowmom475's user avatar
81 votes
11 answers
63k views

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 ...
Anthony Mastrean's user avatar
80 votes
8 answers
31k views

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's user avatar
  • 14.5k
78 votes
3 answers
30k views

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's user avatar
  • 1,420
77 votes
7 answers
39k views

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 ...
arathorn's user avatar
  • 2,108
76 votes
5 answers
35k views

MSTest Equivalent for NUnit's Parameterized Tests?

NUnit supports a feature where you can specify a set of data inputs for a unit test to be run multiple times. [RowTest] [Row(1001,1,2,3)] [Row(1,1001,2,3)] [Row(1,2,1001,3)] public void SumTests(int ...
blaster's user avatar
  • 8,896
75 votes
33 answers
86k views

Visual Studio - suddenly cannot debug tests

I'm not sure what I did, but all of a sudden, my Visual Studio 2012 will not debug any tests. If I select a test from the Test Explorer and tell it to run, it simply outputs this in the Test Output ...
SelAromDotNet's user avatar
75 votes
9 answers
49k views

Where is mstest.exe located?

I need to run mstest from the command line - where in the world is this exe located? Can anyone give me a clue? Edit: I only have Visual Studio 2010 installed
George Mauer's user avatar
73 votes
13 answers
33k views

Can't read app.config in C# .NET Core unit test project with ConfigurationManager

I've created a simple unit test project to read an app.config file. Target framework is Core 2.0. I also created a Core 2.0 console app, to sanity-check myself to make sure I wasn't doing anything ...
Broots Waymb's user avatar
  • 4,741
71 votes
2 answers
60k views

Visual Studio 2013 MSTest vs NUnit

My company is upgrading our Visual Studio 2012 to 2013 Premium. In the midst of this, we are also looking to start automating our tests using Visual Studio Team Services I have read a couple of ...
Null Reference's user avatar
67 votes
3 answers
91k views

DataTestMethod and DataRow attributes in MSTEST

I have seen in a Microsoft video about Visual Studio update 2 regarding these attributes. However, I can't find any other information about them and can't get a project to build with them. Does ...
Simon Vane's user avatar
  • 1,984
66 votes
13 answers
43k views

Visual Studio 15.8.1 not running MS unit tests

When I updated Visual Studio to the latest version, 1 of my test projects stopped running tests and outputted this message: Test project {} does not reference any .NET NuGet adapter. Test discovery ...
csharpsql's user avatar
  • 2,250
65 votes
18 answers
62k views

MSTest: No tests are run because no tests are loaded or the selected tests are disabled

I have a c# solution with the following structure: mySolution myProject myProject.MSTests References Microsoft.VisualStudio.QualityTools.UnitTestFramework sutMSTests.cs sutMSTests....
gerryLowry's user avatar
  • 2,646
63 votes
8 answers
82k views

Stepping through and debugging code in Unit tests

I have not been able to debug or step through unit test. Here is my sample test code... using System; using System.Text; using System.Collections.Generic; using System.Linq; using Microsoft....
dotnet-practitioner's user avatar
63 votes
4 answers
32k views

Why does Visual Studio create a new .vsmdi file?

If I open a solution in Visual Studio 2008 and run a unit test then VS creates a new .vsmdi file in the Solution Items folder and gives it the next number available e.g. My Solution2.vsmdi. Any idea ...
Guy's user avatar
  • 66.1k
62 votes
10 answers
17k views

MSTest run fails because source assembly is not trusted

I just added xUnit to our test project (for the Asserts, we're still using MSTest as the framework) and immediately the test runs refused to execute any of the tests. This is the error message: ...
Jedidja's user avatar
  • 16.7k
62 votes
5 answers
20k views

How to set up LocalDb for unit tests in Visual Studio 2012 and Entity Framework 5

We have a Visual Studio 2012 ASP.NET MVC project using Entity Framework 5. There are some unit tests that depend on a database. Setting up the app.config file in the test project to use a central SQL ...
Klas Mellbourn's user avatar
61 votes
3 answers
10k views

xUnit Equivalent of MSTest's Assert.Inconclusive

What is the xUnit equivalent of the following MSTest code: Assert.Inconclusive("Reason"); This gives a yellow test result instead of the usual green or red. I want to assert that the test ...
Muhammad Rehan Saeed's user avatar
56 votes
5 answers
88k views

Ignore IgnoreAttribute

We have MSTest tests which automatically run in hourly production. One of these tests is marked with [Ignore] attribute because it is not yet ready to run it in our production environment. Now I want ...
brgerner's user avatar
  • 4,315
56 votes
1 answer
3k views

Unit-Test project fails to build after installing .NET 4.5

I have a WPF solution in .NET 4.0 that includes a Unit Test project which tests the different commands used in the ViewModels. Everything was working fine, but then I installed .NET 4.5 and VS2012. ...
atiyar's user avatar
  • 8,042

1
2 3 4 5
73