question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Upgraded to MSTest v2, The type initializer for 'Microsoft.VisualStudio.TestTools.UnitTesting.TestConfiguration' threw an exception

See original GitHub issue

Question

Has anything changed around the DataSource attribute in MSTest v2? Were there any upgrade steps I need to perform?

Description

Have upgraded to MS Test v2 (v 1.1.13). Running my unit test gives:

Message: The type initializer for 'Microsoft.VisualStudio.TestTools.UnitTesting.TestConfiguration' threw an exception.

Result StackTrace:	
at Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.TestDataSource.GetConnectionProperties(DataSourceAttribute dataSourceAttribute, String& providerNameInvariant, String& connectionString, String& tableName, DataAccessMethod& dataAccessMethod)
   at Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.TestDataSource.RunDataDrivenTest(TestContext testContext, ITestMethod testMethodInfo, ITestMethod testMethod, TestMethodAttribute executor)

Steps to reproduce

I have the following attributes on my test:

    [TestMethod]
    [DataSource("NoteData")]
    [DeploymentItem(@".\TestFiles\ExcelFiles\TestData.xls")]
    [DeploymentItem(@".\TestFiles\Note", "NoteAck")]
    [DeploymentItem(@".\TestFiles\Note", @"TestFiles\NoteAck")]

In my app.config I have


 <microsoft.visualstudio.testtools>
    <dataSources>
      <add name="NoteData" connectionString="TestDataConnection" dataTableName="IssueNoteAck$" dataAccessMethod="Sequential" />
    </dataSources>
  </microsoft.visualstudio.testtools>

<connectionStrings>    
    <add name="TestDataConnection" connectionString="Driver={Microsoft Excel Driver (*.xls)}; dbq=TestData.xls; defaultdir=.; driverid=790; maxbuffersize=2048; pagetimeout=5; readonly=true;" providerName="System.Data.Odbc" />
  </connectionStrings>

Expected behavior

Test would pass as previously

Actual behavior

As above with exception and stack trace

Environment

Using VS 2017 15.0.0-RTW+26228.4
Win 7
  <package id="MSTest.TestAdapter" version="1.1.13" targetFramework="net462" />
  <package id="MSTest.TestFramework" version="1.1.13" targetFramework="net462" />
.Net Framework v4.6.2

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:8 (3 by maintainers)

github_iconTop GitHub Comments

3reactions
Smenuscommented, Sep 1, 2017

Actually, I seem to have found the fix! The issue was the old configSections declaration at the top of the app.config. I found that changing the previous one from <section name="microsoft.visualstudio.testtools" type="Microsoft.VisualStudio.TestTools.UnitTesting.TestConfigurationSection, Microsoft.VisualStudio.QualityTools.UnitTestFramework, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"/> to <section name="microsoft.visualstudio.qualitytools" type="Microsoft.VisualStudio.TestTools.UnitTesting.TestConfigurationSection, Microsoft.VisualStudio.TestPlatform.TestFramework.Extensions"/> and switching the <microsoft.visualstudio.testtools> around the dataSources to <microsoft.visualstudio.qualitytools> makes everything work again!

2reactions
Smenuscommented, Sep 2, 2017

Of course!

We went from this

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
  <configSections>
    <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="UnitTestConnection" connectionString="AConnectionString" providerName="System.Data.SqlClient" />
  </connectionStrings>
  <microsoft.visualstudio.testtools>
    <dataSources>
      <add name="TestDataSource" connectionString="UnitTestConnection" dataTableName="UnitTestTable" dataAccessMethod="Sequential" />
    </dataSources>
  </microsoft.visualstudio.testtools>
  <startup>
    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1" />
  </startup>
</configuration>

to this

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
  <configSections>
    <section name="microsoft.visualstudio.qualitytools" type="Microsoft.VisualStudio.TestTools.UnitTesting.TestConfigurationSection, Microsoft.VisualStudio.TestPlatform.TestFramework.Extensions" />
  </configSections>
  <connectionStrings>
    <add name="UnitTestConnection" connectionString="AConnectionString" providerName="System.Data.SqlClient" />
  </connectionStrings>
  <microsoft.visualstudio.qualitytools>
    <dataSources>
      <add name="TestDataSource" connectionString="UnitTestConnection" dataTableName="UnitTestTable" dataAccessMethod="Sequential" />
    </dataSources>
  </microsoft.visualstudio.qualitytools>
  <startup>
    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1" />
  </startup>
</configuration>

I actually can’t remember where I found microsoft.visualstudio.qualitytools, I think it was somewhere in this repo actually! Edit: forgot to mention that this was with 1.1.8.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Use MSTest in unit tests - Visual Studio (Windows)
Learn about the MSTest framework, which supports unit testing in Visual Studio. Use these classes and members to code unit tests.
Read more >
Use configuration file to specify connection string to define ...
Result2 Message: The type initializer for 'Microsoft.VisualStudio.TestTools.UnitTesting.TestConfiguration' threw an exception. Could anyone help ...
Read more >
Most Complete MSTest Unit Testing Framework Cheat Sheet
Most complete MSTest Unit Testing Framework cheat sheet. All you need to to know- the most basic operations to the most advanced configurations....
Read more >
issues running the VsTest tasks on several build agents all ...
An exception occurred while invoking executor 'executor://mstestadapter/v1': The type initializer for 'Microsoft.VisualStudio.TestTools.
Read more >
Most Complete MSTest Framework Tutorial Using .Net Core
Learn about the MSTest Framework using .Net Core in Selenium C# and the aspects related to cross browser testing and parallel testing in ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found