Why does this assert throw a format exception when comparing structures?

I’ve got it. And yes, it’s a bug. The problem is that there are two levels of string.Format going on here. The first level of formatting is something like: string template = string.Format(“Expected: {0}; Actual: {1}; Message: {2}”, expected, actual, message); Then we use string.Format with the parameters you’ve supplied: string finalMessage = string.Format(template, parameters); … Read more

VS 2010 Test Runner error “The agent process was stopped while the test was running.”

This message is caused by an exception on a thread different from the executing test thread. All answers so far boil down to this simple explanation. It is a known bug in Visual Studio not to display any sensible information in that case. Visual Studio’s test runner totally chokes if a thread other than the … Read more

MSTest copy file to test run folder

use a DeploymentItem attribute using System; using System.IO; using Microsoft.VisualStudio.TestTools.UnitTesting; using CarMaker; namespace DeploymentTest { [TestClass] public class UnitTest1 { [TestMethod()] [DeploymentItem(“testFile1.xml”)] public void ConstructorTest() { string file = “testFile1.xml”; Assert.IsTrue(File.Exists(file), “deployment failed: ” + file + ” did not get deployed”); } } }

Can I use mstest.exe without installing Visual Studio?

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 2019 Visual Studio 2017 (127MB disk space, less than that for download) Visual Studio 2015 and older: visit https://www.visualstudio.com/vs/older-downloads/ and follow the instructions This installs everything … Read more

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

FWIW, you can use the AssemblyInitialize attribute to run code before all unit tests in an assembly executes: [TestClass] public class SetupAssemblyInitializer { [AssemblyInitialize] public static void AssemblyInit(TestContext context) { // Initalization code goes here } } If you have more than one unit test assembly, I’m not aware of anything that encompasses more than … Read more