Questions tagged [tdd]

TDD stands for Test-Driven Development, or Test-Driven Design. It is the practice of writing a unit test before writing code to satisfy it, in what is known as the Red-Green-Refactor cycle.

Further Reading

659 questions
421
votes
12 answers

Should I intentionally break the build when a bug is found in production?

It seems reasonable to me that if a serious bug is found in production by end-users, a failing unit test should be added to cover that bug, thus intentionally breaking the build until the bug is fixed. My rationale for this is that the build should…
MattDavey
  • 7,096
  • 3
  • 31
  • 32
249
votes
8 answers

What is the difference between writing test cases for BDD and TDD?

I have been learning writing test cases for BDD (Behavior Driven Development) using specflow. If I write comprehensive tests with BDD, is it necessary to write TDD (Test Driven Development) test separately? Is it necessary to write test cases for…
arjun
  • 2,695
  • 3
  • 15
  • 10
183
votes
16 answers

Why does automated testing keep failing in my company?

We have tried to introduce developer automated testing several times at my company. Our QA team uses Selenium to automate UI tests, but I always wanted to introduce unit tests and integration tests. In the past, each time we tried it, everyone got…
Mag20
  • 3,281
  • 2
  • 23
  • 21
161
votes
13 answers

Is there such a thing as having too many unit tests?

I have been tasked with writing unit tests for an existing application. After finishing my first file, I have 717 lines of test code for 419 lines of original code. Is this ratio going to become unmanageable as we increase our code coverage? My…
user2954463
  • 1,440
  • 2
  • 10
  • 8
155
votes
15 answers

When is it appropriate to not unit test?

I work in a small company as a solo developer. I'm the only developer at the company in fact. I have several (relatively) large projects I've written and maintain regularly, and none of them have tests to support them. As I begin new projects I…
Ken Pespisa
  • 1,873
  • 2
  • 12
  • 11
154
votes
11 answers

When do you write the "real" code in TDD?

All the examples I've read and seen on training videos have simplistic examples. But what I don't see if how I do the "real" code after I get green. Is this the "Refactor" part? If I have a fairly complex object with a complex method, and I write…
johnny
  • 3,669
  • 3
  • 21
  • 35
141
votes
12 answers

TDD vs. Productivity

In my current project (a game, in C++), I decided that I would use Test Driven Development 100% during development. In terms of code quality, this has been great. My code has never been so well designed or so bug-free. I don't cringe when viewing…
Nairou
  • 1,519
  • 2
  • 10
  • 4
130
votes
15 answers

How do you write unit tests for code with difficult to predict results?

I frequently work with very numeric / mathematical programs, where the exact result of a function is difficult to predict in advance. In trying to apply TDD with this kind of code, I often find writing the code under test significantly easier than…
JustinLovinger
  • 1,179
  • 2
  • 7
  • 11
127
votes
14 answers

Why isn't TDD more popular in universities?

Recently, a person here asked a basic question about how to compute in Python all permutations of elements from a list. As for most questions asked by students, I haven't provided the actual source code in my answer, but rather explained how to…
Arseni Mourzenko
  • 134,780
  • 31
  • 343
  • 513
123
votes
16 answers

When is unit testing inappropriate or unnecessary?

It seems to be generally assumed (on Stack Overflow at least) that there should always be unit tests, and they should be kept up to date. But I suspect the programmers making these assertions work on different kinds of projects from me - they work…
Steve Bennett
  • 3,419
  • 4
  • 20
  • 24
118
votes
2 answers

What are the London and Chicago schools of TDD?

I’ve been hearing about the London style vs. Chicago style (sometimes called Detroit style) of Test Driven Development (TDD). Workshop of Utah Extreme Programming User's Group: Interaction-style TDD is also called mockist-style, or London-style…
Arturo Herrero
  • 1,313
  • 2
  • 9
  • 10
113
votes
14 answers

Should I avoid private methods if I perform TDD?

I'm just now learning TDD. It's my understanding that private methods are untestable and shouldn't be worried about because the public API will provide enough information for verifying an object's integrity. I've understood OOP for a while. It's my…
pup
  • 1,712
  • 2
  • 13
  • 14
110
votes
12 answers

Is testable code better code?

I'm attempting to get into the habit of writing unit tests regularly with my code, but I've read that first it's important to write testable code. This question touches on SOLID principles of writing testable code, but I want to know if those design…
WannabeCoder
  • 2,794
  • 5
  • 16
  • 19
107
votes
14 answers

Does TDD make defensive programming redundant?

Today I had an interesting discussion with a colleague. I am a defensive programmer. I believe that the rule "a class must ensure that its objects have a valid state when interacted with from outside the class" must always be adhered to. The reason…
user2180613
  • 1,752
  • 3
  • 14
  • 17
102
votes
16 answers

TDD negative experience

What is a negative side of your TDD experience? Do you find baby steps (the simplest fix to make test green) annoying and useless? Do you find no-value tests (when test has sense initially but in final implementation checks the same logic as other…
SiberianGuy
  • 4,753
  • 6
  • 34
  • 46
1
2 3
43 44