Skip to content

Unit Testing Tools

Suparna Arya Biswas edited this page Aug 16, 2019 · 2 revisions

As we're using python we've come upon several testing tools for it. Two of them are -

1.PyTest


Advantages:

  • In the Python testing community, before the arrival of pytest, developers included their tests inside large classes. However, a revolution was brought by pytest since it made possible to write test suites in a very compact manner than it was before.
  • Other testing tools require the developer or tester to use a debugger or check the logs and detect where a certain value is coming from. Pytest helps you write test cases in a way that gives you the ability to store all values inside the test cases and finally inform you which value failed and which value is asserted.
  • The tests are easier to write and understand since the boilerplate code is not needed that much.
  • Fixtures are functions which you can use by adding an argument to your test function. Their job is to return values. In pytest, you can make them modular by using one fixture from another.Using multiple fixtures help you to cover all the parameter combinations without rewriting test cases.
  • Developers of pytest released some useful plugins that make the framework extensible. For example, pytest-xdist can be used to execute parallel testing without using a different test runner. Unit tests can also be parameterized without duplicating any code.
  • Provides developers with certain special routines that make test case writing simpler and less prone to errors. The code also becomes shorter and easily understandable.

Disadvantages:

The fact that special routines are used by pytest means that you have to compromise with compatibility. You will be able to conveniently write test cases but you won’t be able to use those test cases with any other testing framework.

2.Python standard unittest library


Advantages:

  • The developers are not required to install any additional module since it comes with the box.
  • Unittest is xUnit’s derivative and its working principle is similar to other xUnit frameworks. People who do not have a strong background in Python generally find it comfortable to work.
  • You can run individual test cases in a simpler manner. All you need to do is specify the names on the terminal. The output is concise as well, making the framework flexible when it comes to executing test cases.
  • The test reports are generated within milliseconds.

Disadvantages:

  • Usually, snake_case is used for naming python codes. But since this framework is inspired a lot from Junit, the traditional camelCase naming method persists. This can be quite confusing.
  • The intent of the test code sometimes become unclear, since it supports abstraction too much.
  • A huge amount of boilerplate code is required.

Keeping all advantages and disadvantages in mind,we decided to go with PyTest for unit testing in our project.