MsTest – executing method before each test in an assembly

[TestInitialize()] is what you need. private string dir; [TestInitialize()] public void Startup() { dir = Path.GetTempFileName(); MakeDirectory(ssDir); } [TestCleanup()] public void Cleanup() { ss = null; Directory.SetCurrentDirectory(Path.GetTempPath()); setAttributesNormal(new DirectoryInfo(ssDir)); Directory.Delete(ssDir, true); } [TestMethod] public void TestAddFile() { File.WriteAllText(dir + “a”, “This is a file”); ss.AddFile(“a”); … } [TestMethod] public void TestAddFolder() { ss.CreateFolder(“a/”); … } … Read more

Microsoft unit testing. Is it possible to skip test from test method body?

You should not skip test this way. Better do one of following things: mark test as ignored via [Ignore] attribute throw NotImplementedException from your test write Assert.Fail() (otherwise you can forget to complete this test) remove this test Also keep in mind, that your tests should not contain conditional logic. Instead you should create two … Read more