Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Attach an image to a test report in MSTest

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.

like image 505
Christoph Fink Avatar asked Jun 12 '12 10:06

Christoph Fink


1 Answers

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; }
}
like image 68
chaliasos Avatar answered Oct 13 '22 09:10

chaliasos