python测试简单入门

Python016

python测试简单入门,第1张

感谢大佬 十分钟极速入门unittest ,此处为简易笔记:

例子项目的目录结构如下:

vector.py:

test_vector.py:

可以直接测试

也可以通过参数来指定相应的测试范围:

These instructions explain how to run this guide yourself. If you are not interested in that, you can nevertheless view the results online.

Installations

The recommended approach to install Robot Framework on Python is using pip. Once you have both of these preconditions installed, you can simply run:

pip install robotframework

See Robot Framework installation instructions for alternative installation approaches and more information about installation in general.

This demo is written using reStructuredText markup language with Robot Framework test data in code blocks. Executing tests in this format requires installing additional docutils module:

pip install docutils

Notice that Robot Framework 3.0 is the first Robot Framework version to support Python 3. See the aforementioned installation instructions for information about Python 2 vs Python 3.

Execution

After installations you still need to get the demo itself. It is easiest to download a certain release or grab the latest contentand extract the  package somewhere, but it is also possible to clone the project repository.

After installations and with all other preconditions in place, you can run the demo on the command line by using the robotcommand:

robot QuickStart.rst

If you use Robot Framework 2.9 or older, instead of the robot command you need to use pybot:

pybot QuickStart.rst

You can also configure the execution with various command line options:

robot --log custom_log.html --name Custom_Name QuickStart.rst

For a list of available options run robot --help.

Viewing results

Running the demo generates the following three result files. These files are linked to pre-executed files available online, but executing the demo creates them locally.

report.html

Higher level test report.

log.html

Detailed test execution log.

output.xml

Results in machine readable XML format.