I am attempting to run SpecFlow tests from the Visual Studio 2010 Command Prompt, and I am getting a rather obtuse error message:
Unit Test Adapter threw exception: Unable to load one or more of the requested types. Retrieve the LoaderExceptions property for more information..
Some info about my VS2010 Project setup:
- Windows 7 Enterprise, 64 bit (Version 6.1.7601 Service Pack 1 Build 7601)
- Visual Studio 2010 Premium (v10.0.40219.1 SP1Rel)
- Using Coded UI Tests
- Using SpecFlow 1.9.0, which delegates to the CodedUI test API
- MSTest
- .NET v4.0.30319
- Whole solution is compiling to 32 bit code (I have coworkers using XP still)
I have a post-build event that copies a few DLL files from my NuGet packages directory to the target dir:
copy $(SolutionDir)packages\SpecBind.1.2.1.71\lib\net45\SpecBind.dll $(TargetDir)
copy $(SolutionDir)packages\SpecBind.CodedUI.1.2.1.71\lib\net45\SpecBind.CodedUI.dll $(TargetDir)
Without this, mstest somehow couldn't load a number of SpecFlow assemblies.
Relevant Parts of Test Project's App.config
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
<section name="specFlow" type="TechTalk.SpecFlow.Configuration.ConfigurationSectionHandler, TechTalk.SpecFlow" />
<section name="specBind" type="SpecBind.Configuration.ConfigurationSectionHandler, SpecBind" />
</configSections>
<connectionStrings>
...
</connectionStrings>
<specFlow>
<!-- For additional details on SpecFlow configuration options see http://go.specflow.org/doc-config -->
<unitTestProvider name="MsTest" generatorProvider="Specflow.CodedUI.MsTestCodedUiGeneratorProvider, Specflow.CodedUI" runtimeProvider="TechTalk.SpecFlow.UnitTestProvider.MsTest2010RuntimeProvider, TechTalk.SpecFlow" />
<stepAssemblies>
<!-- This attribute is required in order to use StepArgument Transformation as described here;
https://github.com/marcusoftnet/SpecFlow.Assist.Dynamic/wiki/Step-argument-transformations -->
<stepAssembly assembly="SpecFlow.Assist.Dynamic" />
<stepAssembly assembly="SpecBind" />
</stepAssemblies>
</specFlow>
<specBind>
<browserFactory provider="SpecBind.CodedUI.CodedUIBrowserFactory, SpecBind.CodedUI" browserType="IE" />
<!-- For additional details on SpecBind configuration options see the project site. -->
</specBind>
</configuration>
The command I was using to start the tests:
C:\path\to\bin\Debug> mstest /testcontainer:MyTests.dll /test:SpecFlowFeatureName
Loading MyTests.dll
Starting Execution...
Results Top Level Tests
-------- ------------------
Failed ...
Failed ...
Failed ...
...
I've been searching high and low for a solution, and all I keep finding is references to VS2008 and disabling Code Coverage. I have VS2010 and Code Coverage is not enabled in my local test settings.
Windows Event Log Viewer
After rooting around in my Windows Event Log viewer, I finally came across more info (I've heard people complain they can't find a stack trace with this error -- look in your Event Viewer)
The description for Event ID 0 from source VSTTExecution cannot be found. Either the component that raises this event is not installed on your local computer or the installation is corrupted. You can install or repair the component on the local computer.
If the event originated on another computer, the display information had to be saved with the event.
The following information was included with the event:
(QTAgent32.exe, PID 6920, Thread 213) Unit Test Adapter threw exception: System.Reflection.ReflectionTypeLoadException: Unable to load one or more of the requested types. Retrieve the LoaderExceptions property for more information.
at System.Reflection.RuntimeModule.GetTypes(RuntimeModule module)
at System.Reflection.RuntimeModule.GetTypes()
at System.Reflection.Assembly.GetTypes()
at Microsoft.VisualStudio.TestTools.TestTypes.Unit.UnitTestExecuter.GetAssemblyInfo(Assembly assembly)
at Microsoft.VisualStudio.TestTools.TestTypes.Unit.UnitTestExecuter.GetTypeInfo(Type type, Boolean checkAlreadyExaminedType)
at Microsoft.VisualStudio.TestTools.TestTypes.Unit.UnitTestExecuter.ResolveMethods()
at Microsoft.VisualStudio.TestTools.TestTypes.Unit.UnitTestExecuter.Initialize(UnitTestResult result, UnitTestRunner runner, ConsoleOutputRedirector redirector)
at Microsoft.VisualStudio.TestTools.TestTypes.Unit.UnitTestRunner.Run(UnitTestElement test, ITestContext testContext, Boolean isLoadTest, Boolean useMultipleCpus)
the message resource is present but the message is not found in the string/message table
I don't know how to resolve this error. SpecFlow tests run fine from inside Visual Studio when I right-click in a .feature file loaded in the editor and choose "Run SpecFlow Scenarios..." but I can't run them from the command line.
Any ideas, or additional information I could post?
As a side note, this stemmed from my earlier question: How do you run SpecFlow scenarios from the command line using MSTest?
Update #1
I did a little more poking around, and found this blog post: MSTest and 64bit. I checked my local test settings, and it is forcing the tests to run in 32 bit.
Now using this command:
mstest /testcontainer:MyTests.dll /testsettings:"..\..\..\Local.testsettings"
Error message:
Test method Blah.Dee.Blah threw exception:
System.IO.FileNotFoundException: Could not load file or assembly 'Microsoft.VisualStudio.TestTools.UITest.Extension, Version=11.0.0.0, Culture=neutral, PublicKeyToken=...' or one of its dependencies. The system cannot find the file specified.WRN: Assembly binding logging is turned OFF.
To enable assembly bind failure logging, set the registry value [HKLM\Software\Microsoft\Fusion!EnableLog] (DWORD) to 1.
Note: There is some performance penalty associated with assembly bind failure logging.
To turn this feature off, remove the registry value [HKLM\Software\Microsoft\Fusion!EnableLog].
TestCleanup method Blah.Dee.Blah.ScenarioTearDown threw exception. BoDi.ObjectContainerException: BoDi.ObjectContainerException: Interface cannot be resolved: SpecBind.BrowserSupport.IBrowser.
Update #2
I removed the reference to Microsoft.VisualStudio.TestTools.UITest.Extension and added it back. Cleaned. Rebuilt. Ran the same command again. Still getting the same error.
For some reason it's trying to load the Microsoft.VisualStudio.TestTools.UITest.Extension assembly as Version 11, and I have Version 10 installed on my machine. I'm trying to track down where this version is being specified so I can change it.