Jackson Pope
Jackson Pope

Reputation: 14640

How should I group unit tests using C# and NUnit?

I've a class with a lot of unit tests in C# (using NUnit 2.5.8) and I'd like to group the unit tests together based on which area of the class's functionality I'm testing (so I can quickly choose which set to run in the NUnit UI).

I know I could refactor the class into smaller components, which would solve the problem, but are there any other ways to do this without completely re-designing the production code?

Upvotes: 5

Views: 6027

Answers (1)

jason
jason

Reputation: 241585

Why not a [TestFixture] (separate class) for each area of functionality that you want to test?

class ClassThatDoesTooMuch {
    // functionality related to opening a database connection
    // functionality related to file management
    // functionality related to solving world hunger
}

[TestFixture]
public class ClassThatDoesTooMuchDatabaseConnectionTests { // }

[TestFixture]
public class ClassThatDoesTooMuchFileManagementTests { // }

[TestFixture]
public class ClassThatDoesTooMuchWorldHungerSolutionTests { // }

Upvotes: 12

Related Questions