Auto Test: Test Case Structure

最近在使用的一些Test Case 的逻辑结构:

接口:

    interface ITestCase
    {
        string CaseID { getset; }
        string CaseTitle { getset; }
        bool Passed { getset; }
        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 { getset; }

        public string[] ActualSection { getset; }
        public string[][] ExpectedSection { getset; }

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

循环执行每一条Case:

  ITestCase tc = null;
            for (int i = 1; i < 5; i++)
            {
                tc = case_Helper.FactoryTestCase(i);
                tc.ExcuteTC(xmlPath, excelPath);
}
原文地址:https://www.cnblogs.com/qixue/p/2232028.html