Search code examples
nunit

What sets, and how to control the "id" attribute in an NUnit result file "test-run" element?


I see that the first element in an NUnit testresult.xml file is "test-run", and it has an "id" attribute, such as the following example:

<?xml version="1.0" encoding="utf-8" standalone="no"?>
<test-run id="0" runstate="Runnable" testcasecount="3" result="Failed" total="3" passed="1" failed="2" warnings="0" inconclusive="0" skipped="0" asserts="1" engine-version="3.16.3.0" clr-version="4.0.30319.42000" start-time="2023-09-04 01:10:14Z" end-time="2023-09-04 01:10:15Z" duration="0.848207">

What sets the "id" attribute? It seems to be 0 every time I run a test using nunit3-conosole.exe. Is it possible to control this attribute?


Solution

  • An NUnit test may be an individual test case, or a test suite. There are various kinds of suites representing things like Assemblies, namespaces, test fixture classes, etc. The important thing is that they are all reported as tests.

    Every test in a given execution has has a unique string id. NUnit uses them to keep track of how each test and to index them internally. The single top-level test-run element, which is created by the console runner itself, is always "0".

    NUnit doesn't allow you to control test ids. If it did, you would be able to completely confuse the internal operation of the software. You can however give the tests any name you want and even give the same name to multiple tests. This will confuse you of course but it won't confuse NUnit, which uses the ids rather than your name. :-)