NUnit – test performance time on your method

Possibly save 1 hour of your time: There will be times you want to write some integration unit tests that hit the database to test performance.

One easy way to impose the maximum time in milliseconds on the unit test is using the MaxTime property available on NUnit and can be done as follows:

 [Test, MaxTime(2000)]
public void YourMethod()

Tip: You might also want to do an initial call to your database in OneTimeSetup to simulate first request will take longer time.

[OneTimeSetUp]
public void OneTimeSetUp()
{

// do a call to database to simulate that first request will take longer time

}

 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

w

Connecting to %s