简体   繁体   English

如何配置.NET / C#下的SQLite在NUnit测试中运行?

[英]How do I configure SQLite under .NET/C# to run in NUnit tests?

I am writing NUnit tests and want to use the in-memory database SQLite (.NET) with my DAL. 我正在编写NUnit测试,并且想在我的DAL中使用内存数据库SQLite(.NET)。 I thought that since it is in-memory it shouldn't be such a big deal to run unit tests with it. 我以为,由于它是内存中的,因此使用它运行单元测试应该没什么大不了的。 I have no trouble setting up an executable to run with SQLite. 我毫不费力地设置了一个可与SQLite一起运行的可执行文件。 I add the SQLite dll-references and include the correct DbProviderFactories settings in the App.config file and it works. 我添加了SQLite dll引用,并在App.config文件中包括了正确的DbProviderFactories设置,并且可以正常工作。

However, when I run nunit tests I have trouble getting the data store provider: 但是,当我运行nunit测试时,我很难获得数据存储提供程序:

System.ArgumentException : The specified store provider cannot be found in the configuration, or is not valid.
  ----> System.ArgumentException : Unable to find the requested .Net Framework Data Provider.  It may not be installed.

I tried to do the same process with the test project as i would with a executable project but it doesn't work. 我尝试对测试项目执行与对可执行项目相同的过程,但是它不起作用。

How do I configure SQLite to run in NUnit tests? 如何配置SQLite在NUnit测试中运行?

I don't know if it helps you. 不知道对您有没有帮助。

I use Fluent nHibernate, its light and awesome. 我使用Fluent nHibernate,它轻巧而且很棒。

http://www.dotnetguy.co.uk/post/2009/10/20/sqlite-nunit-fluent-nhibernate-test-your-data-access-layer/ http://www.dotnetguy.co.uk/post/2009/10/20/sqlite-nunit-fluent-nhibernate-test-your-data-access-layer/

I have had the same problem. 我曾经也有过一样的问题。 For me it worked when i switched the SQLite from x86 to x64 (or vice versa, can't remember). 对我来说,当我将SQLite从x86切换到x64时,它起作用了(反之亦然,不记得了)。

If you're using NuGet: There is (confusingly) 3 different packages for SQLite . 如果您使用的是NuGet :(令人困惑的) SQLite有3个不同的软件包。

I also use FluentNH combined with a Repository pattern for data access. 我还使用FluentNH结合Repository模式进行数据访问。 It's super simple to set up for both tests and application :) 为测试和应用程序设置非常简单:)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM