由于连接到测试DataSource,TestMethod失败时TestInitialize和TestCleanup没有触发 [英] TestInitialize and TestCleanup not firing when TestMethod failed due to connect to test DataSource

查看:47
本文介绍了由于连接到测试DataSource,TestMethod失败时TestInitialize和TestCleanup没有触发的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

全部,


TestInitialize和TestCleanup在TestMethod因为"部署项目"连接到测试数据源而失败时未触发。 


[DataSource("Microsoft.VisualStudio.TestTools.DataSource.XML","| DataDirectory | \\ abc.xml","abcd",DataAccessMethod.Sequential)]¥b $ b [DeploymentItem(@" folder \\Data\\abc.xml")]
$
public void TestMethod_ASDF()


}


谢谢,


Raja

解决方案

嗨Raja,


以下是我的问题测试代码。
此测试通过了正确的部署。输出如下:



$


显然,你可以找到 调用顺序是InitializeMethod => TestMethod => CleanupMethod。但请参阅我在InitializeMethod中的代码, 句子"TestContext.WriteLine(TestContext.DataRow ["MyData"]。ToString()+"在
InitializeMethod")"。这段代码可以正常工作!在运行TestMethod之前,InitializeMethod如何从日期源输出数据。从上面的结果来看,我的理解是实际和全面的呼叫顺序:   "DataSourceAttribute
和DeploymentItemAttribute"=> InitializeMethod => TestMethod => CleanupMethod。


这就是为什么您的InitializeMethod和CleanupMethod没有触发。由于部署错误,您无法继续执行后续步骤,并且TestMethod失败。此外,您可以找到两种TestMethod之间的差异
。图片如下:


  1. DataSourceAttribute和DeployItemAttribute是错误的=>不调用InitializeMetthod,TestMethod和CleanupMethod => TestMethod失败( 没有'输出'信息 )                  
  2. DataSourceAttribute和DeployItemAttribute是right =>调用InitializeMethod,TestMethod(其中有例外)和CleanupMethod => TestMethod失败( 有'输出'信息





祝你好运,


杰克


All,

TestInitialize and TestCleanup not firing when TestMethod failed due to connect to test data source as a 'deployment Item'. 

[DataSource("Microsoft.VisualStudio.TestTools.DataSource.XML", "|DataDirectory|\\abc.xml", "abcd", DataAccessMethod.Sequential)]
[DeploymentItem(@"folder\\Data\\abc.xml")]
public void TestMethod_ASDF()

}

Thanks,

Raja

解决方案

Hi Raja,

Here are my testing code about your issue. This test passed because of its correct deployment. And the output is as follows:


Obviously, you can find  that the calling order is InitializeMethod=>TestMethod=>CleanupMethod. But see my code in InitializeMethod,  the sentence "TestContext.WriteLine(TestContext.DataRow["MyData"].ToString()+"In InitializeMethod")" .This code can work correctly unexpectedly! How can InitializeMethod output a data from date source before running TestMethod. From the above result, my understanding is that the actual and all-round calling order:   "DataSourceAttribute and DeploymentItemAttribute"=> InitializeMethod=>TestMethod=>CleanupMethod.

That’s why your InitializeMethod and CleanupMethod are not firing. Because of wrong deployment, you can’t continue the next steps, and the TestMethod failed. Also, you can find the difference between two kinds of TestMethod. Pictures are as follow:

  1. DataSourceAttribute and DeployItemAttribute are wrong=> not calling InitializeMetthod,TestMethod and CleanupMethod=>The TestMethod failed (no ‘output’ information)                  
  2. DataSourceAttribute and DeployItemAttribute are right=>calling InitializeMethod,TestMethod(with an exception in it) and CleanupMethod=>The TestMethod failed(have an ‘output’ information )


Best regards,

Jack


这篇关于由于连接到测试DataSource,TestMethod失败时TestInitialize和TestCleanup没有触发的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆