Attach an image to a test report in MSTest

2019-04-24 09:18发布

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.

1条回答
Rolldiameter
2楼-- · 2019-04-24 10:03

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; }
}
查看更多
登录 后发表回答