mstest

MSTest & AppDomains

偶尔善良 提交于 2019-11-30 01:42:17
问题 In some my project I notice that during executing unit tests under VSTS2008 its VSTestHost's memory consuming grows. As I have very many tests in my solution it leads to OutOfMemroyException eventually. That looks very strange for me as I was sure that MSTest creates a new AppDomain for each unit test. Otherwise how would it reset static fields? But if AppDomain is being created for each test than memory shouldn't leak. But it does. So the question is: Should VS create AppDomain for each test

Why MSTest does not copy referenced project libraries?

 ̄綄美尐妖づ 提交于 2019-11-30 01:15:20
问题 I have a Visual Studio solution with a C# dll project. This solution has also a test project which references the output of the C# dll project. The referenced project dll has set Copy Local = true. If I run this test from the Visual Studio, it works fine. But if I run it from the MSBuild task, for some reason MSTest does not copy the referenced C# dll to the MSTest working folder, so the test fails. The weird thing is, that all the other referenced libaries are copied to the MSTest working

Inherited test class from generic base is ignored in MSTest

梦想的初衷 提交于 2019-11-30 00:50:42
问题 When creating a generic base test class in MSTest, and inheriting from it, I'm unable to run the tests of all the inheriting classes. BaseDependencyPropertyFactoryTest is located in the Whathecode.PresentationFramework.Tests assembly. It is the generic base class. ( BaseDependencyPropertyFactoryTest<TTestClass> ) Both assemblies have a test inheriting from this base class, called DependencyPropertyFactoryTest . All the inherited class does is passing a specific type argument. [TestClass]

MSTEST PrincipalPermission

三世轮回 提交于 2019-11-30 00:32:29
问题 How do you unit test code decorated with the PrincipalPermission attribute? For example, this works: class Program { static void Main(string[] args) { AppDomain.CurrentDomain.SetPrincipalPolicy(PrincipalPolicy.WindowsPrincipal); var c = new MyClass(); } } [PrincipalPermission(SecurityAction.Demand, Role = @"BUILTIN\Users")] class MyClass { public MyClass() { Console.WriteLine("This works."); } } This throws a SecurityException: [TestClass] public class UnitTest1 { [TestInitialize] public void

MSTest: No tests are run because no tests are loaded or the selected tests are disabled

时间秒杀一切 提交于 2019-11-29 23:28:17
I have a c# solution with the following structure: mySolution myProject myProject.MSTests References Microsoft.VisualStudio.QualityTools.UnitTestFramework sutMSTests.cs sutMSTests.cs: [TestClass()] public class sutMSTests { [TestMethod] public void MyTest0() { Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AreEqual(4, 2 + 2); } } When I try to run the tests via Test, Run, All Tests In Solution, I get the following on the VS2008 status line: No tests are run because no tests are loaded or the selected tests are disabled. Test, Windows, Test View shows no tests. Note: I created the tests

Global test initialize method for MSTest

好久不见. 提交于 2019-11-29 22:38:55
Quick question, how do I create a method that is run only once before all tests in the solution are run. driis Create a public static method, decorated with the AssemblyInitialize attribute. The test framework will call this Setup method once per test run: [AssemblyInitialize()] public static void MyTestInitialize(TestContext testContext) {} For TearDown its: [AssemblyCleanup] public static void TearDown() {} EDIT: Another very important detail: the class to which this method belongs must be decorated with [TestClass] . Otherwise, the initialization method will not run. 来源: https:/

Are multiple asserts bad in a unit test? Even if chaining?

a 夏天 提交于 2019-11-29 22:10:51
Is there anything wrong with checking so many things in this unit test?: ActualModel = ActualResult.AssertViewRendered() // check 1 .ForView("Index") // check 2 .WithViewData<List<Page>>(); // check 3 CollectionAssert.AreEqual(Expected, ActualModel); // check 4 The primary goals of this test are to verify the right view is returned (check 2) and it contains the right data (check 4). Would I gain anything by splitting this into multiple tests? I'm all about doing things right, but I'm not going to split things up if it doesn't have practical value. I'm pretty new to unit testing, so be gentle.

Is there anything I can do in NUnit that I can't do in MSTest?

半城伤御伤魂 提交于 2019-11-29 21:20:33
This question has been asked in various forms in a number of different forums, but, IMHO, I haven't been able to find a place where it's really answered clearly, so I'm going to reframe it and ask it again. I work in a basically Microsoft Shop. We use TFS, and all of our developers have MSDN subscriptions including the Team Suite edition of VS. So we have access to MSTest. I've read the various NUnit vs. MSTest comparisons, and the developer community seems to pretty much overwhelmingly choose NUnit. But the reasons given don't ever seem to be overwhelming or compelling, at least to our

How to set up LocalDb for unit tests in Visual Studio 2012 and Entity Framework 5

杀马特。学长 韩版系。学妹 提交于 2019-11-29 20:50:21
We have a Visual Studio 2012 ASP.NET MVC project using Entity Framework 5. There are some unit tests that depend on a database. Setting up the app.config file in the test project to use a central SQL Server database works fine. However, it would be much nicer to use a LocalDb, so that each developer has his/her own database when running the tests. Especially since we would like to have the tests set up to DropCreateDatabaseAlways when running. However, I can't get the setup to work. If I try this in app.config: <add name="TestDb" connectionString="Data Source=(LocalDb)\v11.0;Initial Catalog

MSTest run fails because source assembly is not trusted

故事扮演 提交于 2019-11-29 20:23:31
I just added xUnit to our test project (for the Asserts, we're still using MSTest as the framework) and immediately the test runs refused to execute any of the tests. This is the error message: Failed to queue test run '{ .... }' Test run deployment issue: The location of the file or directory '...xUnit.dll' is not trusted. It took me a few tries to find the answer in Google, so I'm putting it here in case anyone else runs into the same problem. A detailed description can be found at this blog posting . Basically, the fix invovles right-clicking on the dll file (xunit.dll for example) in