Typically, (unit) tests should be independent and work on their own, however, in system testing we face different requirements. For example, I am implementing a test for a setup. Standard functionality is (1) install, (2) repair and (3) uninstall. Obviously, repair and uninstall cannot be run independently of install. Therefore, NUnits Order attribute comes in handy to run install first, followed by repair and then uninstall.
The setup creates a log file for each step and I test that log for different error and/or success messages. I implemented a data driven test which I would like to call after each functionality. Since the other tests have to run in a specific order, I cannot call the test multiple times.
The only solution I have is to take the logic of that test into a class and call that class at the end of each test. This, however, does not allow for a data driven test case that appears in the results. I am wondering if there is any smarter solution to avoid my current code duplication?
Some pseudo code illustrating my issue:
[TestFixture, Category("Setup"), Order(1)]
public class InstallTest
{
[Order(1), Test]
public void Install()
{
//Install
}
//Duplicated log file test code
[Order(2)]
[TestCase("...")]
[TestCase("...")]
public void CheckLogFile()
{
//log file test code
}
}
[TestFixture, Category("Setup"), Order(2)]
public class Repair
{
[Order(1), Test]
public void Uninstall()
{
//Uninstall
}
//Duplicated log file test code
[Order(2)]
[TestCase("...")]
[TestCase("...")]
public void CheckLogFile()
{
//log file test code
}
}
[TestFixture, Category("Setup"), Order(3)]
public class UninstallTest
{
[Order(1), Test]
public void Uninstall()
{
//Uninstall
}
//Duplicated log file test code
[Order(2)]
[TestCase("...")]
[TestCase("...")]
public void CheckLogFile()
{
//log file test code
}
}