Hacker News new | comments | show | ask | jobs | submit login

As someone who has bootstrapped themselves to a basic level of coding knowledge thanks to Google, I'll ask the potentially stupid question: How do I learn how to do unit testing? I know what it is but I have no idea how to go about it. Resources?

What is your language? the answer can be rspec, junit, selenium, etc based on the language and framework.

basically unit testing is on the function/class/module basis.

you break your design into modules, each having a clear role, and make them plug into each other in a way that you can "mock" the "rest of the world" (e.g. other objects) and test only that part.

to give an example, let's say you create a car, the unit test is to take a wheel, and spin it as if it's on the road, but without a car. take the lights, and plug them in as if they are in the car, take the engine and run it as if it's connected to the transmission, etc. in a car it's a bit more difficult, but in code, if your view needs a model, it doesn't matter if it was created from a database, a text file, or coded, as long as the interface fits.

What language are you using? If it's Java I found 'Test Driven Development' by Kent Beck a great book if you want to 'get' unit testing and TDD.

There's a gap before when the point of TDD 'clicks' and you see the 'why'; before that it can seem a huge bore. After that it can seem a bore too in some situations but you can see the benefits of it.

Applications are open for YC Winter 2018

Guidelines | FAQ | Support | API | Security | Lists | Bookmarklet | DMCA | Apply to YC | Contact