为什么数据驱动的单元测试在vs2012失败时,它在VS2010正常工作? [英] Why does data driven unit test fail in vs2012 when it worked fine in vs2010?

查看:380
本文介绍了为什么数据驱动的单元测试在vs2012失败时,它在VS2010正常工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有驱动的是在Visual Studio 2010中,这些测试是使用下面的模式来实现工作得很好单元测试的一些数据。



<预类=郎-CS prettyprint -override> [TestMethod的()]
[DeploymentItem(path_to_data_dir_relative_to_solution\\my_data.xml)]
[数据源(Micr​​osoft.VisualStudio.TestTools.DataSource。 XML,| DataDirectory目录| \\my_data.xml,令牌,DataAccessMethod.Sequential)]
公共无效MyTestMethod()
{
//安排
常量字符串EXPECTED_PARAM_NAME =表;
字符串数据= TestContext.DataRow [数据]的ToString()。
变种SUT =新MyClassUnderTest();

//法案
sut.DoSomething(数据);

//断言
Assert.IsTrue(sut.DidSomething);
}

下面是我的解决方案结构。




  • MySolutionFolder

    • MyTestProjectFolder

    • MyTestDataFolder

      • my_data.xml




$ b $ :b

当我运行在Visual Studio 2012中相同的测试,他们失败,出现以下错误消息



结果消息:单元测试适配器未能连接到数据源或读取数据。有关疑难解答此错误的详细信息,请参阅故障排除数据驱动的单元测试(的http:// go.microsoft.com/fwlink/?LinkId=62412 )的MSDN资源库中错误的详细信息:?对象引用不设置到对象的实例



为什么我的单元测试突然失败


解决方案

在Visual Studio 2010中,在 DeploymentItem 属性是相对于解决方案,但在Visual Studio 2012年,它是相对于在项目。只需指定 DeploymentItem 路径相对于项目文件夹和单元测试将重新开始工作。



有关更多信息请参阅下面的链接。



http://social.msdn.microsoft.com/Forums/en-US/vsunittest/thread/4a8403a2-b495-4120-aad3-0d0becc7e45e/


I have some data driven unit tests that were working just fine in Visual Studio 2010. These tests were implemented using the following pattern.

[TestMethod()]
[DeploymentItem("path_to_data_dir_relative_to_solution\\my_data.xml")]
[DataSource("Microsoft.VisualStudio.TestTools.DataSource.XML", "|DataDirectory|\\my_data.xml", "Token", DataAccessMethod.Sequential)]
public void MyTestMethod()
{
    // Arrange
    const string EXPECTED_PARAM_NAME = "table";
    string data = TestContext.DataRow["Data"].ToString();
    var sut = new MyClassUnderTest();

    // Act
    sut.DoSomething(data);

    // Assert
    Assert.IsTrue(sut.DidSomething);
}

Here is my solution structure.

  • MySolutionFolder
    • MyTestProjectFolder
    • MyTestDataFolder
      • my_data.xml

When I run the same tests in Visual Studio 2012, they fail with the following error message.

Result Message: The unit test adapter failed to connect to the data source or to read the data. For more information on troubleshooting this error, see "Troubleshooting Data-Driven Unit Tests" (http://go.microsoft.com/fwlink/?LinkId=62412) in the MSDN Library. Error details: Object reference not set to an instance of an object.

Why are my unit tests suddenly failing?

解决方案

In Visual Studio 2010, the DeploymentItem attribute is relative to the solution, but in Visual Studio 2012, it is relative to the project. Simply specify the DeploymentItem path relative to the project folder and the unit tests will start working again.

For more info see the following link.

http://social.msdn.microsoft.com/Forums/en-US/vsunittest/thread/4a8403a2-b495-4120-aad3-0d0becc7e45e/

这篇关于为什么数据驱动的单元测试在vs2012失败时,它在VS2010正常工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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