Obe*_*der 20 c# sqlite unit-testing dispose visual-studio-2012
我试图在"测试资源管理器"中使用"全部运行"命令在运行测试一次之后发生以下错误...之后它将不再构建,直到重新启动visual studio
这是构建错误
进程无法访问文件'SQLite.Interop.dll',因为它正被另一个进程使用
这是代码
using System.Data.SQLite;
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace Test.Sqlite
{
[TestClass]
public class Test_Sqlite_Locking
{
[TestMethod]
public void can_create_table()
{
using(var fact = new SQLiteFactory())
using (var conn = fact.CreateConnection())
{
conn.ConnectionString = "Data Source=:memory:;Version=3;New=True;";
conn.Open();
//conn.Close();
}
//SQLiteConnection.ClearAllPools();
//GC.Collect();
}
}
}
Run Code Online (Sandbox Code Playgroud)
我试过,关闭连接,调用ClearAllPools,GC.Collect,直接创建SQLiteConnection(而不是Factory)...仍然是同样的问题
如果您调试所有测试,这可以工作......但是当您运行测试时,它似乎将其锁定
Phi*_*ayr 32
我在VS2012中找不到该选项(至少不能用于标准单元测试),因此我提出了另一种解决方案:
您遇到的问题来自于单元测试运行器仍然加载,以便重复测试运行更快.由于SQLite.Interop.dll可能不会经常更改,我将CopyToOutputDirectory选项更改PreserveNewest为默认值而不是默认值Always.
您可以通过打开属性(F4)视图并SQLite.Interop.dll在解决方案中选择文件来完成此操作.这可能仍会锁定的唯一一次是当您升级到更新版本的SQLite并重新启动VS2012时,对我来说工作正常.
Hap*_*Cat 13
我通过使用以下作为受影响的测试项目的预构建事件来解决这个问题:
对于64位:
taskkill /F /IM vstest.executionengine.exe /FI "MEMUSAGE gt 1"
Run Code Online (Sandbox Code Playgroud)
或32位:
taskkill /F /IM vstest.executionengine.x86.exe /FI "MEMUSAGE gt 1"
Run Code Online (Sandbox Code Playgroud)
在构建测试项目之前,这会默默地杀死执行引擎.在/FI "MEMUSAGE gt 1"停止从如果执行发动机不运行失败的命令(以及因此生成).
小智 8
试试这个:
您应该能够立即运行基于SQLite的测试,而无需重新启动.
还要确保您的数据库安装到正确的文件夹
SQLite 连接字符串
您可能还想尝试使用 SQL Lite 的数据适配器 将 SQLitew 与 .NET 结合使用
SQLiteConnectionStringBuilder builder = new SQLiteConnectionStringBuilder();
builder.FailIfMissing = true;
builder.DataSource = "Insert the fully qualified path to your sqlite db";
SQLiteConnection connection = new SQLiteConnection(builder.ConnectionString);
try
{
connection.Open();
}
catch(SqlException exp)
{
// Log what you need from here.
throw new InvalidOperationException("Whatever exception you want to throw", exp);
}
Run Code Online (Sandbox Code Playgroud)
阅读本文,看看它是否也有助于解决您的问题 System.Data.SQLite.View Ticket
| 归档时间: |
|
| 查看次数: |
6709 次 |
| 最近记录: |