Testcase has already been run in the previous demo, so this article will summarize the relevant knowledge points of running the testCase.
Run TestCase in several scenarios
1. Run a case
I usually run a single case in the editor using the main method, but you can also run it from the command line if you like.
from httprunner import HttpRunner, Config, Step, RunRequest class TestCaseRequestWithGetUserName(HttpRunner): config = ( Config("test /getUserName") .base_url("http://localhost:5000") .verify(False) .export(*["username"]) ) teststeps = [ Step( RunRequest("getUserName") .get("/getUserName") .extract() .with_jmespath("body.username", "username") .validate() .assert_equal("body.username", "wesson") ), ] if __name__ == "__main__": TestCaseRequestWithGetUserName (.) test_start # () hereCopy the code
The main method simply calls test_start() at the end of the class. Command line, is directly in the hrun after the case path, you can run.
D: \ Project lambda hrun httprunner_demo \ the testcases \ get_user_name_test pyCopy the code
2. Run multiple cases
You can also run multiple cases, with Spaces separating paths after hrun.
D:\Project
λ hrun httprunner_demo\testcases\get_user_name_test.py httprunner_demo\testcases\join_str_test.py
Copy the code
3. Run the entire case folder
The testcases directory is where we normally store our testcases, so you can run all of the following cases directly from that directory.
D: \ Project lambda hrun httprunner_demo \ the testcases \Copy the code
2. Run the YAML/JSON file case
When you convert HAR files, pytest files will be generated in the same folder, with _test at the end of the file name. If you run YAML/JSON files, httprunner will convert them to PyTest before running them. So use PyTest for httprunner 3.x.
3. Run pyTest files
For pyTest files, usehrun
orpytest
All commands are ok.
becausehrun
It’s just encapsulatedpytest
, sopytest
Run all parameters, also available inhrun
After it.