mstest

TestInitialize vs ClassInitialize

夙愿已清 提交于 2019-11-27 11:52:30
What is the difference between TestInitialize vs ClassInitialize in MSTest? What are the pros cons of each? I'm under the impression that TestInitialze should run with EACH test, every time? Is that correct? And that ClassInitialize will run every time a new instance of any class? Both attributes are available only for the classes (and hence tests) where they belong. TestInitialize runs before every test that is declared on the the same class where the attribute is declared. ClassInitialize runs only on the initialization of the class where the attribute is declared. In other words it won't

Running unit tests on Team Foundation Server (TFS) builds

柔情痞子 提交于 2019-11-27 11:47:31
问题 What are the steps to get Team Foundation Server running unit tests when a given build runs? What are the caveats / pitfalls / workarounds a dev or sysadmin should be aware of when setting up a TFS server to do this for the first time? What are common troubleshooting steps for unit test problems during builds? 回答1: it depends on which version of TFS you are running, so I will assume it is 2008. Firstly, you must have Team Edition for Testers installed on the computer that will act as your

Integrating Hudson with MS Test?

倾然丶 夕夏残阳落幕 提交于 2019-11-27 11:17:30
问题 Is it possible to integrate Hudson with MS Test? I am setting up a smaller CI server on my development machine with Hudson right now, just so that I can have some statistics (ie. FxCop and compiler warnings). Of course, it would also be nice if it could just run my unit tests and present their output. Up to now, I have added the following batch task to Hudson, which makes it run the tests properly. "%PROGRAMFILES%\Microsoft Visual Studio 9.0\Common7\IDE\MSTest.exe" /runconfig:LocalTestRun

Can I use mstest.exe without installing Visual Studio?

偶尔善良 提交于 2019-11-27 10:14:15
I want to use mstest.exe to run my unit test on build server, but I don't want to install Visual Studio on the build server. Can I just install MSTest without Visual Studio? Bela It is possible to run mstest.exe without visual studio. Download one of the Agents for Visual Studio ISO's below and install the Test Agent on the server: Visual Studio 2017 (127MB disk space, less than that for download) Visual Studio 2015 (128MB setup, 2GB disk space required) Visual Studio 2012 (224MB) Visual Studio 2013 (287MB) Visual Studio 2010 (515MB) This installs everything needed for running mstest.exe from

Is it possible to execute code once before all tests run?

不羁的心 提交于 2019-11-27 09:54:31
问题 Basically I would like to tell MSTest to execute a bit of code before launching into a series of test runs, essentially what I would like to do is the same thing as sticking some code in Main() . The reason I would like to do this is that I would like to do some logging with log4net during my integration test runs. I cannot just use the log4net.Config.XmlConfigurator assembly attribute since by the time it reads it in my test assembly it has already called LoggerManager . The documentation

MSTest Equivalent for NUnit's Parameterized Tests?

試著忘記壹切 提交于 2019-11-27 09:11:07
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. 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 framework available with VS2008, and unfortunately it doesn't support RowTests. But it has a similar feature

No Code Coverage Information for Tests Using Moles

随声附和 提交于 2019-11-27 08:56:27
问题 I have been getting used to OpenCover over the past few days, and have I noticed that tests using Moles do not generate any Coverage information. I have created a small solution to isolate the problem, and have found that code coverage is generated only for tests that do not have the [HostType("Moles")] attribute. Reading around I have found this and this which seem to be NCover equivalents of my problem. They say that it is something to do with Moles running a profiler as well as the

Mocking a TempData in ASP.NET Core in MSTest

家住魔仙堡 提交于 2019-11-27 08:08:26
问题 public ActionResult View(string name) { if (TempData["SessionVariable"] != null) { FileName = name; return View(); } else { return RedirectToAction("index", "Home"); } } TestMethod public void UseCaseView_CorrectRequirements() { var mock = new Mock<Controller>(); mock.Setup(p => p.TempData["SessionVariable"]).Returns("admin"); Controller.View("SAMPLE.xml"); } It throws an error such as , Result StackTrace: at Moq.Mock.ThrowIfSetupExpressionInvolvesUnsupportedMember(Expression setup,

Running Universal Windows unit tests from the command line

十年热恋 提交于 2019-11-27 07:29:00
How do you run Universal Windows (UWP) unit test projects from the command line? I am using the MSTestFramework. Short answer: vstest.console.exe /Platform:x64 AppPackages\UnitTestProject1_1.0.0.0_x64_Debug_Test\UnitTestProject1_1.0.0.0_x64_Debug.appx Long answer: Create the project by selecting Universal / Unit Test App (Universal Windows) template: Build it with command line using in the folder where the solution file is msbuild /p:Platform=x64;Configuration=Debug Try running the vstest.console.exe command above, in the short answer. It will fail, giving the following error message: error

Where is the “Create Unit Tests” selection?

别说谁变了你拦得住时间么 提交于 2019-11-27 06:11:49
I have installed the new Visual Studio 2012 Ultimate. I have created a Test Project with my solution and it contains some default unit tests. However right clicking on new Methods doesn't show the "Create Unit Tests" context menu any longer. See Visual Studio 2010 Ultimate: And Visual Studio 2012 Ultimate: Any idea why that could be? UPDATE: Solution for Visual Studio 2012 and 2013: Microsoft has acknowledged it here and offers an official work around patch to fix it. Download, install and Enjoy! This feature was cut from VS. http://blogs.msdn.com/b/visualstudioalm/archive/2012/03/08/what-s