Writing unittests

July 16, 2013 - 2 minute read -
unittest test gsoc

What I am doing

I am beginning to get an idea of what unittests are. They try to test a particular small portion of your code and ensure that it will behave normally in all test cases.

For example I was writing unittests for a function - set_video_port(video_port) Mithro pointed out that if I give an argument like -1, my code will not work correctly. So this type of error where the port numbers are not in range should induce a ValueError. Similary, putting a string as an argument will should also raise an exception - TypeError.

I am making a class for each function, and the functions in the class are corresponding tests The format is like:

I run these tests by simply issuing a command like

The commits made are

What I am planning to do

I will be continuing with writing unittests for each function of the code :)


An off-topic thing. Getting all commits I had made in the last days on the blog page was such a headache. I have made this small little script for getting these commits and generating html code out of it https://github.com/hyades/hyades.github.com/blob/master/commits.py

Comments Section

Feel free to comment on the post but keep it clean and on topic.

blog comments powered by Disqus