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?
The most scalable way to write unit tests in C is using a unit testing framework, such as: CppUTest. Unity. Google Test.
Good unit tests should be reproducible and independent from external factors such as the environment or running order. Fast. Developers write unit tests so they can repeatedly run them and check that no bugs have been introduced.
The general rule for unit tests is to test the smallest possible piece that you can test. A good rule is that each test should exercise exactly a single method from a public API. That means it should only execute this method and no other, not even transiently.
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 { // }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With