为什么数据驱动unit testing在vs2012中在vs2010中正常工作时失败了?
我有一些数据驱动的unit testing在Visual Studio 2010中运行得很好。这些测试使用以下模式实现。
[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); }
这是我的解决方案结构。
- MySolutionFolder
- MyTestProjectFolder
- MyTestDataFolder
- my_data.xml
当我在Visual Studio 2012中运行相同的测试时,它们失败并显示以下错误消息。
结果消息:unit testing适配器无法连接到数据源或读取数据。 有关解决此错误的详细信息,请参阅MSDN Library中的“数据驱动unit testing疑难解答”( http://go.microsoft.com/fwlink/?LinkId=62412 )。 错误详细信息:对象引用未设置为对象的实例。
为什么我的unit testing突然失败了?
在Visual Studio 2010中, DeploymentItem
属性与解决方案相关 ,但在Visual Studio 2012中,它与项目相关 。 只需指定相对于项目文件夹的DeploymentItem
路径,unit testing将再次开始工作。
有关详细信息,请参阅以下链接。