简体   繁体   中英

How to lay out my integration tests

I have a rather large set of integration tests developed in C#/NUnit. Currently it is one test fixture, one class. In [TestFixtureSetUp] I create a database from a script and populate it with test data, also from a script. My tests do not modify data, so they can run in any order or in parallel.

My problem is that I have too many tests and the file is growing too big, so it looks ugly, and my ReSharper is getting sluggish. I want to split the file, but I really want to create my test database only once. As a temporary measure, I am moving the code which does actual testing into static methods in other classes, and invoke them from a single TextFixture class, as follows:

[Test]
public void YetAnotherIntegrationTest()
{
    IntegrationTestsPart5.YetAnotherIntegrationTest(connection);
}

Yet it still looks ugly and I think there should be a better way.

I am using VS 2008, upgrading to 2010 right now, and SQL Server 2005.

You could split your test class into several partial classes across mutliple files. This way you can keep one [TestFixtureSetup] and split the file up for cleanliness.

You could consider wrapping your database connection in a sigleton class, which would initialize the database while creating the singleton instance. Then you can have as many test classes as you like, just grab the db connection from the singleton.

I'm creating base class containing Setup method. Then You just inherit from it and don't have to call anything to setup database in any of the test classes.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM