DEV Community

My Experience With Test Driven Development (TDD)

Russ on December 29, 2019

What is Test Driven Development (TDD)? TDD is a software development approach in which a test is written before writing the code. Once t...
Collapse
 
rossholloway94 profile image
Ross Holloway

There are some interesting thoughts here.

I think immediately "breaking" rule 1 is sometimes necessary. For example, if I am writing unit tests in Java, most of the time I'll need to create some POJO / model classes to be able to write and compile the unit tests in the first place.

Also, I think you should be careful with this approach to TDD. While what you did made sense, because there is a connection to a database, this becomes more integration testing as opposed to unit testing. Mocks come into play here so that integrations can be mocked and therefore unit tests stay de-coupled.

Collapse
 
russ profile image
Russ

Greatly appreciate the tip regarding mocking my connection to the database, I'll have to look more into it.

Collapse
 
togakangaroo profile image
George Mauer

I recently wrote about a tdd workflow that goes beyond simple exercises. You might be interested georgemauer.net/2019/12/02/tdd-wit...

Collapse
 
russ profile image
Russ

You broke it down very well, thank you for sharing the article :)

Collapse
 
russ profile image
Russ

Thank you for the link :), I'll have to read it.

Collapse
 
davinaleong profile image
Davina Leong • Edited

Just curious, what testing framework are you using?

For a suggestion, I recommend Jest. It's maintained by Facebook.

Collapse
 
russ profile image
Russ

I'm using Mocha + Chai on the backend and Enzyme on the frontend. I've been thinking of using Jest on the frontend. I'll be refactoring my frontend as well so I will be giving Jest a try.

Collapse
 
davinaleong profile image
Davina Leong

I've tried Mocha + Chai too.

What I like about Jest is it's simplicity of use... no setup or configs required...

Thread Thread
 
russ profile image
Russ

I'll have to look into it a bit closer, thank you for the suggestion :)

Collapse
 
ngarbezza profile image
Nahuel Garbezza

Great article, thanks for sharing! I've been doing TDD for many years and I shared some useful tips in this article: dev.to/ngarbezza/6-tips-for-a-powe...

Collapse
 
russ profile image
Russ

Thank you for sharing that with me, I'll have to read it :)

Collapse
 
russ profile image
Russ

Loved those 6 tips, thank you :).