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.

MSTest 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.

3048 questions
871
votes
22 answers

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

How do I use Assert (or other Test class) to verify that an exception has been thrown?
Alex
  • 71,233
  • 79
  • 245
  • 337
438
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
  • 8,700
  • 10
  • 40
  • 80
397
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
  • 45,662
  • 32
  • 173
  • 270
336
votes
11 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
  • 4,402
  • 3
  • 15
  • 25
253
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
  • 6,525
  • 11
  • 39
  • 51
195
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
  • 11,221
  • 13
  • 67
  • 124
178
votes
21 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
  • 10,594
  • 5
  • 25
  • 39
166
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
  • 78,923
  • 102
  • 356
  • 586
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
  • 58,044
  • 75
  • 235
  • 407
152
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
  • 24,407
  • 61
  • 164
  • 254
139
votes
9 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…
126
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
  • 1,911
  • 5
  • 20
  • 20
125
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
  • 44,080
  • 43
  • 148
  • 200
120
votes
5 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
  • 18,744
  • 14
  • 70
  • 100
119
votes
5 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
  • 2,802
  • 3
  • 28
  • 33
1
2 3
99 100