J4N
J4N

Reputation: 20717

How to get the execution time of Nunit tests including the setup time?

We are in the process of running our tests on each pull request. Currently, our tests takes around ~2h30, which is a bit too long for us, especially taking in account that we will only have 2 machine in parallel to execute the tests of 10 people.

So we were thinking about running the more "expensive" tests only once a week and don't block the pull requests on this. Not ideal, but already a progress.

The issue is that apparently the time we have the strong impression that in visual studio and azure devops are time of the test method itself, not including the OneTimeSetup and Setup methods(and their TearDown counterparts). At least the running time is longer that what it's displayed(we get some 10seconds of executions when no test has been done in the last 1 min).

How to get those time included? Either in visual studio or through the command line?

Tests are executed with Visual studio + NUnit test adapter.

I

Upvotes: 2

Views: 1330

Answers (1)

Charlie
Charlie

Reputation: 13706

NUnit reports the time taken in it's XML result output.

For Test cases, the time reported is that of SetUp + TestMethod + TearDown. BTW, traditionally, frameworks using the xunit pattern have called the above the "test", while the method alone is called the "bare test".

OneTimeSetUp and OneTimeTearDown are not associated with a particular test case but with the class that contains the cases. If you use NUnit SetUpFixtures, they also have an execution time associated with them.

You can fish all these details out of the XML file by browsing it or write a report using whatever language you prefer. If most of your time-consuming setups are located in the TestFixtures (either directly or via a base class) I recommend starting with a list of each fixture's time. OTOH, if you have relocated the expensive operations into separate SetUpFixtures, start with those by listing the total time taken by namespace.

Upvotes: 2

Related Questions