Attach an image to a test report in MSTest

半腔热情 提交于 2019-12-10 02:59:00

问题


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:


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; }
}


来源:https://stackoverflow.com/questions/10995017/attach-an-image-to-a-test-report-in-mstest

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!