mstest

What would be an alternate to [TearDown] and [SetUp] in MSTest?

谁都会走 提交于 2019-11-27 06:10:47
When I use MSTest Framework, and copy the code that Selenium IDE generated for me, MSTest doesn't recognize [TearDown] and [SetUp] . What is the alternative to this? You would use [TestCleanup] and [TestInitialize] respectively. Keep in mind that your Initialize/Cleanup methods have to use the right signature. http://msdn.microsoft.com/en-us/library/microsoft.visualstudio.testtools.unittesting.classinitializeattribute.aspx [AssemblyInitialize()] public static void AssemblyInit(TestContext context) {} [ClassInitialize()] public static void ClassInit(TestContext context) {} [TestInitialize()]

Assert.AreEqual fails while it shouldn't

老子叫甜甜 提交于 2019-11-27 05:45:07
问题 I have a really weird behavior which I cannot explain. I have the following class: public class Project { public virtual int Id { get; set; } public virtual string Name { get; set; } } And a method which returns a Project object: public Project GetByName(string Name) { using (ISession session = NHibernateHelper.OpenSession()) { Project project = session.CreateCriteria(typeof(Project)) .Add(Restrictions.Eq("Name", Name)) .UniqueResult<Project>(); return project; } } I have added a Unit Test to

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

Gallio: Cannot run tests because the MSTest executable was not found

南楼画角 提交于 2019-11-27 04:48:39
问题 I installed the newest Gallio release 3.2.603 on a box without Visual Studio that will be our CI server. The NAnt script successfully built the .Net 4.0 projects but when it tries to run MSTest tests the following error occurs. [gallio] Gallio NAnt Task - Version 3.2 build 601 [gallio] [error] Assembly XXXXXXXXXXXXXX [gallio] Cannot run tests because the MSTest executable was not found Am I wrong to expect that Gallio is able to run MSTest tests without the MSTest executable or any other

Forcing MSTest to use a single thread

浪尽此生 提交于 2019-11-27 04:29:10
问题 Given this test fixture: [TestClass] public class MSTestThreads { [TestMethod] public void Test1() { Trace.WriteLine(Thread.CurrentThread.ManagedThreadId); } [TestMethod] public void Test2() { Trace.WriteLine(Thread.CurrentThread.ManagedThreadId); } } Running the test with MSTest through Visual Studio or command line prints two different thread numbers (yet they are run sequentially anyway). Is there a way to force MSTest to run them using a single thread? 回答1: I've fought for endless hours

Change Default MsTest Unit Test Wizard Template

不想你离开。 提交于 2019-11-27 03:35:29
问题 My team is using the unit test wizard, but has found the amount of cruft generated annoying. Is there anyway to modify this template? Thanks 回答1: Yes, you can, on several levels: Project Template You can get rid of the "About Test Projects" and other files using the Options menu in Visual Studio. Go to Test Tools -> Test Project and unselect the options you don't want. If that is not enough, you can find the project template in a folder similar to this: C:\Program Files (x86)\Microsoft Visual

How to compare Lists in Unit Testing

与世无争的帅哥 提交于 2019-11-27 03:35:05
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 } To make assertions about collections, you should use CollectionAssert : CollectionAssert.AreEqual(expected, actual); List<T> doesn't override Equals , so if Assert.AreEqual just calls Equals , it will end up using reference

Do MSTest deployment items only work when present in the project test settings file?

扶醉桌前 提交于 2019-11-27 02:41:53
I can't seem to grasp how MSTest deployment items are supposed to be configured. I have been able to get them working properly by modifying the project's test settings file, but this is less then ideal -- the deployment item configuration is separated from individual tests, and the file paths appear to be stored as absolute paths unless the files are under the solution folder. Am I not supposed to be able to add a deployment item using the [DeploymentItem] attribute on either a [TestClass] or [TestMethod] without having to create/modify a project test settings file? How do I accomplish this?

How does Visual Studio /mstest identify test projects?

本小妞迷上赌 提交于 2019-11-27 02:39:19
问题 Say (100% hypothetically) that I've accidentally added a unit test project as project type "Class library" to a VS2010 solution. I've then added the assemblies needed to run it as a Unit Test project, but MSTest won't pick up on it when I hit "Run all tests in solution". What are the criterias here? I had a couple of theories, which all have failed so far: Something in the .testsettings file (no references to any assemblies here as far as I can see) Something in the .SLN file (can't find

Where is mstest.exe located?

旧城冷巷雨未停 提交于 2019-11-27 01:43:57
问题 I need to run mstest from the command line - where in the world is this exe located? Can anyone give me a clue? Edit: I only have Visual Studio 2010 installed 回答1: for %x in (mstest.exe) do @echo.%~dp$PATH:x from the Visual Studio Command Prompt is your friend. For me it's in C:\Program Files (x86)\Microsoft Visual Studio 9.0\Common7\IDE\ 回答2: Type where mstest.exe into a Visual Studio Command Prompt... 回答3: Since Visual Studio 2012 (at least the express versions) MsTest.exe is called vstest