要解决这个问题,你可以在测试代码中手动禁用附件上传。下面是一个示例代码:
[TestClass]
public class MyTestClass
{
[TestMethod]
public void MyTestMethod()
{
// 在测试方法开始前禁用附件上传
TestContext.TestRunProperties["UploadTestAttachments"] = "false";
// 测试代码
// 在测试方法结束后重新启用附件上传
TestContext.TestRunProperties["UploadTestAttachments"] = "true";
}
public TestContext TestContext { get; set; }
}
在上面的示例中,我们在测试方法开始前将TestRunProperties["UploadTestAttachments"]
属性设置为"false"
来禁用附件上传,然后在测试方法结束后将其重新设置为"true"
来重新启用附件上传。
请注意,TestContext
对象在测试类中必须作为一个公共属性存在,以便我们可以访问TestRunProperties
属性。
这样,即使“Visual Studio Test”的“Upload Test Attachments”设置为false
,附件也不会被上传。