Determining currently executing test case by Nunit
Asked Answered
C

2

5

I am using Cruisecontrol for building code and executing ~200 test cases.

Sometimes the build gets hung due to some of the test cases and I am not able to determine which test case it is.

Is it possible to print the name of the currently executing test case without modifying the current test case code?

If yes, how?

Chiachiack answered 11/4, 2012 at 6:23 Comment(0)
C
3

TestContext.CurrentContext.Test.Name will help in identifying the currently executing test case. Putting

Console.WriteLine("Currently Executing Test Case : " + TestContext.CurrentContext.Test.Name);

in method with SetUp attribute will print the UT currently executing.

Chiachiack answered 7/1, 2013 at 12:19 Comment(0)
S
4

I'm assuming you are using NUnit to do your tests. If so, instead of using the <nunit> block in the CruiseControl config, use the <exec> task. In the <buildArgs> element, include the /labels command line argument. This will print the info to the server log.

Instead of using:

<nunit>
    <path>C:\Program Files (x86)\NUnit 2.5.10\bin\net-2.0\nunit-console.exe</path>
    <assemblies>
        <assembly>C:\Projects\Personal\MyTestApp\MyTestApp.Tests\bin\Debug\MyTestApp.Tests.dll</assembly>
    </assemblies>
</nunit>

Use:

<exec>
    <executable>C:\Program Files (x86)\NUnit 2.5.10\bin\net-2.0\nunit-console.exe</executable>
    <buildArgs>/labels C:\Projects\Personal\MyTestApp\MyTestApp.Tests\bin\Debug\MyTestApp.Tests.dll</buildArgs>
</exec>

I know it isn't ideal, but it will print each test as it runs to the log. You can then use the merge task to merge the xml file output by nunit into your build log.

Try doing this using the ccnet console application first, so you can see the output in real time. It should help you see what you are looking for.

It might also be good to submit a patch to CruiseControl to add the following line to the "project\core\tasks\NUnitArgument.cs" file:

line: 53            argsBuilder.AddArgument("/labels");

Or you could just add that line, build CruiseControl and use your own version.

Shroudlaid answered 25/4, 2012 at 16:18 Comment(0)
C
3

TestContext.CurrentContext.Test.Name will help in identifying the currently executing test case. Putting

Console.WriteLine("Currently Executing Test Case : " + TestContext.CurrentContext.Test.Name);

in method with SetUp attribute will print the UT currently executing.

Chiachiack answered 7/1, 2013 at 12:19 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.