C# SQLite的单元测试应用

C# SQLite的单元测试应用,c#,sqlite,unit-testing,C#,Sqlite,Unit Testing,我有一个项目,我正在使用SQLite(文件名:myDatabase.db)。 例如,我有一个简单的类,下面是代码: public class teacher : Idatabase { private cSQLite = new cSQLite(); private string _name; private string _surname; public teacher(string name, string surname) { _n

我有一个项目,我正在使用SQLite(文件名:myDatabase.db)。 例如,我有一个简单的类,下面是代码:

public class teacher : Idatabase {
    private cSQLite = new cSQLite();
    private string _name;
    private string _surname;

    public teacher(string name, string surname)
    {
        _name = name;
        _surname = surname;
        AddToDataBase();
    }

    private void AddToDataBase()
    {
        this.cSQLite.Query = "insert into teachers(name, surname) values = ('" + _name + "', '" + _surname + "');";
        this.cSQLite.ExecuteNonQuery();
    }
}
类cSQLite实现了一些重要的类,例如:SQLiteconnection等。 在我的项目中,一切都是可行的,但当我想在unitTest中进行测试时:

[TestClass]
    public class UnitTest1//NDbUnit.Core.SqlLite.SqlLiteDbUnitTest
    {
        Exception execute(string name, string surname)
        {
            try
            {
                teacher t = new teacher(name, surname);
            }
            catch (Exception e)
            {
                throw e;
            }
            return null;
        }
        [TestMethod]
        [DeploymentItem("myDatabase.db")] //its file to 
        public void testCon()
        {
            Exception ex = execute("iiiiii", "dudaa");
            Assert.IsNull(ex);            
        }
然后我就有了糟糕的单元测试(失败的结果,但在我的应用程序中一切都正常:(-每个都正常工作)。我如何为我的应用程序实现良好的单元测试


我正在使用Nunit并在internet NDbUnit.SQLite中搜索,但我不知道如何实现它。有人会给我一个使用此应用程序的简单方法吗?

测试会抛出什么错误?我如何读取ex.消息?在这种情况下,我很抱歉(今天学习它)对assert.isnull(ex)进行调试,然后从菜单test->debug->tests in current context,或者只是注释掉assert..SQL逻辑错误或缺少数据库没有这样的表:从这里开始只教猜测,但确保myDatabase.db已添加到项目中,并且在解决方案资源管理器中选择文件时,在属性窗口中确保复制到输出属性为设置为“始终复制”或“较新时复制”。