1. Test Case
1.1 understand the test case
1) Baidu Encyclopedia: What is the test?
2) English name: Test Case, referred to as the TC
1.2 Test Case title
# With Example {1} {2} _ {_} _ 3 _ {4} {5 } wherein: 1 represents the service module represents the interface abstraction function 3 represents a forward or reverse 4 represents features of a particular Interface 5 represents an example of use important detailed description may not be have been described many times # exemplified by Example title 1: device management _ add device _ positive test _ add a shop meter apparatus with Example title 2: device management _ add device _ anti test _ add a _ gates gates coding device already exists
1.3 Description of test cases
Preconditions: Login: Do I need to log, what role login privileges: the account has permission to access interface associated with: Is there a dependency on other interfaces (only interested in direct dependence) Test procedure: Step: Test Procedure expect: Perform the operation after the need for assertion (for this interface or other associated interfaces) # NOTE: in the test procedure steps and expectations can appear multiple times
1.4 test rating
pytest + allure of the installation 2. python3
2.1 install third-party packages
# Install pytest library PIP install pytest # install allure-pytest library pip install allure-pytest
2.2 Installation allure html tool
Allure Framework is a flexible, supporting multi-language test reporting tools.
Step One: Download tools: https://github.com/allure-framework/allure2/releases
Step two: Add the environment variable
The third step: Description: allure generate [xml file path] -o [html file path] --clean
Use of substantially 2.3 pytest
1) Find a function test performed in the beginning or end
2) pytest command execution Example:
pytest.main(['-s', '-v', 'file_path', "--alluredir=./report/xml"])
Use of substantially 2.4 allure
. 1 # - * - Coding: UTF-8 - * - 2 # @time: 2019/9/16 16:38 . 3 # @author: chinablue . 4 . 5 Import Allure . 6 . 7 @ allure.feature ( " a module " ) 8 allure.story @ ( " two modules " ) . 9 @ allure.description ( '' ' 10 preconditions: 11 1. Log: the platform administrator 12 has access to: permissions 2. 13 3. related data: XXX 14 test step: 15 1. step: yyy 16 2. 校验:zzz 17 ''') 18 def test(): 19 with allure.step("步骤:yyy"): 20 pass 21 with allure.step("校验:zzz"): 22 pass 23 24 import pytest 25 case_flie = r"C:\Users\reconova\Desktop\0909\new\case\module_rank\tmp.py" 26 pytest.main(['-s', '-v', '{}'.format(case_flie), "--alluredir=./output/report/xml"]) 27 28 import os 29 cmd = "allure generate ./output/report/xml -o ./output/report/html --clean" 30 os.popen(cmd)
3. The rules for writing test cases illustrate the interface
Realization of ideas: using python version of the allure library (dependent pytest library) to write test cases and use cases presented in the form of html.
3.1 Explain the concept
1) test case: a function to start with test.
2) Test class: a start with Test class, the class may include a plurality of test cases.
3) the test module: a .py file, the file can contain multiple test classes.
4) test set: a test set may comprise a plurality of test modules.
3.2 New test module
${project_root}/case/module_rank/person.py
3.3 New Test class
1) classes with a large hump, naming rules as follows:
Naming format: the Test. 1 {} {2 } # . 1 represent a module name. Such as: Person, Device other # 2 represents the interface abstraction function. Such as: Add, Delete, Edit, Detail , List , etc.
2) For chestnut
# TestPersonAdd on behalf of the new personnel management module interfaces # TestDeviceEdit on behalf of the device management module editing interfaces
3.4 New Test Methods
1) naming rules as follows:
Naming format: with test_. 1} {2} {_ _ (3 ) # . 1 represents n measured or anti measured # 2 represents the interface specific functions # 3 represents the embodiment described with important details, this site may not be described repeatedly
2) For chestnut
# Test_ counter-measure _ add a device to capture cameras _ _ coding equipment has been used # test_ positive test _ add people _ ordinary people # test_ positive measure to add people _ _ _ ordinary people Consignee Required
3.5 integrated use of (a)
. 1 # - * - Coding: UTF-. 8 - * - 2 # @time: 2019/9/23 11:15 . 3 # @author: chinablue . 4 # @file: person.py . 5 . 6 . 7 class TestPersonAdd (): . 8 . 9 DEF with test_ measuring added n _ _ ordinary skill in the art (Self): 10 Pass . 11 12 is 13 is class TestPersonDelete (): 14 15 DEF with test_ positive test _ _ special personnel remove the art (Self): 16 Pass . 17 18 is . 19 class TestPersonEdit ( ): 20 21 DEFtest_ positive test _ _ names of persons who edit (Self): 22 is Pass 23 is 24 25 class TestPersonDetail (): 26 is 27 DEF test_ anti-personnel before test _ _ person id does not exist (Self): 28 Pass 29 30 31 is class TestPersonList (): 32 33 is DEF with test_ positive screening test list _ _ M _ art (self) by the person gender: 34 is pass
3.6 allure of commonly used tags Introduction
# Test label, a first layer packet . 1) @ allure.feature ( " a tag " ) # test label, the packet of the second layer 2) @ allure.story ( " two tags " ) # test Level 3 ) allure.severity @ (allure.severity_level.BLOCKER) # test case title, using the default function name. . 4) @ allure.title ( " Example with the title " ) # test case description . 5) @ allure.description ( " use described in " ) # test step . 6) @ allure.step ( " use case step " ) # presented important reports information on the steps 7) @ allure.attach ()
3.7 integrated use of (b)
Elements of test cases
4. Efficient preparation of test cases
Realization of ideas: pycharm custom template code, the fixed code output block fast