最近在使用的一些Test Case 的逻辑结构:
接口:
interface ITestCase
{
string CaseID { get; set; }
string CaseTitle { get; set; }
bool Passed { get; set; }
void ExcuteTC(string xmlFilePath, string infFilePath);
bool VerifyPass(string xmlFilePath, string infFilePath);
}
{
string CaseID { get; set; }
string CaseTitle { get; set; }
bool Passed { get; set; }
void ExcuteTC(string xmlFilePath, string infFilePath);
bool VerifyPass(string xmlFilePath, string infFilePath);
}
Sample of Test Case:
class TestCase_1 : ITestCase
{
public string CaseID
{
get
{
return "1&10";
}
set
{
throw new NotImplementedException();
}
}
public string CaseTitle
{
get
{
return "INF: Review Disk: Opening screens are presented in the correct order";
}
set
{
throw new NotImplementedException();
}
}
public bool Passed { get; set; }
public string[] ActualSection { get; set; }
public string[][] ExpectedSection { get; set; }
public TestCase_1()
{
}
public bool IsCorrectOrder(ExamClass exam, ExcelHelper excel, int lanugage)
{
bool isPass = true;
return isPass;
}
public bool VerifyPass(string xmlFilePath, string infFilePath)
{
XmlDocument xmlDoc = XmlHelper.CreateXMLDocumentObject(xmlFilePath);
ExamClass exam = ExamHelper.CreateExam(xmlDoc);
ExcelHelper excelHelper = new ExcelHelper(infFilePath);
//string welcomeTime = excelHelper.ReturnWelcomeTime();
//string ndaTime = excelHelper.ReturnNDATime();
//string conditionalItemTime = excelHelper.ReturnConditionalItemTime();
string surveyTime = excelHelper.ReturnSurveyTime();
//string examTime = excelHelper.ReturnExamTime();
//string commentTime = excelHelper.ReturnCommentTime();
//string reportTime = excelHelper.ReturnReportTime();
//Logical Code...
return true;
}
public void ExcuteTC(string xmlFilePath, string infFilePath)
{
Passed = VerifyPass(xmlFilePath, infFilePath);
}
}
{
public string CaseID
{
get
{
return "1&10";
}
set
{
throw new NotImplementedException();
}
}
public string CaseTitle
{
get
{
return "INF: Review Disk: Opening screens are presented in the correct order";
}
set
{
throw new NotImplementedException();
}
}
public bool Passed { get; set; }
public string[] ActualSection { get; set; }
public string[][] ExpectedSection { get; set; }
public TestCase_1()
{
}
public bool IsCorrectOrder(ExamClass exam, ExcelHelper excel, int lanugage)
{
bool isPass = true;
return isPass;
}
public bool VerifyPass(string xmlFilePath, string infFilePath)
{
XmlDocument xmlDoc = XmlHelper.CreateXMLDocumentObject(xmlFilePath);
ExamClass exam = ExamHelper.CreateExam(xmlDoc);
ExcelHelper excelHelper = new ExcelHelper(infFilePath);
//string welcomeTime = excelHelper.ReturnWelcomeTime();
//string ndaTime = excelHelper.ReturnNDATime();
//string conditionalItemTime = excelHelper.ReturnConditionalItemTime();
string surveyTime = excelHelper.ReturnSurveyTime();
//string examTime = excelHelper.ReturnExamTime();
//string commentTime = excelHelper.ReturnCommentTime();
//string reportTime = excelHelper.ReturnReportTime();
//Logical Code...
return true;
}
public void ExcuteTC(string xmlFilePath, string infFilePath)
{
Passed = VerifyPass(xmlFilePath, infFilePath);
}
}
返回每一条Case的实例:
class TestCaseHelper
{
public ITestCase FactoryTestCase(int i)
{
ITestCase tc = null;
switch (i)
{
case 1: tc = new TestCase_1(); break;
case 2: tc = new TestCase_2(); break;
case 3: tc = new TestCase_3(); break;
case 4: tc = new TestCase_4(); break;
case 1001: tc = new TestCase_1001(); break;
case 1002: tc = new TestCase_1002(); break;
case 1003: tc = new TestCase_1003(); break;
case 1004: tc = new TestCase_1004(); break;
case 1005: tc = new TestCase_1005(); break;
case 1006: tc = new TestCase_1006(); break;
}
return tc;
}
}
{
public ITestCase FactoryTestCase(int i)
{
ITestCase tc = null;
switch (i)
{
case 1: tc = new TestCase_1(); break;
case 2: tc = new TestCase_2(); break;
case 3: tc = new TestCase_3(); break;
case 4: tc = new TestCase_4(); break;
case 1001: tc = new TestCase_1001(); break;
case 1002: tc = new TestCase_1002(); break;
case 1003: tc = new TestCase_1003(); break;
case 1004: tc = new TestCase_1004(); break;
case 1005: tc = new TestCase_1005(); break;
case 1006: tc = new TestCase_1006(); break;
}
return tc;
}
}
循环执行每一条Case:
ITestCase tc = null;
for (int i = 1; i < 5; i++)
{
tc = case_Helper.FactoryTestCase(i);
tc.ExcuteTC(xmlPath, excelPath);
}
for (int i = 1; i < 5; i++)
{
tc = case_Helper.FactoryTestCase(i);
tc.ExcuteTC(xmlPath, excelPath);
}