Difference between revisions of "Writing unit tests"
From Simson Garfinkel
Jump to navigationJump to search
(3 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
Information on writing unit tests, from the Internet: | Information on writing unit tests, from the Internet: | ||
== Key Concepts == | |||
* Smallest testable unit | |||
* Test Cases | |||
* Test Discovery | |||
* Test Coverage | |||
* Test Driven Development / [http://pythontesting.net/agile/test-first-programming/ Test First Programming] / Test First Development | |||
* Turning bugs into test cases | |||
* Integration Testing / Test on commit | |||
Line 11: | Line 19: | ||
* Use [https://docs.pytest.org/en/latest/ pytest] for Python unit tests. It's the best developed test framework, and widely supported. | * Use [https://docs.pytest.org/en/latest/ pytest] for Python unit tests. It's the best developed test framework, and widely supported. | ||
* [http://pythontesting.net/framework/pytest/pytest-introduction/ Introduction to pytest], by Brian Okken, who wrote the book [https://pragprog.com/book/bopytest/python-testing-with-pytest "Python Testing with pytest"] | * [http://pythontesting.net/framework/pytest/pytest-introduction/ Introduction to pytest], by Brian Okken, who wrote the book [https://pragprog.com/book/bopytest/python-testing-with-pytest "Python Testing with pytest"] | ||
* [http://pythontesting.net/start-here/ Brian Okken's python testing blog and podcast] | * [http://pythontesting.net/start-here/ Brian Okken's python testing blog and podcast] | ||
* [http://agiletesting.blogspot.com/2005/01/python-unit-testing-part-3-pytest-tool.html 2005 article on Python unit testing with py.test] | * [http://agiletesting.blogspot.com/2005/01/python-unit-testing-part-3-pytest-tool.html 2005 article on Python unit testing with py.test] | ||
* [https://semaphoreci.com/community/tutorials/testing-python-applications-with-pytest Tutorial on fixtures and unit-testing with semaphore] | |||
* [https://www.tutorialspoint.com/unittest_framework/unittest_framework_py_test_module.htm TutorialsPoint on pytest] | |||
* [https://stackoverflow.com/questions/tagged/py.test StackOverflow questions on py.test] | |||
== Other collateral == | == Other collateral == | ||
* [https://www.toptal.com/qa/how-to-write-testable-code-and-why-it-matters Excellent article on Toptal about writing unit tests], | * [https://www.toptal.com/qa/how-to-write-testable-code-and-why-it-matters Excellent article on Toptal about writing unit tests], |
Latest revision as of 08:07, 25 April 2018
Information on writing unit tests, from the Internet:
Key Concepts
- Smallest testable unit
- Test Cases
- Test Discovery
- Test Coverage
- Test Driven Development / Test First Programming / Test First Development
- Turning bugs into test cases
- Integration Testing / Test on commit
General Guidance
- When you write a function, immediately write the test. (Or, better, write the test before you write the function).
- If function A creates a data object and then calls function B, which does something to the data object and then calls function C, it may be difficult to generate a test for each function. This may indicate that you should refactor your program. For example, you may wish to create a new class, AA, which has different methods for different data functions. You can then write tests for each of these methods.
Testing Python with py.test
- Use pytest for Python unit tests. It's the best developed test framework, and widely supported.
- Introduction to pytest, by Brian Okken, who wrote the book "Python Testing with pytest"
- Brian Okken's python testing blog and podcast
- 2005 article on Python unit testing with py.test
- Tutorial on fixtures and unit-testing with semaphore
- TutorialsPoint on pytest
- StackOverflow questions on py.test