vendredi 6 juin 2014

Unit test application with SQLite


Vote count:

0




i have project, where i'm using SQLite (file name: myDatabase.db). For example, i have simple class, here is code:



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();
}
}


class cSQLite have implement some important class, for example: SQLiteconnection etc. All is works in my project, but when I want to test in 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);
}


then i have bad unit test (fail result, but in my app all is ok :( - every works properly). How can I implement good unit test for my app?


I'm using Nunit and search in internet NDbUnit.SQLite, but i don't know how to implement it. Somebody would give me a simple way to this app?



asked 48 secs ago






Aucun commentaire:

Enregistrer un commentaire