Test-First/Test-Driven Development

TylerHutchison
Unregistered
 
Post: #16
For people who are not going to read a lengthy post about why Unit testing is "for teh win."

I guess you have several options when it comes to testing:

1) No testing: uhhh well good luck...

2) Home brew erratic testing: This might seem faster for you because you can test things using print lines and you don't need to learn any sort of testing framework, but doing this tends to make your code base very cluttered. Unit testing will allow you to keep tests separate from your code, which will make your code easier to read.

3) Final Testing Phase (similar to testing with a Waterfall Model): You test all of your code at the very end of the project to make sure it works. This will become a nightmare when you try to debug your entire code base all at once. Testing your code often times will help you uncover flaws in your design, so if you are saving all of your testing for the end it will not be as helpful.

4)Test first design with Unit Tests: YAY!! I know it may seem like a hassle to set up unit tests. But if you make the effort to learn how to use them you will save yourself loads of time debugging. Also, it may seem goofy having to write tests in a specific way, but they are really not that complex, just start using them. With practice writing unit tests becomes intuitive, and writing them before you code will really force you to think about the exact function you need your piece of code to accomplish.

P.S. Hokan, thinking about someone unit testing Microsoft Office made me "LOL"
Quote this message in a reply
⌘-R in Chief
Posts: 1,265
Joined: 2002.05
Post: #17
Can you believe they actually teach us the Waterfall method in university? For huuuge projects! What moron decided that was a good idea?

Anyway, there's a 5th option you didn't mention which is to write the code and run it and test it with a bunch of inputs while executing as opposed to writing code-level tests.
Quote this message in a reply
Luminary
Posts: 5,143
Joined: 2002.04
Post: #18
If you're going to "integration test" the product as a whole, you'll either need a massive test team to be able to cover all the ground every release, or you'll need an automated approach (again, Eggplant or AppleScript can help).

Ultimately though, if you're having trouble testing something, find someone who claims to know how, plonk your code down in front of them, and say "go" Wink There are a few outcomes, of course -- they tell you to redesign your code (helpful, though perhaps not immediately so), they write a test (helpful), or they go "oh my god I have no idea how to test this" (unhelpful, but at least you don't have to feel stupid or guilty) Smile
Quote this message in a reply
Post Reply