unit testing in python
Python hosting: Host, run, and code Python in the cloud!
If you build a car, you will build a lot of sub components such as the engine, the wheels, the brakes and so on. All these components have requirements.
Without testing, we wouldn’t know if a car would drive after putting the components together.

Software is similar, it consists of different components. We can test all of the components before putting the whole software package together.
Software quality is no better than the quality of the least tested component.
Unit Testing - unittest module
The module unittest is a complete unit testing framework.
Lets define a simple function:
|
Then we can test it using the assertEquals method:
|
Running the program will show:
|
Unit Testing - py.test
An alternative to the unittest module is pytest.
Install using:
|
Create a simple program like:
|

Lets make a test fail, change the code to:
|

Testing modules
There are several other unit testing modules: Nose, Tox, unittest2 and unittest.mock.
Posted in Testing
Leave a Reply: