Andres C
Andres C

Reputation: 463

Took me two hours to TDD some code that should have taken half an hour. Is this ok?

I'm diving into the TDD world for iOS development. Been reading a lot, watching some screencasts, and overall convincing myself of the power of TDD. But I lack the experience so I just started with a little project.

The thing is that it takes me more time to write some code with TDD than without it. For a simple functionality that should have taken me half an hour I was almost two hours battling. I get the benefit of having the tests, and wrapping your head around the high level functionality, like clearly explained here.

But I'm worried this is something that will bite me if I doesn't improve. Also, I started writing tests with Kiwi and it took me a little to get used to its notation. I noticed I spent quite some time trying to figure out the proper way to wirte/refactor test code with the specs, and not so much with the production code. In fact, most of the time I was working with the tests code due to some spec I wasn't using right, or a mock I should not have used, and so on. I find it super useful, but maybe getting my head around tests AND kiwi is too much?

In your experience, does it get better? Thanks in advance.

Upvotes: 1

Views: 64

Answers (1)

KirkSpaziani
KirkSpaziani

Reputation: 1972

You need to understand the benefits and then decide on the proper balance.

You'll get better at using kiwi or whatever tool the more you use it.

You will take more time to get your feature ready if you write tests. They can be very time consuming. They will, if written correctly, prove that the tested code works. This is a huge QA benefit and will help you to be able to use the same code in the future, running into less issues.

You're also protecting the code from future changes. A break will cost a lot of time investment down the road and your unit tests will be there protecting working functionality.

Writing tests first also gives your code an actual consumer - this will help your spot design flaws in the usage and interface.

Good luck!

Upvotes: 1

Related Questions