vs-unit-testing-framework

Using .runsettings to exclude assemblies from code coverage

懵懂的女人 提交于 2019-11-28 08:19:29
When running code coverage for my solution which contains multiple projects, I noticed that Code Coverage includes also my test assemblies. I found an article which suggests the following template for .runsettings: <?xml version="1.0" encoding="utf-8"?> <RunSettings> <DataCollectionRunSettings> <DataCollectors> <DataCollector friendlyName="Code Coverage" uri="datacollector://Microsoft/CodeCoverage/2.0" assemblyQualifiedName="Microsoft.VisualStudio.Coverage.DynamicCoverageDataCollector, Microsoft.VisualStudio.TraceCollector, Version=11.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">

MSTest cannot find the assembly

早过忘川 提交于 2019-11-28 07:13:49
问题 I was using MSTest and i use command mstest /testsettings:local.Testsetting /testcontainer:folder\obj\Debug\test.dll and this is the output, Run has the following issue(s): Warning: Test Run deployment issue: The assembly or module 'Microsoft.Practices. Prism' directly or indirectly referenced by the test container 'test.dll' was not found. Warning: Test Run deployment issue: The assembly or module 'Project.Common.dll' directly or indirectly referenced by the test container 'test.dll' was not

Model state validation in unit tests

社会主义新天地 提交于 2019-11-28 06:48:34
I am writing a unit test for a controller like this: public HttpResponseMessage PostLogin(LoginModel model) { if (!ModelState.IsValid) return new HttpResponseMessage(HttpStatusCode.BadRequest); } the model looks like: public class LoginModel { [Required] public string Username { set; get; } [Required] public string Password { set; get; } } Then I have unit test like this one: [TestMethod] public void TestLogin_InvalidModel() { AccountController controller = CreateAccountController(); ... var response = controller.PostLogin(new LoginModel() { }); Assert.AreEqual(HttpStatusCode.BadRequest,

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

家住魔仙堡 提交于 2019-11-28 03:10:05
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 that the [TestInitialize] & [TestCleanup] should only be run once, per local test run. Is that correct? If not, what is the proper way to do this? alexn TestInitialize and TestCleanup are ran before and after each test, this is to ensure that no tests are coupled. If you want to run methods before and after ALL tests, decorate relevant methods with

TestInitialize vs ClassInitialize

夙愿已清 提交于 2019-11-27 11:52:30
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 every time a new instance of any class? Both attributes are available only for the classes (and hence tests) where they belong. TestInitialize runs before every test that is declared on the the same class where the attribute is declared. ClassInitialize runs only on the initialization of the class where the attribute is declared. In other words it won't

Jquery AJAX success not getting triggered with Coded UI test project

夙愿已清 提交于 2019-11-27 05:50:43
问题 I am trying to run a Coded-UI test project on a asp.net MVC4 application. The application contains various ajax calls involved. When i test it manually,it works fine but when i test it by using coded-ui test project, it breaks because in the ajax calls,the callback function does not get called. Can anybody tell me what am i missing here.? Thanks in advance. 回答1: What's going wrong Microsoft's Coded UI browser injects javascript to shim the XMLHttpRequest object for tracking. Any ajax calls in

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

点点圈 提交于 2019-11-27 05:04:01
问题 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 that the [TestInitialize] & [TestCleanup] should only be run once, per local test run. Is that correct? If not, what is the proper way to do this? 回答1: TestInitialize and TestCleanup are ran before and after each test, this is to ensure that no

Using .runsettings to exclude assemblies from code coverage

痞子三分冷 提交于 2019-11-27 02:09:11
问题 When running code coverage for my solution which contains multiple projects, I noticed that Code Coverage includes also my test assemblies. I found an article which suggests the following template for .runsettings: <?xml version="1.0" encoding="utf-8"?> <RunSettings> <DataCollectionRunSettings> <DataCollectors> <DataCollector friendlyName="Code Coverage" uri="datacollector://Microsoft/CodeCoverage/2.0" assemblyQualifiedName="Microsoft.VisualStudio.Coverage.DynamicCoverageDataCollector,

Model state validation in unit tests

人走茶凉 提交于 2019-11-27 01:30:29
问题 I am writing a unit test for a controller like this: public HttpResponseMessage PostLogin(LoginModel model) { if (!ModelState.IsValid) return new HttpResponseMessage(HttpStatusCode.BadRequest); } the model looks like: public class LoginModel { [Required] public string Username { set; get; } [Required] public string Password { set; get; } } Then I have unit test like this one: [TestMethod] public void TestLogin_InvalidModel() { AccountController controller = CreateAccountController(); ... var

TestInitialize vs ClassInitialize

て烟熏妆下的殇ゞ 提交于 2019-11-26 18:07:06
问题 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 every time a new instance of any class? 回答1: Both attributes are available only for the classes (and hence tests) where they belong. TestInitialize runs before every test that is declared on the the same class where the attribute is declared.