Mew
Mew

Reputation: 1049

First steps with tdd

I am currently trying out the process of test-driven development on a hobby project and while I do understand the concept (write your unit test first, watch it fail, make it work, refactor your code) I still have some questions.

The project I am working on is a MUD-client in Python. Right now I am busy with implementing the telnet protocol. (I know there is already a telnetlib in Python or an implementation in Twisted, but that's not the point)

Right now I have a class TelnetHandler that implements the Telnet protocol (or at least parts of it) and various unit tests for it. Since they're rather large they are on pastebin: TelnetHandler and the unit tests

My issues now are the following:

Basically, what I am asking is various hints and pointers that can help me improve my unit testing skills.

Thank you!

Upvotes: 4

Views: 267

Answers (1)

Michael Lloyd Lee mlk
Michael Lloyd Lee mlk

Reputation: 14661

A lot of tests depend on each other: for instance if the test_handle_read tests fails then a lot of other tests will fail too.

Don't do this. At the start of each test throw the world away and re-create it the way it should be for that test to run.

When I started writing my test I changed the handle_read method to also parse telnet commands. Afterwards, once I had my tests done I split the handle_read in various _handle_do, _handle_dont, etc... But I don't have unit tests for those as they're being tested in the original handle_read. Is this the proper way, or is it good practice to write unit tests also when you split a method in different methods?

It depends. When you split did you split into different public methods, or are they private methods that handle the implementation.

Upvotes: 4

Related Questions