Where should I place code that should only run once (and not once per class)? An example for this would be a statement that initializes the DB connection string. And I only need to run that once and I don't want to place a new method within each "TestFixture" class just to do that.
+6
A:
The [SetupFixture] attribute allows you to run setup and/or teardown code once for all tests under the same namespace. If that is not sufficient (i.e. you have multiple namespaces for your tests), you could always define a static class strictly for the purpose of defining "global" test variables.
Here are the docs on SetupFixture:
Ben Hoffstein
2010-07-06 16:57:21
that is exactly what I was looking for, thanks :)
a b
2010-07-09 00:46:50
+1
A:
Create a class (I call mine Config) and decorate it with the [SetUpFixture]
attribute. The [SetUp]
and [TearDown]
methods in the class will run once.
[SetUpFixture]
public class Config
{
[SetUp]
public void SetUp()
{
}
[TearDown]
public void TearDown()
{
}
}
Jamie Ide
2010-07-06 16:58:56