mstest

how do you mock an xml for unit testing?

拟墨画扇 提交于 2019-12-21 12:31:11
问题 I need to unit testing this GetData method. public MessageResponse GetData(XmlElement requestElement) { MessageResponse MsgResponse = new MessageResponse(); if (requestElement.Attributes["employeeNo"] == null){ MsgResponse.Messages = new List<string>(); MsgResponse.Messages.Add("Attribute employeeNo is missing"); MsgResponse.Error = true; return MsgResponse; } if (requestElement.Attributes["xmlEmployeeName"] == null){ MsgResponse.Messages.Add("Attribute xmlEmployeeName is missing");

What is the replacement for TestContext.DataRow[“MyColumnName”]

允我心安 提交于 2019-12-21 09:18:32
问题 Using MSTest in a .Net Core Unit test project. I am attempting to use a csv datasource to provide the data for a test method. Previously, I would use something like below in a .Net Framework test project: [DataSource("Microsoft.VisualStudio.TestTools.DataSource.CSV", @"data.csv", "data#csv", DataAccessMethod.Sequential), DeploymentItem("data.csv"), TestMethod] public void ValuesController_Post() { _controller.Post(TestContext.DataRow["body"]); _valuesRepository.Verify(_ => _.Post(It.IsAny

Using both MSTest and NUnit?

狂风中的少年 提交于 2019-12-21 07:06:53
问题 Reading about MSTest and NUnit I couldn't really decide what to use in my project. We use TFS 2008 and VS2010. I like MSTest because of its integration into VS2010, Continuous Integration and Code Coverage reports. I like NUnit because it allows to formulate complex assert statements in a nice, readable fashion. Stumbling upon http://alsagile.com/archive/2010/03/09/stop-the-war-between-nunit-and-mstest-make-them.aspx I ask the community: is it possible to use both? I also think about sticking

VStest code coverage report in jenkins

▼魔方 西西 提交于 2019-12-21 06:04:04
问题 I am setting CI for .Net project using Jenkins. I used MSTest Plugin and VStestrunner plugin to run test. Now I have .trx file and .Coverage file I am facing problem in displaying code coverage report Please help me is you know any plugin to do this. 回答1: To display coverage report you need to convert it in XML format and use MSTest Plugin to publish report. MSTest Plugin recommends (https://wiki.jenkins-ci.org/display/JENKINS/MSTest+Plugin) to use thrid party application to convert in XML

ExpectedExceptionAttribute is not working in MSTest

我只是一个虾纸丫 提交于 2019-12-21 04:50:42
问题 This is weird, but all of a sudden the ExpectedExceptionAttribute quit working for me the other day. Not sure what's gone wrong. I'm running VS 2010 and VS 2005 side-by-side. It's not working in VS 2010. This test should pass, however it is failing: [TestMethod] [ExpectedException(typeof(ArgumentNullException))] public void Test_Exception() { throw new ArgumentNullException("test"); } Any ideas? This really sux. 回答1: Not to resurrect a dead thread, but I came across this when this all the

TestMethod: async Task TestSth() does not work with .NET 4.0

非 Y 不嫁゛ 提交于 2019-12-21 04:25:29
问题 I'm trying to run asynchronous test methods with .NET 4.0 BCL Async and MsTest. It seems that this setup is not able to deal with [TestMethod] async Task TestSth() due to a missing entry in the test case explorer. After changing the signature to async void , I can run the the test case but with the wrong outcome (no errors will be reported at all). I have seen an attemt at Running Async Task unit tests with TFS 2010 but I think there should be a prettier way to tackle the problem. Any

Why is [AssemblyInitialize] and [AssemblyCleanup] being called twice in same test project assembly?

喜欢而已 提交于 2019-12-21 04:10:51
问题 I thought the whole purpose of these attributes was to run them only once per assembly. I have a simple class as follows: [TestClass] public class AssemblyIntegrationTestSetup { public AssemblyIntegrationTestSetup() { } public TestContext TestContext { get; set; } [AssemblyInitialize] public static void SetupIntegrationTests(TestContext context) { WindowsServiceService.Instance.StartService("Distributed Transaction Coordinator"); } [AssemblyCleanup] public static void TeardownIntegrationTests

Mixed-Mode Assembly MSTest Failing in VS2015

别说谁变了你拦得住时间么 提交于 2019-12-21 03:53:06
问题 When attempting to run unit tests that use mixed mode assemblies in VS2015 the tests fail to execute with the usual message: System.IO.FileLoadException: Mixed mode assembly is built against version 'v2.0.50727' of the runtime and cannot be loaded in the 4.0 runtime without additional configuration information. Creating an app.config and adding useLegacyV2RuntimeActivationPolicy to it has no effect - it seems as though this configuration is impossible to change. This previously worked with no

Mixed-Mode Assembly MSTest Failing in VS2015

自闭症网瘾萝莉.ら 提交于 2019-12-21 03:53:06
问题 When attempting to run unit tests that use mixed mode assemblies in VS2015 the tests fail to execute with the usual message: System.IO.FileLoadException: Mixed mode assembly is built against version 'v2.0.50727' of the runtime and cannot be loaded in the 4.0 runtime without additional configuration information. Creating an app.config and adding useLegacyV2RuntimeActivationPolicy to it has no effect - it seems as though this configuration is impossible to change. This previously worked with no

How To Read UnitTest Project's App.Config From Test With HostType(“Moles”)

百般思念 提交于 2019-12-21 03:46:25
问题 I have the folowing tests: [TestClass] public class GeneralTest { [TestMethod] public void VerifyAppDomainHasConfigurationSettings() { string value = ConfigurationManager.AppSettings["TestValue"]; Assert.IsFalse(String.IsNullOrEmpty(value), "No App.Config found."); } [TestMethod] [HostType("Moles")] public void VerifyAppDomainHasConfigurationSettingsMoles() { string value = ConfigurationManager.AppSettings["TestValue"]; Assert.IsFalse(String.IsNullOrEmpty(value), "No App.Config found."); } }