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
957
votes
25 answers

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
  • 75,813
  • 86
  • 255
  • 348
452
votes
34 answers

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.SqlProviderServices, EntityFramework.SqlServer,…
ashutosh raina
  • 9,228
  • 12
  • 44
  • 80
412
votes
7 answers

NUnit vs. MbUnit vs. MSTest vs. xUnit.net

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? Does it matter? Which one is most future proof…
bitbonk
  • 48,890
  • 37
  • 186
  • 278
411
votes
18 answers

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 fairly minimal version of the code and the test…
junichiro
  • 5,282
  • 3
  • 18
  • 26
280
votes
16 answers

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 "TargetFrameworks" property of your project file and then…
264
votes
4 answers

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
  • 7,053
  • 11
  • 42
  • 53
222
votes
7 answers

How to compare Lists in Unit Testing

How can this test fail? [TestMethod] public void Get_Code() { var expected = new List(); expected.AddRange(new [] { 100, 400, 200, 900, 2300, 1900 }); var actual = new List(); actual.AddRange(new [] { 100, 400, 200, 900,…
Ray Cheng
  • 12,230
  • 14
  • 74
  • 137
212
votes
24 answers

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
  • 11,514
  • 5
  • 27
  • 40
182
votes
9 answers

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 will run six times: MyTest(1, "A") MyTest(1, "B") MyTest(2,…
The Light
  • 26,341
  • 62
  • 176
  • 258
175
votes
4 answers

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 methods are ALSO run! I was under the impression…
Pure.Krome
  • 84,693
  • 113
  • 396
  • 647
165
votes
17 answers

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 using work fine. I understand that unit testing…
Chris
  • 2,341
  • 5
  • 23
  • 21
154
votes
9 answers

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 "Create Unit Tests" context menu any longer. See…
Houman
  • 64,245
  • 87
  • 278
  • 460
149
votes
6 answers

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] public class StringFormatUtilsTest { …
tjjjohnson
  • 3,270
  • 4
  • 31
  • 33
131
votes
6 answers

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 long time, adding debug information anywhere we…
Julian
  • 20,008
  • 17
  • 77
  • 108
131
votes
3 answers

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 reason I would like to do this is that I would…
George Mauer
  • 117,483
  • 131
  • 382
  • 612
1
2 3
99 100