单元测试适配器无法连接到数据源或读取数据。 (未标记为可序列化)
The unit test adapter failed to connect to the data source or to read the data. (is not marked as serializable)
我正在使用 VS 2015 Enterprise 并尝试让我的单元测试直接从 TFS 2013 中的测试用例中读取数据。目前我在尝试通过数据源连接时遇到以下错误。
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: Type
'Microsoft.TeamFoundation.TestManagement.Client.TestObjectNotFoundException'
in Assembly 'Microsoft.TeamFoundation.TestManagement.Client,
Version=14.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' is
not marked as serializable.
我的测试方法是这样的。
[TestMethod]
[DataSource("TfsDataSource")]
public void Test1()
{
string expected = "t1";
string actual = TestContext.DataRow["actual"].ToString();
Assert.AreEqual(expected, actual);
}
我的配置部分是这样的:
<section name="microsoft.visualstudio.testtools" type="Microsoft.VisualStudio.TestTools.UnitTesting.TestConfigurationSection, Microsoft.VisualStudio.QualityTools.UnitTestFramework, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"/>
</configSections>
<connectionStrings>
<add name="TestCaseConnection" connectionString="http://tfsurl/DefaultCollection;projectname" providerName="Microsoft.VisualStudio.TestTools.DataSource.TestCase"/>
</connectionStrings>
<microsoft.visualstudio.testtools>
<dataSources>
<add name="TfsDataSource" connectionString="TestCaseConnection" dataTableName="103217" dataAccessMethod="Sequential"/>
</dataSources>
</microsoft.visualstudio.testtools>
已经搜索了一段时间的解决方案,但没有找到与此问题匹配的任何内容,因此感谢所有帮助或输入!
我这边测试了你的测试方法,可以用。你可以按照我下面的步骤再试一次:
首先,在TFS的测试用例中插入参数actual
。查看下面的屏幕截图:
然后,创建一个单元测试项目。检查下面的代码:
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace UnitTestProject1
{
[TestClass]
public class UnitTest1
{
[DataSource("Microsoft.VisualStudio.TestTools.DataSource.TestCase", "http://tfsurl:8080/tfs/DefaultCollection;teamprojectname", "TestCaseID", DataAccessMethod.Sequential), TestMethod]
public void Test1()
{
string expected = "t1";
string actual = TestContext.DataRow["actual"].ToString();
Assert.AreEqual(expected, actual);
}
public TestContext TestContext
{
get { return testContextInstance; }
set { testContextInstance = value; }
}
private TestContext testContextInstance;
}
}
最后,添加一个 .testsettings 文件,以及 select 这个 testsettings 文件。现在运行测试,你应该测试成功。
我正在使用 VS 2015 Enterprise 并尝试让我的单元测试直接从 TFS 2013 中的测试用例中读取数据。目前我在尝试通过数据源连接时遇到以下错误。
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: Type 'Microsoft.TeamFoundation.TestManagement.Client.TestObjectNotFoundException' in Assembly 'Microsoft.TeamFoundation.TestManagement.Client, Version=14.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' is not marked as serializable.
我的测试方法是这样的。
[TestMethod]
[DataSource("TfsDataSource")]
public void Test1()
{
string expected = "t1";
string actual = TestContext.DataRow["actual"].ToString();
Assert.AreEqual(expected, actual);
}
我的配置部分是这样的:
<section name="microsoft.visualstudio.testtools" type="Microsoft.VisualStudio.TestTools.UnitTesting.TestConfigurationSection, Microsoft.VisualStudio.QualityTools.UnitTestFramework, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"/>
</configSections>
<connectionStrings>
<add name="TestCaseConnection" connectionString="http://tfsurl/DefaultCollection;projectname" providerName="Microsoft.VisualStudio.TestTools.DataSource.TestCase"/>
</connectionStrings>
<microsoft.visualstudio.testtools>
<dataSources>
<add name="TfsDataSource" connectionString="TestCaseConnection" dataTableName="103217" dataAccessMethod="Sequential"/>
</dataSources>
</microsoft.visualstudio.testtools>
已经搜索了一段时间的解决方案,但没有找到与此问题匹配的任何内容,因此感谢所有帮助或输入!
我这边测试了你的测试方法,可以用。你可以按照我下面的步骤再试一次:
首先,在TFS的测试用例中插入参数actual
。查看下面的屏幕截图:
然后,创建一个单元测试项目。检查下面的代码:
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace UnitTestProject1
{
[TestClass]
public class UnitTest1
{
[DataSource("Microsoft.VisualStudio.TestTools.DataSource.TestCase", "http://tfsurl:8080/tfs/DefaultCollection;teamprojectname", "TestCaseID", DataAccessMethod.Sequential), TestMethod]
public void Test1()
{
string expected = "t1";
string actual = TestContext.DataRow["actual"].ToString();
Assert.AreEqual(expected, actual);
}
public TestContext TestContext
{
get { return testContextInstance; }
set { testContextInstance = value; }
}
private TestContext testContextInstance;
}
}
最后,添加一个 .testsettings 文件,以及 select 这个 testsettings 文件。现在运行测试,你应该测试成功。