It would be nice, in many scenarios that I can think of, to be able to set a certain test or tests as a prerequisite for other tests. I realize there is already the [SetUp] attribute and [TextFixtureSetUp] attribute, but what I'm talking about would allow more than that. Firstly, while the SetUp attributes are a prerequisite for all tests, a [Require] attribute would be much more specific. We could have a syntax similar to:
[Require: SomeFunction]
which would tell NUnit that each time, before running our current test, we need to test SomeFunction first. And, we could use multiple [Require] attributes for a single function that we're testing.
So, for instance, we could have something like:
[Test]
[Require: GrindBeans]
[Require: LoadCoffeeMaker]
public void MakeCoffee()
{
...
Assert...
}
Something like that would tell NUnit to test the functions GrindBeans() and LoadCoffeeMaker()before testing MakeCoffee(), each time MakeCoffee would be tested.
Is this intended as a partial ordering of tests in the fixture? That is, are GridBeans and LoadCoffeeMaker also tests in the same fixture?
Charlie
Yes, they would be in the same fixture. This would be two-fold, however: it would implicate partial ordering of tests, as well as, and perhaps more importantly, allowing less code redundancy. What I mean by that last part, is that a certain function that we're testing (such as MakeCoffee) might require output from another function (such as GrindBeans), and/or even might not even be possible to run if a different test doesn't even pass. An example might be something like
[Test]
[Require: DbRequest]
public void ParseData()
{
...
}
This might be a case where a) ParseData() requires data fetched by DbRequest() b) DbRequest should not go in the [SetUp] section, because it is only a prerequisite to ParseData(), c) there are several other tests in this particular fixture, and d) there would likely be times when we would want to test DbRequest() individually.
This would allow us to have less code redundancy, since we may have a complex DbRequest() function (for example), able to be tested individually, and also not have to copy code out of it to place it into our ParseData function. We could also be sure that the DbRequest() function test passes each time we test the ParseData function.
Thanks for the reply.
-Max