Skip to main content

Unit Testing in Python

  • Chapter
  • First Online:
Book cover Python Continuous Integration and Delivery
  • 3193 Accesses

Abstract

Many programmers manually test the code they are writing by calling the piece of code they are developing, printing the result to the console, and visually scanning the output for correctness. This works for simple tasks but suffers from some problems:

This is a preview of subscription content, log in via an institution to check access.

Access this chapter

Chapter
USD 29.95
Price excludes VAT (USA)
  • Available as PDF
  • Read on any device
  • Instant download
  • Own it forever
eBook
USD 39.99
Price excludes VAT (USA)
  • Available as EPUB and PDF
  • Read on any device
  • Instant download
  • Own it forever
Softcover Book
USD 54.99
Price excludes VAT (USA)
  • Compact, lightweight edition
  • Dispatched in 3 to 5 business days
  • Free shipping worldwide - see info

Tax calculation will be finalised at checkout

Purchases are for personal use only

Institutional subscriptions

Notes

  1. 1.

    It actually raises an IndexError, from trying to access the last element of the sorted list, which is empty.

  2. 2.

    Wikipedia, “Dependency injection,” https://en.wikipedia.org/wiki/Dependency_injection , 2018.

  3. 3.

    Python Software Foundation, “unittest.mock—mock object library,” https://docs.python.org/3/library/unittest.mock.html , 2018.

  4. 4.

    https://docs.python.org/3/install/index.html#inst-search-path .

  5. 5.

    https://docs.pytest.org/en/latest/goodpractices.html .

  6. 6.

    Pytest, “pytest: helps you write better programs,” https://docs.pytest.org/en/latest/ , 2018.

  7. 7.

    tox, “Welcome to the tox Automation Project,” https://tox.readthedocs.io/en/latest/ , 2018.

Author information

Authors and Affiliations

Authors

Rights and permissions

Reprints and permissions

Copyright information

© 2019 Moritz Lenz

About this chapter

Check for updates. Verify currency and authenticity via CrossMark

Cite this chapter

Lenz, M. (2019). Unit Testing in Python. In: Python Continuous Integration and Delivery. Apress, Berkeley, CA. https://doi.org/10.1007/978-1-4842-4281-0_2

Download citation

Publish with us

Policies and ethics