“单元测试”中需要帮助一个方法! [英] Help needed in "Unit Testing" a method!
问题描述
我创建了一个基于三层窗口的应用程序。我正在尝试使用NUINT进行单元测试,但问题是我不知道如何访问该方法。
我以这种方式创建了我的应用程序:
我会尝试测试方法Shto(Klasa obj)
Business Object名称空间BO
I created a three layer windows based application. I'm trying to make a unit testing using NUINT, but the problem is that I don't know how to access the method.
I created my application in this manner :
I'll try to test the method Shto(Klasa obj)
Business Object namespace "BO"
namespace BO
{
public class Klasa
{
private int k_ID_Klasa;
private int k_KlasaViti;
private int k_Paralelja;
public Klasa()
{
}
public int ID_Klasa
{
get { return k_ID_Klasa; }
set { k_ID_Klasa = value; }
}
public int KlasaViti
{
get { return k_KlasaViti; }
set { k_KlasaViti = value; }
}
public int Paralelja
{
get { return k_Paralelja; }
set { k_Paralelja = value; }
}
}
}
数据访问层DAL
Data Access Layer "DAL"
namespace DAL
{
public class KlasaDB
{
public KlasaDB()
{
}
public static void Shto(Klasa obj)
{
SqlConnection sqlConn = new SqlConnection(StringKoneksioni.Stringu);
SqlCommand sqlCmd = new SqlCommand("procShtoKlasa", sqlConn);
sqlCmd.CommandType = CommandType.StoredProcedure;
sqlCmd.Parameters.AddWithValue("@KlasaViti", obj.KlasaViti);
sqlCmd.Parameters.AddWithValue("@Paralelja", obj.Paralelja);
sqlConn.Open();
sqlCmd.ExecuteNonQuery();
sqlConn.Close();
}
}
}
商业逻辑层BLL
Business Logic Layer "BLL"
namespace BLL
{
public class KlasaIURD
{
public KlasaIURD()
{
}
public static void Shto(Klasa obj)
{
KlasaDB.Shto(obj);
}
}
}
我为项目中所需的命名空间创建了参考资料我也创建了一个测试类,但问题是我不知道如何访问类方法,这意味着我已经堆积在下面的类中:
I created the references for the namespaces needed in the project and also I created a testing class but the problem is that I don't know how to access the class method, that means I'm stacked in the following class:
namespace ScoMan_TI.NUnit_Testing
{
[TestFixture]
class Klasa_Testuese
{
Klasa klasa;
[SetUp]
public void initKlasa()
{
//int ID_Klasa = 15;
//int KlasaViti = 12;
//int Paralelja = 5;
//KlasaDB = new KlasaDB()
//KlasaDB.Shto()
//klasa = new Klasa(new Klasa{ID_Klasa, KlasaViti, Paralelja});
}
}
}
提前感谢您的回复。
干杯
Thank you in advance for your reply.
Cheers
推荐答案
为BLL实例化对象并使用它可以调用KlasaDB .Shto()就像这样
Hi,
Instantiate an object for BLL and using that you can call KlasaDB.Shto() like this
BLL.KlasaIURD BussObj = new BLL.KlasaIURD();
BussObj.Shto(obj);
现在它将从那里转移到BLL它将转移到KlasaDB.Shto()
希望这对你有所帮助。
问候,
RK
Now it will move to BLL from there it will move to KlasaDB.Shto()
Hope this helps you a bit.
Regards,
RK
>
这篇关于“单元测试”中需要帮助一个方法!的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!