怎么使用appium跑测试用例

2025-06-22 18:27:24
推荐回答(1个)
回答1:

我用的python,所以就拿python来举例子了,框架是python自带的unittest。关于unittest资料很多,这里也写不下。

总之就是得有个test suit,如果有多个case,可以用TestLoader把所有的要跑的case搂出来。

比如testcase文件夹下的一个testxxx.py是这样,

class test_longpress(unittest.TestCase):
    def setUp(self):
        pass
    def test_longpress(self):
        print "End 1 ~~~~~"
    def test_longpress_2(self):
        print "End 2 ~~~~~"
    def test_longpress_3(self):
        print "End 3 ~~~~~"
    ......

收集testcase文件夹下所有的用例的时候可以用TestLoader,比如写我写一个load_case的方法,把所有的case都楼到testcase_class中。

def load_case(self):
    testcase_array = []
    testsuits = unittest.defaultTestLoader.discover('testcase/', pattern='test*.py')
    for testsuite in testsuits:
        for suite in testsuite._tests:
            for test in suite:
                testcase_array.append(test.__class__)
    self.testcase_class = sorted(set(testcase_array), key=testcase_array.index)

后面可以参数化testcase,把想要的case添加到suit中就可以了。