Upgraded to MSTest v2, The type initializer for 'Microsoft.VisualStudio.TestTools.UnitTesting.TestConfiguration' threw an exception
See original GitHub issueQuestion
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:
- Created 6 years ago
- Comments:8 (3 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
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!Of course!
We went from this
to this
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.