Esempio n. 1
0
 def test_seq_and_repeat_test(self):
     report = TestReport()
     r = runner.TestRunner(report)
     r.run("test.sampletest.seqtest")
     results = []
     for it in report.logs:
         if it[0] == 'log_test_result':
             results.append(type(it[1]).__name__)
     self.assertEqual(results, ["TestA"] + ["TestB"] * 4 + ["TestC"])
Esempio n. 2
0
    def execute(self, args):
        '''执行过程
        '''
        from testbase.testcase import TestCase
        from testbase import runner, report

        if args.working_dir is None:
            args.working_dir = os.getcwd()

        if args.priorities is None:
            priorities = [
                TestCase.EnumPriority.Low, TestCase.EnumPriority.Normal,
                TestCase.EnumPriority.High, TestCase.EnumPriority.BVT
            ]
        else:
            priorities = args.priorities.split('/')

        if args.status is None:
            status = [
                TestCase.EnumStatus.Design, TestCase.EnumStatus.Implement,
                TestCase.EnumStatus.Review, TestCase.EnumStatus.Ready
            ]

        test_conf = runner.TestCaseSettings(args.tests,
                                            priorities=priorities,
                                            status=status)

        if args.report_type == 'xml':
            report_inst = report.XMLTestReport()
        elif args.report_type == 'stream':
            report_inst = report.StreamTestReport()
        elif args.report_type == 'online':
            report_inst = report.OnlineTestReport("调试报告")
        else:
            raise ValueError("非法的报告类型:" + str(args.report_type))

        if args.runner_type == 'normal':
            runner_inst = runner.TestRunner(report_inst, args.retries)
        elif args.runner_type == 'threading':
            runner_inst = runner.ThreadingTestRunner(report_inst,
                                                     args.concurrency,
                                                     args.retries)
        elif args.runner_type == 'multiprocessing':
            runner_inst = runner.MultiProcessTestRunner(
                report_inst, args.concurrency, args.retries)
        else:
            raise ValueError("非法的执行方式类型:" + str(args.runner_type))

        prev_dir = os.getcwd()
        os.chdir(args.working_dir)
        runner_inst.run(test_conf)
        os.chdir(prev_dir)
        if isinstance(report_inst, report.OnlineTestReport):
            print report_inst.url
Esempio n. 3
0
 def test_retry(self):
     report = TestReport()
     r = runner.TestRunner(report, retries=1)
     r.run("test.sampletest.runnertest")
     testresults = {}
     for it in report.logs:
         if it[0] == 'log_test_result':
             testresults.setdefault(it[1], [])
             testresults[it[1]].append(it[2])
     for tc, testresult in testresults.items():
         if tc.expect_passed:
             self.assertEqual(len(testresult), 1)
         else:
             self.assertEqual(len(testresult), 2)
Esempio n. 4
0
 def test_run_testcasesettings(self):
     report = TestReport()
     r = runner.TestRunner(report)
     r.run(
         runner.TestCaseSettings(["test.sampletest"],
                                 tags=["mod"],
                                 excluded_tags=["test2"]))
     tcs = []
     for it in report.logs:
         if it[0] == 'log_test_result':
             tcs.append(it[1])
     self.assertEqual(len(tcs), 1)
     tc = tcs[0]
     from test.sampletest.tagtest import TagTest
     self.assertIsInstance(tc, TagTest)
Esempio n. 5
0
 def test_run_plan(self):
     import uuid
     from test.sampletestplan.hello import HelloTestPlan
     report = TestReport()
     r = runner.TestRunner(report)
     r.run(HelloTestPlan())
     ops = []
     for it in report.logs:
         if it[0] == "log_test_target":
             ops.append(it[0])
         elif it[0] == "log_loaded_tests":
             ops.append(it[0])
         elif it[0] == "log_record" and it[2] == 'plan':
             ops.append(it[3])
     self.assertEqual(ops, [
         "test_setup", "log_test_target",
         "resource_setup-node-%s" % uuid.getnode(),
         "resource_setup-hello-1", "resource_setup-hello-2",
         "log_loaded_tests", "resource_teardown-hello-1",
         "resource_teardown-hello-2",
         "resource_teardown-node-%s" % uuid.getnode(), "test_teardown"
     ])
Esempio n. 6
0
    def execute(self, args):
        '''执行过程
        '''      
        from testbase.testcase import TestCase
        from testbase import runner, report
        
        if args.working_dir is None:
            args.working_dir = os.getcwd()
            
        if args.priorities is None:
            priorities = [TestCase.EnumPriority.Low, 
                          TestCase.EnumPriority.Normal, 
                          TestCase.EnumPriority.High, 
                          TestCase.EnumPriority.BVT]
        else:
            priorities = args.priorities.split('/')
            
        if args.status is None:
            status = [TestCase.EnumStatus.Design, 
                      TestCase.EnumStatus.Implement, 
                      TestCase.EnumStatus.Review, 
                      TestCase.EnumStatus.Ready]
        else:
            status = args.status

        test_conf = runner.TestCaseSettings(args.tests, priorities=priorities, status=status)
    
        if args.report_type == 'xml':
            class VerboseXMLTestReport(report.XMLTestReport):
                def log_test_result(self, testcase, testresult ):
                    print ("run test case: %s(pass?:%s)" % (testcase.test_name, testresult.passed))
                    super(VerboseXMLTestReport, self).log_test_result(testcase, testresult)
            report_inst = VerboseXMLTestReport()
            
        elif args.report_type == 'stream':
            report_inst = report.StreamTestReport(output_testresult=args.verbose)
            
        elif args.report_type == 'online':
            class VerboseOnlineTestReport(report.OnlineTestReport):
                def log_test_result(self, testcase, testresult ):
                    print ("run test case: %s(pass?:%s)" % (testcase.test_name, testresult.passed))
                    super(VerboseOnlineTestReport, self).log_test_result(testcase, testresult)
            receivers=args.notification
            if receivers and receivers[-1]!=";":#需要分号结尾
                receivers+=";"
            notification=report.Notification(receivers=receivers)
            report_inst = VerboseOnlineTestReport("调试报告",notification=notification)
            print "报告url: %s" % report_inst.url
            
        else:
            raise ValueError("非法的报告类型:" + str(args.report_type))
        
        args.retries=int(args.retries)
        if args.runner_type == 'normal':
            runner_inst = runner.TestRunner(report_inst, args.retries)
        elif args.runner_type == 'threading':
            runner_inst = runner.ThreadingTestRunner(report_inst, args.concurrency, args.retries)
        elif args.runner_type == 'multiprocessing':
            runner_inst = runner.MultiProcessTestRunner(report_inst, args.concurrency, args.retries)
        else:
            raise ValueError("非法的执行方式类型:" + str(args.runner_type))
        
        prev_dir = os.getcwd()
        os.chdir(args.working_dir)
        runner_inst.run(test_conf)
        os.chdir(prev_dir)
        if args.report_type == 'online':
            if sys.platform == "win32":
                print "opening online report url:%s" % report_inst.url
                os.system("start %s" % report_inst.url)
            else:
                print "online report generated: %s" % report_inst.url
                
        elif args.report_type == 'xml':
            if sys.platform == "win32":
                print "opening XML report with IE..."
                os.system("start iexplore %s" % os.path.realpath("TestReport.xml"))
            else:
                print "XML report generated: %s" % os.path.realpath("TestReport.xml")
Esempio n. 7
0
 def test_run(self):
     report = TestReport()
     r = runner.TestRunner(report)
     self._run_runner_test(report, r)