ASP.NET integration tests - TestDrive.net won't run them, other testrunners will

775 Views Asked by At

I recently had problems with integration tests after I upgraded my solution to .NET 4.0 - the answer to that question was to grab the 64 bit version of System.Data.SQLite.dll.

I've figured that out but I have a related problem. My integration tests execute when I use the Resharper testrunner, but an exception is thrown when I use the TestDriven.NET testrunner:

Test 'MyApp.IntegrationTests.DataAccess.Providers.ContactFormSubmissionProviderTest.CanFetchContactFormSubmissionById' failed:
    System.TypeInitializationException : The type initializer for 'MyApp.DataAccess.NHibernate.SessionManager' threw an exception.
  ----> NHibernate.HibernateException : Could not create the driver from NHibernate.Driver.SQLite20Driver.
  ----> System.Reflection.TargetInvocationException : Exception has been thrown by the target of an invocation.
  ----> NHibernate.HibernateException : The IDbCommand and IDbConnection implementation in the assembly System.Data.SQLite could not be found. Ensure that the assembly System.Data.SQLite is located in the application directory or in the Global Assembly Cache. If the assembly is in the GAC, use <qualifyAssembly/> element in the application configuration file to specify the full name of the assembly.
    at MyApp.DataAccess.NHibernate.SessionManager.OpenSession()
    DataAccess\Providers\ContactFormSubmissionProviderTest.cs(28,0): at MyApp.IntegrationTests.DataAccess.Providers.ContactFormSubmissionProviderTest.CanFetchContactFormSubmissionById()
    --HibernateException
    at NHibernate.Connection.ConnectionProvider.ConfigureDriver(IDictionary`2 settings)
    at NHibernate.Connection.ConnectionProvider.Configure(IDictionary`2 settings)
    at NHibernate.Connection.ConnectionProviderFactory.NewConnectionProvider(IDictionary`2 settings)
    at NHibernate.Cfg.SettingsFactory.BuildSettings(IDictionary`2 properties)
    at NHibernate.Cfg.Configuration.BuildSettings()
    at NHibernate.Cfg.Configuration.BuildSessionFactory()
    NHibernate\SessionManager.cs(18,0): at MyApp.DataAccess.NHibernate.SessionManager..cctor()
    --TargetInvocationException
    at System.RuntimeTypeHandle.CreateInstance(RuntimeType type, Boolean publicOnly, Boolean noCheck, Boolean& canBeCached, RuntimeMethodHandleInternal& ctor, Boolean& bNeedSecurityCheck)
    at System.RuntimeType.CreateInstanceSlow(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache)
    at System.RuntimeType.CreateInstanceDefaultCtor(Boolean publicOnly, Boolean skipVisibilityChecks, Boolean skipCheckThis, Boolean fillCache)
    at System.Activator.CreateInstance(Type type, Boolean nonPublic)
    at System.Activator.CreateInstance(Type type)
    at NHibernate.Connection.ConnectionProvider.ConfigureDriver(IDictionary`2 settings)
    --HibernateException
    at NHibernate.Driver.ReflectionBasedDriver..ctor(String driverAssemblyName, String connectionTypeName, String commandTypeName)
    at NHibernate.Driver.SQLite20Driver..ctor()

The image: Exception, D'oh!

I also tried the solution in this link; it didn't help. How can I run my tests from Testdriven.Net?

UPDATE:

My project is set to built as Any CPU, Release platform.

My OS is Windows 7 64-bit. I have linked against both x86 and x64 versions SQLite. Explanation:

My solution has several projects - DataAccess, IntegrationTests, Core, and UI. All are .net 4.0 projects, and all are class libraries with the exception of UI, which is an MVC 3.0 project. I'm using nUnit 2.4.8.0. My DataAccess layer utilizes NHibernate.

  • My UI project references 1.0.60.0 (Otherwise I cannot run my app from within VS2010).
  • My IntegrationTests project references 1.0.74.0 (Otherwise I cannot run my tests using Resharper's TestRunner).
  • My DataAccess project references 1.0.60.0, and
  • My Core project has no knowledge of anything database related.

1.0.60.0 is the x86, and 1.0.74.0 is the x64.

When the site is deployed, the server requires x86.

UPDATE 2:

There is an option for TestDriven.NET for it use 32-bit or 64-bit processes under Tools -> Options -> TestDriven.NET. I changed this to 64-bit. Now, rightclicking and selecting "run tests" will execute them fine, but I still have the same problem with "Test with NCover" or "Test with Coverage", which is what I really want to accomplish.

1

There are 1 best solutions below

0
On

I think you might have answered your own question :)

Most of the runners you mention will run in x86 mode by default, you've had to find specific instances where you can tell certain runners (like TestDriven.net) to use x64 to run on your machine, but now you're hitting the same problem with NCover or Coverage.

So, the solution is to just force the project to build against x86 instead. Your libraries will target x86; ReSharper's runner will detect this from the build configuration in your solution. Since your target production machine is x86, there's no issue. You can run x86-targetted assemblies on Win7 x64.

Go to your solution config, and for each of your projects, select the "target platform" to be x86. Reference the x86 SQLite assembly from all your projects. This is how we have it set up on several projects on Win7x64 dev machines with NCrunch, R#, dotCover all behaving fine.