pytest with unittest advantages and disadvantages with

First, patients with written rules

1. Use unittest write test cases must follow these rules:

  1. You must first import import unittest

  2. Test class must inherit unittest.TestCase

  3. The test method must begin with test_kai

2.pyest third-party testing framework for Python, is based on the expansion of unittest framework, more cleanly and efficiently than unittest, using pytest writing test cases must follow these rules:

  1. The test file must end with the beginning of the test or _test

  2. The need to test at the beginning of the test method

  3. Test class must begin with a Test

Second, with the front rear

  Providing 1.unittest setUp / tearDown, run before each use case, once the end of run. setUpClass and tearDownClass, with cases before executing, after the end of the run only once.

  @ Pytest.fixture 2.pyets may be used before the function () decorator, fixture range may be used: function (function level), class, module (module level), package (package level), session (class plurality of test share a session)

  Advantage:

  1.fixure named more flexible, the limitations of small

  2.conftest.py configuration where you can share data, do not need to import will be able to find some automatic configuration file py for multiple calls.

  3.scope = "session" in order to achieve a plurality of cross .py file accomplished using a session with a plurality of cases

Third, the assertion

  1.unittest provides assertEqual, assertIn, assertTrue, assertFalse etc.

  2.pytest connected directly behind assert expression

Fourth, the test report

  1.unittest use HTMLTestRunnerNew library

  2.pytest have pytest-HTML, allure plug.

Fifth, run heavy defeat

  1.unittest no function

  2.pytest support

Sixth, parametric

  1.unittest need to rely on ddt library

  2.pytest directly @ pytest.mark.parametrize decorator

Guess you like

Origin www.cnblogs.com/666666pingzi/p/11450687.html