An Interest In:
Web News this Week
- March 3, 2024
- March 2, 2024
- March 1, 2024
- February 29, 2024
- February 28, 2024
- February 27, 2024
- February 26, 2024
July 13, 2021 12:53 pm GMT
Original Link: https://dev.to/ramushetty/python-unit-testing-2b3p
Python UNIT Testing
UNIT Testing
It is the processing of testing whether a particular unit is working properly or not is called unit testing
Test Scenario vs Test Case vs Test Suite
- Test Scenario consists of multiple test case for single scenario
- So there will be different scenarios consists of test cases for a given application example of one scenario is testing login functionality.
- Test Suite is something like grouping of test cases and executing them at a time
Implementing Python Unit testing
- We will use Python in-built module unittest
- We will use TestCase class to implement
- We also use 3 instance methods setUp(), test(), tearDown()
Here we need to be careful that setUp and tearDown method names are fixed but we can change the test method name as we like bit it need to be prefix with "test" example test_sample(), test1().
We can include as many test methods we want into the class
Note
For every test method setUp(),tearDown() methods will be executed.
To avoid this repeated call of setUp and tearDown methods we can use setUpClass(), tearDownClass() methods, now only one time setup and teardown methods are called regardless of how many number of testcases.
O/P
You can also use assert functions in test method
Hope you learned something!!!
Happy coding!!!
Original Link: https://dev.to/ramushetty/python-unit-testing-2b3p
Share this article:
Tweet
View Full Article
Dev To
An online community for sharing and discovering great ideas, having debates, and making friendsMore About this Source Visit Dev To