In fact, this writing is Pytest test framework application, to achieve the principle of automation and https://www.cnblogs.com/Jack-cx/p/9357658.html consistent
1. Why not UnitTest
Pytest relative unittest more flexible, unittest need to write class inheritance unittest. TestCase class , Pytest does not require writable and writable classes, and also supports the generation of HTML test reports
2. Create a project
& Compare the above robot project, add a pyunit directory and report, here the main unit test framework of the other implementation of the same idea, the results generated after the implementation of the HTML reports
3. Create a new test case
& can see that the unit Test framework naming rules style is actually consistent, call "bottom" write a method to read Execel run test cases
4.pytest Run Case rules
& In-depth study please Baidu, the following only allows you to independently write an automated engineering purpose
1. File has test_ beginning test_*.py
2. class has test_ start class Test_login ()
3. method has test_ start def test_login ()
5. Methods of initialization and cleanup use
- The fixture function can be used in test functions, in test classes, in test files, and throughout the test project.
- Fixture supports modularity,fixture can be nested with each other
- Fixture Support Parameterization
- Fixture supports unittest type of setup and teardown
1) module level (setup_module/teardown_module) begins at the beginning of the module: execute at all test cases Setup_module and all use cases are executed after the end of execution Teardown_module
2) class-level (setup_class/teardown_class) begins at the beginning and end of the class: execution at the start of the current test class
3) inside the class (setup/teardown) (run before and after calling the function)
4) Functional level (setup_function/teardown_function) starts from the beginning of the function function (not in the Class): used to execute each test case when it starts execution Setup_function and executes teardown_function after each use case execution ends
5) method level (Setup_method/teardown_method) starts at the beginning of themethod (in the Class): at the beginning and end of each test method
& This time with UI Automation as an example, use only the Setup_method each use case execution first call the browser open URL
Details can be consulted: https://www.cnblogs.com/ranxf/p/7766229.html Speaking of the relatively thin
6. Multiple Run test Cases
& All test cases under Run directory
Dos down to pyunit execution of py. test–html= required to generate the report path
& Run execution of Use cases in a py file
under Dos to pyunit execute the py. Test file name . py–html= need to generate the report path
& Run a method in the class
Pytest-v Test_a.py::testclass::test_method
& Run All the methods in the specified class
Pytest-v Test_a.py::testclass
& Combined Operation
Pytest-v test_a.py::testclass test_b.py:: Test_method
7. Assertions
simple assertion, when the use case finishes executing returns a True or False assert==true, which is true if passed, otherwise fails
[Python]pytest implements Web UI Automation