mirror of
https://github.com/httprunner/httprunner.git
synced 2026-06-02 22:39:42 +08:00
add unittest for running single api
This commit is contained in:
@@ -211,10 +211,10 @@ class HttpRunner(object):
|
|||||||
dict: valid testcase/testsuite data
|
dict: valid testcase/testsuite data
|
||||||
|
|
||||||
"""
|
"""
|
||||||
if validator.is_testcases(path_or_tests):
|
if validator.is_testcase_path(path_or_tests):
|
||||||
return self.run_tests(path_or_tests)
|
|
||||||
elif validator.is_testcase_path(path_or_tests):
|
|
||||||
return self.run_path(path_or_tests, dot_env_path, mapping)
|
return self.run_path(path_or_tests, dot_env_path, mapping)
|
||||||
|
elif validator.is_testcases(path_or_tests):
|
||||||
|
return self.run_tests(path_or_tests)
|
||||||
else:
|
else:
|
||||||
raise exceptions.ParamsError("invalid testcase path or testcases.")
|
raise exceptions.ParamsError("invalid testcase path or testcases.")
|
||||||
|
|
||||||
|
|||||||
8
tests/httpbin/api/get_headers.yml
Normal file
8
tests/httpbin/api/get_headers.yml
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
|
||||||
|
name: headers
|
||||||
|
request:
|
||||||
|
url: http://httpbin.org/headers
|
||||||
|
method: GET
|
||||||
|
validate:
|
||||||
|
- eq: ["status_code", 200]
|
||||||
|
- eq: [content.headers.Host, "httpbin.org"]
|
||||||
@@ -279,6 +279,14 @@ class TestHttpRunner(ApiServerUnittest):
|
|||||||
self.assertFalse(summary["success"])
|
self.assertFalse(summary["success"])
|
||||||
self.assertEqual(summary["stat"]["errors"], 1)
|
self.assertEqual(summary["stat"]["errors"], 1)
|
||||||
|
|
||||||
|
def test_run_api(self):
|
||||||
|
path = "tests/httpbin/api/get_headers.yml"
|
||||||
|
self.runner.run(path)
|
||||||
|
summary = self.runner.summary
|
||||||
|
self.assertTrue(summary["success"])
|
||||||
|
self.assertEqual(summary["stat"]["testsRun"], 1)
|
||||||
|
self.assertEqual(summary["stat"]["successes"], 1)
|
||||||
|
|
||||||
def test_run_testcase_hardcode(self):
|
def test_run_testcase_hardcode(self):
|
||||||
for testcase_file_path in self.testcase_file_path_list:
|
for testcase_file_path in self.testcase_file_path_list:
|
||||||
self.runner.run(testcase_file_path)
|
self.runner.run(testcase_file_path)
|
||||||
|
|||||||
Reference in New Issue
Block a user