9

We are using Visual Studio 2010 connected to Team Foundation Server 2010 and we use MSTest to create our unit tests.

Is it possible to attach an image to a test report, so when a test fails we can visualize something?

This image can for example be a screenshot of the application for UI tests or a graph visualizing measurement data.

Christoph Fink
  • 22,727
  • 9
  • 68
  • 113

1 Answers1

12

Use the TestContext.AddResultFile method:

[TestClass]
public class UnitTest
{
    [TestCleanup]
    public void TestCleanup()
    {
        if (TestContext.CurrentTestOutcome == UnitTestOutcome.Passed)
            TestContext.AddResultFile(testPassedFile);
        else
            TestContext.AddResultFile(testFailedFile);
    }

    [TestMethod]
    public void TestMethod()
    {

    }

    public TestContext TestContext { get; set; }
}
Community
  • 1
  • 1
chaliasos
  • 9,659
  • 7
  • 50
  • 87