mirror of
https://github.com/httprunner/httprunner.git
synced 2026-05-11 18:11:21 +08:00
TestRunner: run testcase suite
This commit is contained in:
@@ -19,3 +19,9 @@ class TestRunner(object):
|
||||
diff_content = utils.diff_response(resp_obj, testcase['response'])
|
||||
success = False if diff_content else True
|
||||
return success, diff_content
|
||||
|
||||
def run_testcase_suite(self, testcase_sets):
|
||||
return [
|
||||
self.run_single_testcase(testcase)
|
||||
for testcase in testcase_sets
|
||||
]
|
||||
|
||||
@@ -17,6 +17,10 @@
|
||||
"status_code": 201,
|
||||
"headers": {
|
||||
"Content-Type": "application/json"
|
||||
},
|
||||
"body": {
|
||||
"success": true,
|
||||
"msg": "user created successfully."
|
||||
}
|
||||
}
|
||||
},
|
||||
@@ -37,6 +41,10 @@
|
||||
"status_code": 500,
|
||||
"headers": {
|
||||
"Content-Type": "application/json"
|
||||
},
|
||||
"body":{
|
||||
"success": false,
|
||||
"msg": "user already existed."
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import os
|
||||
import random
|
||||
import requests
|
||||
from ate import runner, exception
|
||||
from ate import runner, exception, utils
|
||||
from .base import ApiServerUnittest
|
||||
|
||||
class TestUtils(ApiServerUnittest):
|
||||
@@ -15,31 +15,9 @@ class TestUtils(ApiServerUnittest):
|
||||
return requests.delete(url)
|
||||
|
||||
def test_run_single_testcase_success(self):
|
||||
testcase = {
|
||||
"name": "create user which does not exist",
|
||||
"request": {
|
||||
"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)
|
||||
testcase_file_path = os.path.join(os.getcwd(), 'test/data/demo.json')
|
||||
testcases = utils.load_testcases(testcase_file_path)
|
||||
success, _ = self.test_runner.run_single_testcase(testcases[0])
|
||||
self.assertTrue(success)
|
||||
|
||||
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, {})])
|
||||
|
||||
Reference in New Issue
Block a user