Sequential testing runs integration tests one after another, keeping only one test active at a time. It reduces interference when tests share a database and makes leftover-data cleanup more manageable. section 10.3
Use sequential execution when:
- Tests share one database instance and could violate constraints or consume each other’s data when parallelized. section 10.3
- The performance gain from parallel execution does not justify unique test data, more complicated cleanup, and additional maintenance. section 10.3
- Keep test state independent by clearing leftover data and having each test establish its required database state. section 10.3
Listing 10.6. Base class for integration tests
public abstract class IntegrationTests
{
private const string ConnectionString = "...";
protected IntegrationTests()
{
ClearDatabase();
}
private void ClearDatabase()
{
string query =
"DELETE FROM dbo.[User];" + #1
"DELETE FROM dbo.Company;"; #1
using (var connection = new SqlConnection(ConnectionString))
{
var command = new SqlCommand(query, connection)
{
CommandType = CommandType.Text
};
connection.Open();
command.ExecuteNonQuery();
}
}
}
A base integration-test class clears database tables before each test, providing a concrete sequential-execution setup. section 10.3
