Possible Duplicate:
What would be an alternate to [SetUp] and [TearDown] in MSTest?
I'm learning how to use Unit Testing and automated testing in general and have a few questions I can't figure out/find the answer to
I currently test by having multiple [TestMethod]s that call various methods and have asserts in them. Right now the TestMethod's all have duplicate code to hit a DB and set themself up for the rest of the test. An example is:
public void TestDBReturnsFooInFormatXyz() {
var foo = HitDBAndReturnStuff();
Assert.IsTrue( // foo format is xyz );
}
public void TestDBFooContainsAbc() {
var foo = HitDBAndReturnStuff();
Assert.IsTrue( // foo contains abc );
}
So some questions: Is it a best practice to make private fields in a test class and have the constructor set them?
Should I do it in each TestMethod because testing speed doesn't matter that much?
What [Test???] do I put on top of the constructor to make sure it gets called when running tests?
I've looked at MSDN and the book "Programming Microsoft Visual C# 2008: The Language" and I can't find any good information on unit testing. If there is a resource I should have read which answers these questions just let me know.
Thanks!