0
votes

I'm using VS 2015 Enterprise and trying to get my unit tests to read data directly from the test case, which is in TFS 2013. Currently I´m getting the following error when trying to connect through the datasource.

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.

My test method looks like this.

[TestMethod]
[DataSource("TfsDataSource")]
public void Test1()
{
     string expected = "t1";
     string actual = TestContext.DataRow["actual"].ToString();
     Assert.AreEqual(expected, actual);
}

And my config sections like this:

   <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>

Have searched for a solution for some time now but haven´t found anything that matches this issue, so all help or input is appreciated!

1

1 Answers

0
votes

I have tested your test method on my side, which can work. You can follow my steps below to have another try:

First, insert parameter actual in a test case in TFS. Check the screenshot below:

enter image description here

Then, create an Unit Test Project. Check the code below:

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;
    }
}

Last, add a .testsettings file, and select this testsettings file. Now run test, you should get a successful test.