3

I am aware that there is already a similar question here, but I think my problem is sufficiently different to warrant creating a new post.

I use CAKE 0.21.1.0.

As a build step on TeamCity, I am executing build.ps1, which in turn invokes build.cake. In the build.cake script, I have added a task called RunTests, which uses the VS Test Runner to execute my unit tests.

Currently, whenever there are failed tests, all I see is Exit code 1 on the TeamCity main page:

enter image description here

When I navigate to view the build log itself, I see more details about the failed tests:

enter image description here

In the screenshot above, I have highlighted the text output that I would like to display on the TeamCity main page as part of the project's summary, instead of Exit code 1.

How can I capture the VS Test Runner output, so that I can include it as part of my build script's interaction with TeamCity?

UPDATE:

Thank you @mholo65 for his reply! I tried the first approach that he outlined, but unfortunately it did not work for me.

I modified my build.cake script to include these lines:

VSTest("./**/bin/Release/CakeTest.dll", new VSTestSettings() { Logger = "trx"} );
TeamCity.ImportData("vstest", "./TestResults/*.trx");

When running the tests on my TeamCity build agent, this is my working/checkout directory:

enter image description here

And this is the full path to my results file:

enter image description here

However, this is still what I see on the TeamCity main page, instead of the VSTest output Total tests: 5. Passed: 3. Failed: 2. Skipped: 0.:

enter image description here

M.Y. Babt
  • 2,733
  • 7
  • 27
  • 49

1 Answers1

4

You have two options.

  1. Have vstest.console.exe to output the test results to trx format and import that in TeamCity. I.e. set VSTestSettings.Logger to "trx" and then import using TeamCity.ImportData("vstest", "TestResults\the_name_of_the_result_file.trx"). The path to the trx file MUST be relative to the checkout directory see this for more information. The caveat here is that it is not possible (unlike MSTest.exe) to tell vstest.console.exe where to place the trx file (see this for more info).
  2. Download and install the custom VSTestLogger on your build agent from here and set VSTestSettings.Logger to "TeamCity". This option will give you real-time reporting when running Unit Tests.
bjorkstromm
  • 423
  • 2
  • 5
  • Thank you very much for your reply! I tried your first approach, but unfortunately that did not work for me. I have updated my post to include what steps I took, and what the end-result was. Will you kindly take a look and give me some feedback? Much appreciated! – M.Y. Babt Aug 24 '17 at 09:31
  • 1
    Sorry for the late reply. You can't create a `FilePath` from a glob pattern, instead you need to do something like this: `var testResult = GetFiles("./TestResults/*.trx").FirstOrDefault(); TeamCity.ImportData("vstest", "./TestResults/" + testResult.GetFilename());` – bjorkstromm Aug 28 '17 at 18:49
  • Also, check your TeamCity logs. It should say something like `##teamcity[importData type='vstest' path='TestResults/foobar.trx']` and `Importing data from 'TestResults/foobar.trx' (291.39 KB) with 'vstest' processor` – bjorkstromm Aug 28 '17 at 18:57