Pipeline Tasks - Is that possible to publish the Error Message and Stack Trace from c# code

Nadeem Bader 21 Reputation points
2021-02-13T16:53:56.877+00:00

Hi
I have Pipeline and Release, and I'm wonder if is it possible to publish the Error Message and Stack Trace directly from a running test (Nunit3 - c#).

67694-tfs1.png

Best Regards,
Nadeem Bader

Developer technologies | C#
{count} votes

5 answers

Sort by: Most helpful
  1. VaibhavPandey 31 Reputation points
    2021-02-13T20:10:28.277+00:00

    Hey Nadeem,

    If your unit tests are really isolated they will have same behaviour on your local developer workstation, isnt it?

    On emitting details from pipelines:

    1. If your pipelines are running unit test code on a Microsoft hosted agent then perhaps it will not be easy, as these hosts are isolated and tests are also assumed to be run in isolation, not sure Microsoft will let you connect to any external services except the one configured via vulnerability scanning.
    2. I assume this will be easy if you standup your own build agents in your on-prem network or Azure Virtual network, you can then log errors or exceptions to windows eventviewer or to custom log files, etc.

    Hopt this helps.

    Thanks,
    Vaibhav

    0 comments No comments

  2. VaibhavPandey 31 Reputation points
    2021-02-14T06:50:04.867+00:00

    Hi,

    This one is a on-prem scenario: application code should throw and log exceptions in the application log and unit test code should validate that an exception test case was validated.

    It should be possible to publish exceptions/stack trace.

    Add logging library to your .Net code and following below links might help you:

    http://dontcodetired.com/blog/post/Testing-for-Thrown-Exceptions-in-NUnit

    and this one should help you on publishing stack track publishing(pls look in result format mapping section)

    https://learn.microsoft.com/en-us/azure/devops/pipelines/tasks/test/publish-test-results?view=azure-devops&tabs=trx%2Cyaml

    thanks.

    0 comments No comments

  3. Nadeem Bader 21 Reputation points
    2021-02-14T11:57:47.247+00:00

    Hi
    Thank you very much for the reply.
    I viewed the links above.
    My tests also throw exceptions, but actually I didn't understand how should I implement the Results Format Mapping in my code - hope if you can provide an example.
    My focus here is on the following:
    * Error message: /test-suite[@type ='Assembly']/test-case/failure/message
    * Stack Trace: /test-suite[@type ='Assembly']//test-case/failure/stack-trace
    Hope you can assist?

    More information about my case: The nunit3 generates a XML file. I was able to copy that XML file to TFS and publish it.
    That displayed all Test Info including the Error Message and Stack Trace (As shown in the screen-shot in my first post).
    As we can see here, the Test Info was published by using the Publish Test Results task. Should I use this task anyway? Or, can I publish the results from c# code without using this task?

    67830-tfs2.png

    Best Regards,
    Nadeem Bader

    0 comments No comments

  4. VaibhavPandey 31 Reputation points
    2021-02-14T17:40:56.083+00:00

    Hey Nadeem,

    I think you are after Visual Studio Test Task. Check out following link, it has example you are looking for. Example you will see is for yaml based pipeline, however you can do the same in classic pipelines as well. Just try to add new task and you will be able to find this task "Visual Studio Test" and add scripts in the highlighted box in the attached screenshot:

    https://learn.microsoft.com/en-us/azure/devops/pipelines/tasks/test/vstest?view=azure-devops
    67892-help-testresult.png

    You want results as shown on following link(check "test tab" section on following):

    https://learn.microsoft.com/en-us/azure/devops/pipelines/test/review-continuous-test-results-after-build?view=azure-devops

    0 comments No comments

  5. Nadeem Bader 21 Reputation points
    2021-02-15T09:27:19.073+00:00

    Hi
    I appreciate your assistance.
    Actually, the goal is to get rid of the Publish Tests Results and handle the publish from the tests (The c# which is triggered by Run Functional Tests).
    I need to publish the Error Message and Stack Trace from the test code.
    Is that possible?
    Best Regards,
    Nadeem Bader

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.