mstest

Mstest name instead Data Row with Data-Driven testing

我是研究僧i 提交于 2019-12-04 07:47:43
I use MsTests and Data Driven approach for testing. (Excel is data storage for tests) tests result dont provide any information about tests data. For example: Result look as: testname (Data row 5). And it is not clear for me. How can i customise output test result? For example testname (Test data (word, number, or row named)) I found only one solution: I have MyData.xlsx file with 1000 rows. Simple logic: "A" column = 1, "B" column = A*2+2. Rows 5,6,7 and 11,12,13 conteins zero for make a failed results. SourceCode of my Test: public TestContext TestContext { get; set; } [TestMethod]

MsTest, DataSourceAttribute - how to get it working with a runtime generated file?

时光毁灭记忆、已成空白 提交于 2019-12-04 06:47:43
for some test I need to run a data driven test with a configuration that is generated (via reflection) in the ClassInitialize method (by using reflection). I tried out everything, but I just can not get the data source properly set up. The test takes a list of classes in a csv file (one line per class) and then will test that the mappings to the database work out well (i.e. try to get one item from the database for every entity, which will throw an exception when the table structure does not match). The testmethod is: [DataSource( "Microsoft.VisualStudio.TestTools.DataSource.CSV", "

Selenium C# Mstest - chromedriver.exe does not exist. Getdirectory() referring some-other directory while executing vis mstest commands

北城余情 提交于 2019-12-04 06:39:13
问题 when i'm running the selenium test from VS2017 it is able to pick the drivers successfully BUT when i run the same test using mstest command - internally it is referring some other directory! C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\Common7\IDE\mstest.exe/ testcontainer:..\Test\Sun.TestAutomation.dll /test:"myfristtest" /resultsfile:..\Test\TestResultLog.trx //Mstest commands OpenQA.Selenium.DriverServiceNotFoundException: OpenQA.Selenium.DriverServiceNotFoundException

how do you mock an xml for unit testing?

和自甴很熟 提交于 2019-12-04 06:38:00
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"); MsgResponse.Error = true; return MsgResponse; } return MsgResponse; } this method needs a XmlElement parameter.

MStests taking too long to load

那年仲夏 提交于 2019-12-04 06:36:20
问题 I have a project setup to use MSTests but they are simply taking too long to load all the the test DLLs, before even loading my project specific DLLs. I´m on Visual Studio Professional 2015 with Resharper 10.0.1 I´m attaching only part of the the logs down here since stack overflow complaint about limit, but it would be 10 times as bigger, following the same line of these dlls. The total time was around 30s, before my dlls started being loaded, but only a couple of acceptable seconds

MSTest TestMethod Dependency Injection

徘徊边缘 提交于 2019-12-04 06:11:44
I'm using a DI container and I want to do MSTest (VS 2010) unit tests with instances resolved from the container. I'd like to get these instances injected into my TestMethod or at least my TestClass. Is this possible? Right now my TestMethods directly call container.Resolve<T>(xxx) which I'd prefer to avoid so that my injection testing is more realistic. Anyone have experience with this? Thanks in advance. The instantiation of the test class happens deeply in the internal classes of the MSTest framework so injecting dependencies into it would be a challenging task. Steven The main reason -for

How can I pass property as parameter in MSTest DataRow

匆匆过客 提交于 2019-12-04 05:12:16
问题 I have a DataTestMethod in my unit test using MSTest, and I have a string property in my constructor, let's say I have this code for example: [DataTestMethod] [DataRow("test")] [DataRow(stringproperty)] // How is this? public void TestMethod(string test) { Assert.AreEqual("test", test); } Is it possible to pass a property as parameter in DataRow? Thanks. 回答1: Yes if you use the DynamicDataAttribute [DynamicData("TestMethodInput")] [DataTestMethod] public void TestMethod(string test) { Assert

Repeat mstest test run multiple times

大城市里の小女人 提交于 2019-12-04 03:58:35
Some of my mstest unit tests help detect multi-threading race conditions, and as such they are most useful when run many times in a row, but I only want to do this for specific test runs -- not all the time. Is there a way to configure mstest (in the Test List Editor preferably) to run a test multiple times? I needed to do something similar, so I came up with a solution to this. It's not simple, but once everything is setup you can reuse it across projects. I also have a download of this code on GitHub ( https://github.com/johnkoerner/MSTestLooper ), but in case that goes away at some point,

Unit Test Assert.AreEqual failed

独自空忆成欢 提交于 2019-12-04 03:09:16
问题 I have a unit test for a method which gets an object from a collection. This keeps failing and I cannot see why, so I have created a very simple test below to create 2 supplier object and test they are equal to see if I can spot the problem in my test of my code. But this test again is failing. Can anyone see or explain why? [TestMethod()] public void GetSupplierTest2() { Supplier expected = new Supplier(); expected.SupplierID = 32532; expected.SupplierName = "Test 1" Supplier actual = new

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

坚强是说给别人听的谎言 提交于 2019-12-04 03:01:21
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<string>()), Times.Once); } The key here being the DataRow property found in TestContext. This doesn't