mstest

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? Thanks ...

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 .WithViewData<List<Page>>(); // check 3 CollectionAssert.AreEqual(Expected, ActualModel); // check 4 ...

how to exclude a Web Reference from Code Coverage in VS 2008 Team System

When I run my MSTest tests in Visual Studio 2008 Team System and get code coverage results, I always see a particular web service included. I don't care how well this web service is tested, I'm intentionally only using a small part of it. How can I exclude the Web Reference from showing up in my Code Coverage results? I see that someo...

MSTEST CollectionAssert use with generics?

It appears that CollectionAssert cannot be used with generics. This is super frustrating; the code I want to test does use generics. What am I to do? Write boilerplate to convert between the two? Manually check collection equivalence? This fails: ICollection<IDictionary<string, string>> expected = // ... IEnumerable<ID...

First Test Crashes using MSTEST with ASP.NET MVC 1

I'm trying to start using Unit Testing and I want to test the following Controller: public class AjaxController : Controller { ... public JsonResult RateVideo( int userRating, long videoId ) { string userName = User.Identity.Name; ... } } I have a created a TestClass with the following method: [ TestM...

WatiN in MSTest - ClassCleanup fail

In thread WatiN in Visual Studio 2008 - second test method fails there is a good solution with IEStaticInstanceHelper (original answer Reusing an IE instance in VS test, sources), but when ClassCleanup fires it fails on AttachToIE. As result IEXPLORAR remain running. What is the problem? Of course it is possible to just kill the proce...

TFS 2010 RC does not run Visual Studio 2008 MSTest unit tests

Steps: Run the build including unit tests. Expected result: the unit tests are executed and succeed. Actual result: the unit tests are built by the build, but this is the result: 1 test run(s) completed - 0% average pass rate (0% total pass rate) 0/4 test(s) passed, 0 failed, 4 inconclusive, View Test Results O...

How to integrate NUnit tests into a TFS 2010 build

What is the best way to integrate nunit tests into TFS 2010? Is it via generic tests or is there a better approach to running them? Ideally I'd like to have the granularity of one generic test per test assembly and have a way to surface the results in the TFS build report. ...

How to get an xml file when running mstest

I have a class which loads an xml file using the following: Path.Combine( AppDomain.CurrentDomain.BaseDirectory, "Xml", documentName ); The documents that are being loaded are set to copy to the output directory. However, when I run mstest the xml file is not being copied to the BaseDirectory. Does anyone have any idea how I can acc...

double.NaN Equality in MS Test

Why am I getting this result? [TestMethod] public void nan_test() { Assert.AreEqual(1, double.NaN, 1E-1); <-- Passes Assert.AreEqual(1, double.NaN); <-- Fails } What difference does the delta have in asserting NaN equals a number? Surely it should always return false. I am aware of IsNaN, but that's not useful here (see ...

Detect if Visual Studio Test is running

Is there an easy way to detect if you're running in the context of a Visual Studio Test as opposed to debug or release? Here's the scenario - we have a factory class that we use heavily throughout our existing codebase, and I figured instead of refactoring it out in each class so we can substitute the default factory with one that wou...

How do I give each test its own TestResults folder?

I have a set of unit tests, each with a bunch of methods, each of which produces output in the TestResults folder. At the moment, all the test files are jumbled up in this folder, but I'd like to bring some order to the chaos. Ideally, I'd like to have a folder for each test method. I know I can go round adding code to each test to mak...

Adding a proof to VS2010 Testing file

As you know, when you run test (on this case coded ui tests) in visual studio or MS Test a .trx file is generated. Anyone knows a way to "add" a file/resource to such file? I want to add a image capture if my assertion fails. Thanks ...

Issues integrating NCover with CC.NET, .NET framework 4.0 and MsTest

I'm implementing continuous integration with CruiseControl.NET, .NET 4.0, NCover and MsTest. On the build server I'm unable to run code coverage from the Ncover explorer or NCover console. When I run where vstesthost.exe from the Ncover console it returns the Visual Studio 9.0 path and does not seem to pick up .net framework 4.0. I've fo...

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 List Editor, by running all tests, or anywhere else. If I unload the project and then re...

MSTest Not Finding New Tests

Using VS2010, I can't seem to add additional test methods. If I set up my project like this [TestMethod] public void Test1() { Assert.AreNotEqual(0,1); } [TestMethod] public void Test2() { Assert.AreNotEqual(0,1); } The only test that shows up in my Test View is Test1. How do I make sure Test2 gets in to that list? EDIT: A...

Does VS2010 Code Coverage support nUnit?

According to this schema VS2010 Premium and Ultimate has a tool for checking Code Coverage - together with a few other testing tools. Does this support nUnit too, or just MS test? ...

MSTest Deployment without DeploymentItemAttribute

Is there any way to deploy an item without using this attribute? I'm starting to get a stack of attributes over my test base and it's becoming hard to maintain. Most of my items are DLLs that need to be put into a folder below the deployment directory. ...

MSTest project can't get localized string?

I ran into a strange problem. In my unit test, I want to check the localized strings. However, I can't seem to get it work. For example, I created two resources: Resource1.resx for English and Resource1.zh-CN.resx for Chinese. The unit test project can only get the (default?) English resource string. This is the code I'm using: Resource...

Unit testing ASP.NET MVC 2 routes with areas bails out on AreaRegistration.RegisterAllAreas()

I'm unit testing my routes in ASP.NET MVC 2. I'm using MSTest and I'm using areas as well. [TestClass] public class RouteRegistrarTests { [ClassInitialize] public static void ClassInitialize(TestContext testContext) { RouteTable.Routes.Clear(); RouteTable.Routes.IgnoreRoute("{resource}.axd/{*pathInfo}"); ...