mstest

How to create Startup and Cleanup script for Visual Studio Test Project?

你。 提交于 2019-12-18 03:05:14
问题 I'm using a Visual Studio Test project, am modifying the test config with deployment files, etc. (through the VS GUI) and now I need to write a Startup script for the test run. I have no clue what language or file type or mechanism is used for these scripts. Need a tip. 回答1: Create a unit test in your test project. In the unit test class, create methods with the [TestInitialize] and [TestCleanup] attributes. They will be run before/after each test method. Or, if you want to run before/after

How does Assert.AreEqual determine equality between two generic IEnumerables?

老子叫甜甜 提交于 2019-12-17 17:56:13
问题 I have a unit test to check whether a method returns the correct IEnumerable . The method builds the enumerable using yield return . The class that it is an enumerable of is below: enum TokenType { NUMBER, COMMAND, ARITHMETIC, } internal class Token { public TokenType type { get; set; } public string text { get; set; } public static bool operator == (Token lh, Token rh) { return (lh.type == rh.type) && (lh.text == rh.text); } public static bool operator != (Token lh, Token rh) { return !(lh =

MsTest ClassInitialize and Inheritance

天涯浪子 提交于 2019-12-17 15:59:23
问题 I have a base class for my tests which is composed in the following way: [TestClass] public abstract class MyBaseTest { protected static string myField = ""; [ClassInitialize] public static void ClassInitialize(TestContext context) { // static field initialization myField = "new value"; } } Now I am trying to create a new test that inherits from the base, with the following signature: [TestClass] public class MyTest : MyBaseTest { [TestMethod] public void BaseMethod_ShouldHave

How to write output from a unit test?

空扰寡人 提交于 2019-12-17 10:15:01
问题 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 is meant to be automated, but I still would like to be able to output messages from a unit test. 回答1: Try using TestContext.WriteLine() which outputs text in test results. Example: [TestClass] public class UnitTest1 { private TestContext

MSTest Equivalent for NUnit's Parameterized Tests?

我的梦境 提交于 2019-12-17 09:53:27
问题 NUnit supports a feature where you can specify a set of data inputs for a unit test to be run multiple times. [RowTest] [Row(1001,1,2,3)] [Row(1,1001,2,3)] [Row(1,2,1001,3)] public void SumTests(int x, int y, int z, int expected) { ... } What's the best way to accomplish this same type of thing using MSTest? I can't find a similar set of attributes. 回答1: Would this help? This week I was adding some unit tests to a project that is managed by TFS, so I decided to use the "core" unit testing

How to compare Lists in Unit Testing

旧街凉风 提交于 2019-12-17 07:16:12
问题 How can this test fail? [TestMethod] public void Get_Code() { var expected = new List<int>(); expected.AddRange(new [] { 100, 400, 200, 900, 2300, 1900 }); var actual = new List<int>(); actual.AddRange(new [] { 100, 400, 200, 900, 2300, 1900 }); Assert.AreEqual(expected, actual); // Assert.AreSame(expected, actual) fails // Assert.IsTrue(expected.Equals(actual)) fails } 回答1: To make assertions about collections, you should use CollectionAssert: CollectionAssert.AreEqual(expected, actual);

How to compare Lists in Unit Testing

烂漫一生 提交于 2019-12-17 07:16:06
问题 How can this test fail? [TestMethod] public void Get_Code() { var expected = new List<int>(); expected.AddRange(new [] { 100, 400, 200, 900, 2300, 1900 }); var actual = new List<int>(); actual.AddRange(new [] { 100, 400, 200, 900, 2300, 1900 }); Assert.AreEqual(expected, actual); // Assert.AreSame(expected, actual) fails // Assert.IsTrue(expected.Equals(actual)) fails } 回答1: To make assertions about collections, you should use CollectionAssert: CollectionAssert.AreEqual(expected, actual);

What's the alternative to use Thread.Sleep when working with Selenium in system testing?

社会主义新天地 提交于 2019-12-14 03:49:29
问题 I have a TestMethod using Selenium as below: [TestMethod] public void ShouldSendPasswordReminder() { // go to loginregister url _fireFoxWebDriver.Navigate().GoToUrl(UkPaBaseUrl + "loginregister.aspx"); Thread.Sleep(1000); // click the forgotten password _fireFoxWebDriver.FindElement(By.LinkText("Forgotten your password?")).Click(); Thread.Sleep(1000); // enter your email address _fireFoxWebDriver.FindElement(By.Id("PasswordResetRequest1_PasswordResetRequest_Username")) .SendKeys("username

DataSource attribute with Specflow for multiple browser testing

六眼飞鱼酱① 提交于 2019-12-14 01:13:40
问题 I have some web ui tests in C# which are executed through selenium in browserstack. Currently these are just simple unit ms tests and they are executed againts different browsers. I want to port the test to specflow, but I don't really know how to do the multiple browser testing bit. At the moment, to execute these tests in multiple browsers I am using a DataSource attribute, which basically takes different inputs for the same tests from an XML file [TestMethod] [Ignore] [DeploymentItem("JLL

How do you create a unit test assembly for a .NET Portable Class Library?

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-14 00:42:59
问题 I am attempting to unit test a Portable Class Library that I've created and I want to make sure it's being tested with the same framework subset that it targets. Per the Visual Studio ALM + Team Foundation Server blog, the MSTest unit test framework was converted to a PCL in Visual Studio 2012 RC; however, I am unable to create a portable class library and then reference the MSTest framework in VS2012 RTM. Browsing in the "References" dialog shows me that no unit testing components are