Created
October 25, 2011 16:22
-
-
Save gbHeadspring/1313334 to your computer and use it in GitHub Desktop.
Sample code for demonstrating the use of NUnit SetUpFixture classes
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Dropping Database. | |
Rebuild Database with latest Schema. | |
Load basic test environment data. | |
Loading basic account data. | |
Opening outer Transaction scope | |
Executing test 1. | |
Executing test 2. | |
Roll back transaction scope. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using NUnit.Framework; | |
[SetUpFixture] | |
public class TestSuiteInitializer : IDisposable | |
{ | |
public TestSuiteInitializer() | |
{ | |
Console.WriteLine("Constructing TestSuiteInitializer."); | |
} | |
[SetUp] | |
public void SetUp() | |
{ | |
Console.WriteLine("Setting up TestSuiteInitializer."); | |
} | |
[TearDown] | |
public void TearDown() | |
{ | |
Console.WriteLine("Tearing down TestSuiteInitializer."); | |
} | |
public void Dispose() | |
{ | |
Console.WriteLine("Disposing TestSuiteInitializer."); | |
} | |
} | |
namespace SetUpFixtureSample | |
{ | |
[SetUpFixture] | |
public class NamespaceInitializer : IDisposable | |
{ | |
public NamespaceInitializer() | |
{ | |
Console.WriteLine("Constructing NamespaceInitializer ."); | |
} | |
[SetUp] | |
public void SetUp() | |
{ | |
Console.WriteLine("Setting up NamespaceInitializer ."); | |
} | |
[TearDown] | |
public void TearDown() | |
{ | |
Console.WriteLine("Tearing down NamespaceInitializer ."); | |
} | |
public void Dispose() | |
{ | |
Console.WriteLine("Disposing NamespaceInitializer ."); | |
} | |
} | |
[TestFixture] | |
public class SimpleTests | |
{ | |
[Test] | |
public void Test() | |
{ | |
Console.WriteLine("Executing test."); | |
} | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Constructing TestSuiteInitializer. | |
Setting up TestSuiteInitializer. | |
Constructing NamespaceInitializer . | |
Setting up NamespaceInitializer . | |
Executing test. | |
Tearing down NamespaceInitializer . | |
Disposing NamespaceInitializer . | |
Tearing down TestSuiteInitializer. | |
Disposing TestSuiteInitializer. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using NUnit.Framework; | |
[SetUpFixture] | |
public class DatabaseInitializer | |
{ | |
public DatabaseInitializer() | |
{ | |
Console.WriteLine("Dropping Database."); | |
Console.WriteLine("Rebuild Database with latest Schema."); | |
Console.WriteLine("Load basic test environment data."); | |
} | |
} | |
namespace SetUpFixtureSample.DatabaseTests | |
{ | |
[SetUpFixture] | |
public class DatabaseWithBasicAccountsInitializer: IDisposable | |
{ | |
public DatabaseWithBasicAccountsInitializer() | |
{ | |
Console.WriteLine("Loading basic account data."); | |
Console.WriteLine("Opening outer Transaction scope"); | |
} | |
public void Dispose() | |
{ | |
Console.WriteLine("Roll back transaction scope."); | |
} | |
} | |
[TestFixture] | |
public class BasicAccountTester1 | |
{ | |
[Test] | |
public void Test() | |
{ | |
Console.WriteLine("Executing test 1."); | |
} | |
} | |
[TestFixture] | |
public class BasicAccountTester2 | |
{ | |
[Test] | |
public void Test() | |
{ | |
Console.WriteLine("Executing test 2."); | |
} | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using NUnit.Framework; | |
namespace SetUpFixtureSample | |
{ | |
[TestFixture] | |
[Explicit] | |
[Category("DataLoader")] | |
public class DataLoaderFixture | |
{ | |
[Test] | |
public void LoadData() | |
{ | |
//Clean the database | |
//Load test data into the database | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment