Exemplo n.º 1
0
class atest_api_users(unittest.TestCase, Ski):
    def setUp(self):
        self.logger = SkiLogger("atest_api_users")

    def tearDown(self):
        pass

    @Ski.case()
    def case_api_users(self):
        model_name = "api_users"
        self.logger.info("in case_api_users")
        mjstr = DT.json(model_name + '_model.json')
        res = self.step("requestFromModel", mjstr)
        jstr = DT.json(model_name + "_res.json")
        self.assertEqual(jstr['status'], res.result.status_code)
        self.logger.info("login res {0}".format(res))
Exemplo n.º 2
0
class TestSendMessage(unittest.TestCase, Ski):
    def setUp(self):
        self.logger = SkiLogger('TestSendMessage')

    def tearDown(self):
        pass

    @Ski.case()
    def test_send(self):
        self.logger.info("I'm in test_two test_send")
        # print(self.ski_step_result)
        self.assertTrue(True)
        res = self.step("userkw_sendmsg", "get", "http://www.baidu.com")
        self.logger.info(res.result)
        self.assertEqual(200, res.result.status_code)

    @Ski.case()
    def test_send_use_robotframework_requestlibary(self):
        self.logger.info("I'm in test_two test_send")
        # print(self.ski_step_result)
        # self.assertTrue(True)
        self.step("Create Session", "baidu", "http://www.baidu.com")
        res = self.step("Get Request", "baidu", "/")
        self.assertEqual(200, res.result.status_code)
Exemplo n.º 3
0
    # 测试用例使用"ski_"开头命名
    suites = unittest.defaultTestLoader.discover(dirpath,
                                                 name + '*.py',
                                                 top_level_dir=dirpath)
    for suite in suites:
        test_cases.addTests(suite)
    return test_cases


if __name__ == '__main__':
    report_type = input("report mode(h or t):")
    casepath = input("input case file pash(defult is ./utest/testcase):")
    casename = input("input case name (defult is test_*.py):")
    cases = get_test_cases('./utest/testcase' + casepath, casename)
    now = time.strftime("%Y-%m-%d %H_%M_%S")  # 报告生成时间
    test_reports_address = '../utest/report'  # 测试报告存放位置
    filename = './utest/report/' + now + 'report.html'  # 设置报告文件名

    if (report_type == 't'):
        logger.info("开始执行测试,报告输出模式text")
        runner = unittest.TextTestRunner()
        runner.run(cases)
    elif (report_type == 'h'):
        logger.info("开始执行测试,报告输出模式html")
        fp = open(filename, 'wb')
        runner = HTMLTestRunner(stream=fp,
                                title=u'自动化测试',
                                description=u'详细测试结果如下:')
        runner.run(cases)
        fp.close()