TestRunner: run testcase suite

This commit is contained in:
httprunner
2017-06-21 18:43:15 +08:00
parent 3550f1debd
commit 3b380bf464
3 changed files with 25 additions and 26 deletions
+6
View File
@@ -19,3 +19,9 @@ class TestRunner(object):
diff_content = utils.diff_response(resp_obj, testcase['response']) diff_content = utils.diff_response(resp_obj, testcase['response'])
success = False if diff_content else True success = False if diff_content else True
return success, diff_content return success, diff_content
def run_testcase_suite(self, testcase_sets):
return [
self.run_single_testcase(testcase)
for testcase in testcase_sets
]
+8
View File
@@ -17,6 +17,10 @@
"status_code": 201, "status_code": 201,
"headers": { "headers": {
"Content-Type": "application/json" "Content-Type": "application/json"
},
"body": {
"success": true,
"msg": "user created successfully."
} }
} }
}, },
@@ -37,6 +41,10 @@
"status_code": 500, "status_code": 500,
"headers": { "headers": {
"Content-Type": "application/json" "Content-Type": "application/json"
},
"body":{
"success": false,
"msg": "user already existed."
} }
} }
} }
+11 -26
View File
@@ -1,7 +1,7 @@
import os import os
import random import random
import requests import requests
from ate import runner, exception from ate import runner, exception, utils
from .base import ApiServerUnittest from .base import ApiServerUnittest
class TestUtils(ApiServerUnittest): class TestUtils(ApiServerUnittest):
@@ -15,31 +15,9 @@ class TestUtils(ApiServerUnittest):
return requests.delete(url) return requests.delete(url)
def test_run_single_testcase_success(self): def test_run_single_testcase_success(self):
testcase = { testcase_file_path = os.path.join(os.getcwd(), 'test/data/demo.json')
"name": "create user which does not exist", testcases = utils.load_testcases(testcase_file_path)
"request": { success, _ = self.test_runner.run_single_testcase(testcases[0])
"url": "http://127.0.0.1:5000/api/users/1000",
"method": "POST",
"headers": {
"content-type": "application/json"
},
"json": {
"name": "user1",
"password": "123456"
}
},
"response": {
"status_code": 201,
"headers": {
"Content-Type": "application/json"
},
"body": {
'success': True,
'msg': 'user created successfully.'
}
}
}
success, _ = self.test_runner.run_single_testcase(testcase)
self.assertTrue(success) self.assertTrue(success)
def test_run_single_testcase_fail(self): def test_run_single_testcase_fail(self):
@@ -90,3 +68,10 @@ class TestUtils(ApiServerUnittest):
} }
} }
) )
def test_run_testcase_suite_success(self):
testcase_file_path = os.path.join(os.getcwd(), 'test/data/demo.json')
testcases = utils.load_testcases(testcase_file_path)
result = self.test_runner.run_testcase_suite(testcases)
self.assertEqual(len(result), 2)
self.assertEqual(result, [(True, {}), (True, {})])