# "Total" count of UnitTestResult is not including nested (InnerResults) results

**URL:** <https://www.finalbuilder.com/forums/t/total-count-of-unittestresult-is-not-including-nested-innerresults-results/7228>\
**Category:** Bugs\
**Tags:** fixed\
**Created:** [May 26, 2022, 11:50am UTC](https://www.finalbuilder.com/forums/t/total-count-of-unittestresult-is-not-including-nested-innerresults-results/7228 "2022-05-26T11:50:53Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![ktopaz](https://www.finalbuilder.com/forums/user_avatar/www.finalbuilder.com/ktopaz/32/2390_2.png) [@ktopaz](https://www.finalbuilder.com/forums/u/ktopaz)\
**Post date:** [May 26, 2022, 11:50am UTC](https://www.finalbuilder.com/forums/t/total-count-of-unittestresult-is-not-including-nested-innerresults-results/7228/1 "2022-05-26T11:50:53Z")

</div>

Hi Guys,

I’ve noticed that one of our unit test seems to “fail but pass” strangely.  
After investigating: It looks as if the “Total” count of UnitTestResult - is not taking nested results into account, screenshot:

 ![image](https://www.finalbuilder.com/forums/uploads/default/original/2X/6/63e573d8edee6e5e5a597b8a238ae896660c6636.png)

There are total of 40 sections in the TRX file that was loaded.

 ![image](https://www.finalbuilder.com/forums/uploads/default/original/2X/2/232865a25d1d7415659e3e20f3cf222aa601a831.png)

11 of the 40 are nested inside other UnitTestResult sections  
As these aren’t counted for the “Total” - the Math doesn’t work:  
29 total is not equal to 36 passed +4 failed

I’m using the following expression in order to evaluate whether or not I should fail the unit test job:

> The conditional ‘$Utils.GetNumber($Build.Metrics.UnitTests.Passed$)$’ GreaterThanOrEqual ‘$Utils.GetNumber($Build.Metrics.UnitTests.CaseCount$)$’ has been evaluated to true.

This expands to:

> [If [‘36’ GreaterThanOrEqual ‘29’]]

# ===

# ===

Also (a different but possibly related issue): strangely enough:

 ![image](https://www.finalbuilder.com/forums/uploads/default/original/2X/4/41546586bb494e10095d845597ae14d244266f21.png)

The expression:

> $Stage.Metrics.UnitTests.Failed$

Does not equal zero -  
Both stages finish staged as “success”  
The 2nd stage is staged as “success” because of the Metrics.UnitTests expression that was shown above was evaluated to “True” but the stage gate condition after this stage - fails the build (as I would expect)

The thing is, although the build is shown in the UI as failed:

 ![image](https://www.finalbuilder.com/forums/uploads/default/original/2X/6/68ecead32bd01c1aeb7500dd215cc4781b9107a5.png)

The final status reported back to our GitHub server is “Successful”:

 ![image](https://www.finalbuilder.com/forums/uploads/default/original/2X/a/a2ccba3585150ffbd2365cfd8d582615c1d7bd3c.png)

The “Update Github Status” type event handler is configured this way:

 ![image](https://www.finalbuilder.com/forums/uploads/default/original/2X/b/be9af37687e87872b691dd41872ce9bf5700e819.png)  
 ![image](https://www.finalbuilder.com/forums/uploads/default/original/2X/0/05d2d74fd5bc7006c6b1fc2a50f9247a302c21f7.png)

I’d appreciate your input about both the unit test count issue and this failed but passed issue.  
Thanks!

---

<div class="post-metadata">

**Author:** ![Sparky](https://www.finalbuilder.com/forums/user_avatar/www.finalbuilder.com/sparky/32/10_2.png) [@Sparky](https://www.finalbuilder.com/forums/u/Sparky)\
**Post date:** [May 26, 2022, 12:16pm UTC](https://www.finalbuilder.com/forums/t/total-count-of-unittestresult-is-not-including-nested-innerresults-results/7228/2 "2022-05-26T12:16:16Z")

</div>

Hi Arik,

We get the total count from the `<ResultSummary>` element in the trx file, rather that counting the unit tests. So it seems that there maybe something different with how MSTest it writing the totals in your case. Which version of MSTest are you running? If you send us a copy of the trx file (either by direct message to me her to to our support email) we’ll investigate what is happening with the counts tomorrow.

Regarding the second issue, this outcome would be expected as the stage gate expression fails the build (as there are failures) but not the stage which is already in a successful state. The stage gate runs after the stage result is complete.

---

<div class="post-metadata">

**Author:** ![ktopaz](https://www.finalbuilder.com/forums/user_avatar/www.finalbuilder.com/ktopaz/32/2390_2.png) [@ktopaz](https://www.finalbuilder.com/forums/u/ktopaz)\
**Post date:** [May 26, 2022, 12:25pm UTC](https://www.finalbuilder.com/forums/t/total-count-of-unittestresult-is-not-including-nested-innerresults-results/7228/3 "2022-05-26T12:25:19Z")

</div>

Thank you Dave!  
I’ve sent you the .trx file.  
We’re using dotnet 6.0.202 to run the test in this case, with a command line that looks like this:

> Execute Program [cmd.exe /c dotnet test C:\…\Service.Test.csproj /p:IsTestProject=true --logger “trx;LogFileName=C:\CCIAgentShare\Ws\151043\Source\DevOps\Deployment\UnitTesting\Service.Test.26052022\_145303.trx”]

About the 2nd issue: only now I see that the event handler is operating in stage scope rather than in a build scope; So I understand why the passed/failed discrepancy occurred.

Could you tell me why the event handler works with a stage scope and not with the scope of the full build?  
(Just asking out of interest)

---

<div class="post-metadata">

**Author:** ![Sparky](https://www.finalbuilder.com/forums/user_avatar/www.finalbuilder.com/sparky/32/10_2.png) [@Sparky](https://www.finalbuilder.com/forums/u/Sparky)\
**Post date:** [May 26, 2022, 12:34pm UTC](https://www.finalbuilder.com/forums/t/total-count-of-unittestresult-is-not-including-nested-innerresults-results/7228/4 "2022-05-26T12:34:42Z")

</div>

> [@ktopaz](#):
>
> Could you tell me why the event handler works with a stage scope and not with the scope of the full build?  
> (Just asking out of interest)

No reason, that’s just how we it’s set up so that a stage is selected rather than a build. I guess we could add an option post at the end of the build - I’ll look into it.

What type of unit tests cause the nested UnitTestResult sections to be created? Are they parameterised tests using the `[DataTestMethod]` attribute?

---

<div class="post-metadata">

**Author:** ![ktopaz](https://www.finalbuilder.com/forums/user_avatar/www.finalbuilder.com/ktopaz/32/2390_2.png) [@ktopaz](https://www.finalbuilder.com/forums/u/ktopaz)\
**Post date:** [May 26, 2022, 1:05pm UTC](https://www.finalbuilder.com/forums/t/total-count-of-unittestresult-is-not-including-nested-innerresults-results/7228/5 "2022-05-26T13:05:13Z")

</div>

Looks like parameterized tests indeed, but using a regular old `[TestMethod]`

 ![image](https://www.finalbuilder.com/forums/uploads/default/original/2X/c/cb3c469d935f19fe9656ffbbd322b28bbeab1dc7.png)

> [@Sparky](#):
>
> I guess we could add an option post at the end of the build - I’ll look into it.

Thanks!

---

<div class="post-metadata">

**Author:** ![Sparky](https://www.finalbuilder.com/forums/user_avatar/www.finalbuilder.com/sparky/32/10_2.png) [@Sparky](https://www.finalbuilder.com/forums/u/Sparky)\
**Post date:** [May 27, 2022, 6:53am UTC](https://www.finalbuilder.com/forums/t/total-count-of-unittestresult-is-not-including-nested-innerresults-results/7228/6 "2022-05-27T06:53:19Z")

</div>

Hi Arik,

We’ve been looking at this today and there some oddities about the content of your trx file.

The counters in the `ResultSummary` appear to be counting the outer `UnitTestResult` as well as the `UnitTestResult` nodes under `InnerResults`. This means that it counts 5 tests for the test you posted in your last comment. We think that it should be 4 and that the total for the whole file should be 37 not 40.

Also when we run `dotnet test` on a .Net 6 project with parameterised tests defined in a similar way to yours, all test results are listed at the same level - there are no `InnerResults`.

We’re currently planning to ignore the `ResultSummary` counters and count the results as we iterate through the file. We hope to have a patch ready by the beginning of next week.

---

<div class="post-metadata">

**Author:** ![Sparky](https://www.finalbuilder.com/forums/user_avatar/www.finalbuilder.com/sparky/32/10_2.png) [@Sparky](https://www.finalbuilder.com/forums/u/Sparky)\
**Post date:** [May 27, 2022, 7:20am UTC](https://www.finalbuilder.com/forums/t/total-count-of-unittestresult-is-not-including-nested-innerresults-results/7228/7 "2022-05-27T07:20:51Z")

</div>

See [Extra test cases for DataRow methods · Issue #488 · microsoft/testfx · GitHub](https://github.com/microsoft/testfx/issues/488#issuecomment-1026686187). Which version of the `MSTest.TestAdapter` NuGet package is your project using?

---

<div class="post-metadata">

**Author:** ![ktopaz](https://www.finalbuilder.com/forums/user_avatar/www.finalbuilder.com/ktopaz/32/2390_2.png) [@ktopaz](https://www.finalbuilder.com/forums/u/ktopaz)\
**Post date:** [May 30, 2022, 8:19am UTC](https://www.finalbuilder.com/forums/t/total-count-of-unittestresult-is-not-including-nested-innerresults-results/7228/8 "2022-05-30T08:19:49Z")

</div>

MSTest.TestAdapter version for this test project is 2.1.1

---

<div class="post-metadata">

**Author:** ![Sparky](https://www.finalbuilder.com/forums/user_avatar/www.finalbuilder.com/sparky/32/10_2.png) [@Sparky](https://www.finalbuilder.com/forums/u/Sparky)\
**Post date:** [June 2, 2022, 10:02am UTC](https://www.finalbuilder.com/forums/t/total-count-of-unittestresult-is-not-including-nested-innerresults-results/7228/9 "2022-06-02T10:02:52Z")

</div>

The MSTest results parser in [v1.9.2.902](https://www.finalbuilder.com/forums/t/continua-ci-v1-9-2-902-released/) now counts UnitTestResult sections.
