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.

Filter by
Sorted by
Tagged with
104 votes
10 answers

Where is the line between unit testing application logic and distrusting language constructs?

Consider a function like this: function savePeople(dataStore, people) { people.forEach(person => dataStore.savePerson(person)); } It might be used like this: myDataStore = new Store('some ...
Jonah's user avatar
  • 1,476
74 votes
5 answers

Do I need unit test if I already have integration test?

If I already have integration test for my program, and they all passed, then I have a good feel that it will work. Then what are the reasons to write/add unit tests? Since I already have to write ...
Bryan Chen's user avatar
  • 1,095
123 votes
16 answers

When is unit testing inappropriate or unnecessary? [duplicate]

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 ...
158 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 ...
Ken Pespisa's user avatar
  • 1,903
79 votes
10 answers

Should we test all our methods?

So today I had a talk with my teammate about unit testing. The whole thing started when he asked me "hey, where are the tests for that class, I see only one?". The whole class was a manager (or a ...
Zenzen's user avatar
  • 996
35 votes
5 answers

Why is it often said that the test cases need to be made before we start coding? [duplicate]

Why is it often said that the test cases need to be made before we start coding? What are its pros and what the cons if we don't listen to this advice? Moreover, does that advice refer to black box ...
Aquarius_Girl's user avatar
10 votes
1 answer

Testing private methods as protected

I was reading this answer about testing private methods and it mentioned several possibilities: extract methods as public to another class make them public separate the env of test and production ...
sam's user avatar
  • 211
73 votes
7 answers

Difference Between Unit Testing and Test Driven Development

From reading the descriptions, I understand that in TDD tests are done prior to writing the function and in Unit Testing, its done afterwards. Is this the main difference, or the two terms can't even ...
Shamim Hafiz - MSFT's user avatar
17 votes
2 answers

Software Testing Techniques or Categories [closed]

What kinds of software testing do you know? I've heard about Test-Driven Development, Unit tests etc, but can't understand their importance and difference. For example, why are we using regression ...
Dehumanizer's user avatar
  • 1,381
13 votes
1 answer

Is wrapping a third party code the only solution to unit test its consumers?

I'm doing unit testing and in one of my classes I need to send a mail from one of the methods, so using constructor injection I inject an instance of Zend_Mail class which is in Zend framework. Now ...
Songo's user avatar
  • 6,588
14 votes
4 answers

When should I use mock objects?

I've read a lot of things about TDD but I still have doubts. For example, I have these class diagrams: It's a simple example, just to learn about TDD and mock objects. Which test should I write ...
user avatar
58 votes
12 answers

How to test the tests?

We test our code to make it more correct (actually, less likely to be incorrect). However, the tests are also code -- they can also contain errors. And if your tests are buggy, they hardly make your ...
Ryszard Szopa's user avatar
48 votes
9 answers

Is unit testing or test-driven development worthwhile?

My team at work is moving to Scrum and other teams are starting to do test-driven development using unit tests and user acceptance tests. I like the UATs, but I'm not sold on unit testing for test-...
Owen Johnson's user avatar
35 votes
3 answers

Does TDD lead to good design? [duplicate]

I'm in transition from "writing unit tests" state to TDD. I saw as Johannes Brodwall creates quite acceptable design from avoiding any of architecture phase before. I'll ask him soon if it was real ...
Eugen Martynov's user avatar
33 votes
4 answers

Relation between BDD and TDD

What is the relation of BDD and TDD? From what I understood BDD adds two main things over TDD: tests naming (ensure/should) and acceptance tests. Should I follow TDD during development by BDD? If yes,...
SiberianGuy's user avatar
  • 4,783
22 votes
5 answers

How to correct a mistake in the test, after writing implementation

What is the best course of action in TDD if, after implementing the logic correctly, the test still fails (because there is a mistake in the test)? For example, suppose you would like to develop the ...
Attilio's user avatar
  • 487
423 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....
MattDavey's user avatar
  • 7,116
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 ...
pup's user avatar
  • 1,712
49 votes
9 answers

What are the disadvantages of test-first programming?

It's all the rage nowadays. "Everyone" recommends it. That in and of itself makes me suspicious. What are some disadvantages you have found when doing test-first (test-driven) development? I'm ...
Alex Feinman's user avatar
  • 5,792
46 votes
5 answers

How do you convince management to "invest" in unit tests?

How did you convince your manager to let you unit test? By "use", I mean being allowed to develop, check-in to source control and maintain the unit tests over time, etc. Typical management ...
louisgab's user avatar
  • 876
35 votes
6 answers

What is a normal "functional lines of code" to "test lines of code" ratio?

I'm pretty new to TDD approach and my first experiments say that writing 1 line of functional code means writing about 2-3 lines of testing code. So, in case I'm going to write 1000 LOC, the whole ...
Andrey Agibalov's user avatar
32 votes
4 answers

Are there areas where TDD provides a high ROI and other areas where the ROI is so low that it is not worth following? [closed]

Test driven development. I get it, like it. But writing tests does require overhead. So should TDD be used universally throughout the code base, or are there areas where TDD provides a high ROI and ...
Phillip Ngan's user avatar
  • 1,681
28 votes
4 answers

Should each unit test be able to be run independently of other tests?

Say you have tests for two methods of a class. The first method gathers data from another tier and puts it into some sort of storage independent of the runtime (such as a SQL table), so all of the ...
Morgan Herlocker's user avatar
12 votes
6 answers

test driven development - Who should write the tests?

Originally, it is the duty of the developer to write the test, but I noticed that in many cases/e-mature developers those cases are not giving even 80% coverage. How about I have a QA person dedicated ...
Itay Moav -Malimovka's user avatar
142 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 ...
Nairou's user avatar
  • 1,529
102 votes
16 answers

TDD negative experience [closed]

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 ...
96 votes
19 answers

Why does TDD work? [closed]

Test-driven development (TDD) is big these days. I often see it recommended as a solution for a wide range of problems here in Programmers SE and other venues. I wonder why it works. From an ...
CesarGon's user avatar
  • 2,981
60 votes
5 answers

What are the design principles that promote testable code? (designing testable code vs driving design through tests)

Most of the projects that I work on consider development and unit testing in isolation which makes writing unit tests at a later instance a nightmare. My objective is to keep testing in mind during ...
CKing's user avatar
  • 1,012
48 votes
11 answers

What are the disadvantages of automated testing?

There are a number of questions on this site that give plenty of information about the benefits that can be gained from automated testing. But I didn't see anything that represented the other side of ...
RationalGeek's user avatar
  • 10.1k
38 votes
7 answers

Should I have unit tests for known defects?

If my code contains a known defect which should be fixed, but isn't yet, and won't be fixed for the current release, and might not be fixed in the forseeable future, should there be a failing unit ...
Martijn's user avatar
  • 1,016
38 votes
7 answers

Unit testing newbie team needs to unit test

I'm working with a new team that has historically not done ANY unit testing. My goal is for the team to eventually employ TDD (Test Driven Development) as their natural process. But since TDD is ...
Walter's user avatar
  • 16.1k
38 votes
13 answers

Writing the minimum code to pass a unit test - without cheating!

When doing TDD and writing a unit test, how does one resist the urge to "cheat" when writing the first iteration of "implementation" code that you're testing? For example: Let's I need to calculate ...
CraigTP's user avatar
  • 1,554
33 votes
6 answers

how much time do you spend on Unit testing?

In a company I used to work for, executives insisted that the code coverage with unit tests must be 99% or more. This resulted in writing more tests than code. It took us literally 3 days to write ...
Maggie's user avatar
  • 826
25 votes
8 answers

Are "TDD Tests" different to Unit Tests? [duplicate]

I read Stephen Walther's article about Test Driven Development (TDD) and unit testing. I think it was an excellent article. The author makes a distinction between what he calls "TDD Tests" and unit ...
asgeo1's user avatar
  • 440
21 votes
5 answers

In TDD, if I write a test case that passes without modifying production code, what does that mean?

These are Robert C. Martin's rules for TDD: You are not allowed to write any production code unless it is to make a failing unit test pass. You are not allowed to write any more of a unit test than ...
Daniel Kaplan's user avatar
18 votes
4 answers

How to do Test Driven Development

I have just 2+ years of experience in application development. In those two years my approach towards development was as following Analyze requirements Identity Core component/Objects, Required ...
Yogesh's user avatar
  • 291
17 votes
3 answers

How to test the data access layer?

I have a DAO method that utilizes Spring for JDBC access. It calculates a seller's success rate of selling an item. Here is the code: public BigDecimal getSellingSuccessRate(long seller_id) { ...
Michael's user avatar
  • 273
11 votes
2 answers

Why is it inappropriate to use UML diagrams to plan how your code will be organized?

So, yes, diagrams can be inappropriate at times. When are they inappropriate? When you create them without code to validate them, and then intend to follow them. There is nothing wrong with drawing ...
q126y's user avatar
  • 1,713
10 votes
5 answers

If TDD is about design why do I need it? [closed]

TDD gurus more and more tell us that TDD is not about tests, it is about design. So I know some developers who create really great design without TDD. Should they practice TDD then?
SiberianGuy's user avatar
  • 4,783
6 votes
2 answers

Unit test SHA256 wrapper queries

I have the following SHA256 wrapper. public static string SHA256(string plainText) { StringBuilder sb = new StringBuilder(); SHA256CryptoServiceProvider provider = new ...
Sam Leach's user avatar
  • 441
6 votes
4 answers

How do asserts and other error avoidance checks fit into TDD? You are not allowed to write any production code unless it is to make a failing unit test pass. So where do asserts fit into this? If ...
Edward Strange's user avatar
1 vote
1 answer

How to test an algorithm with multiple inputs?

I want to check group of algorithms which has up to 8 input options. The native idea would be to check all possibilities via brute force. How can I reduce it without leaving out required combinations? ...
rekire's user avatar
  • 113
250 votes
8 answers

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

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 ...
arjun's user avatar
  • 2,705
185 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. ...
Mag20's user avatar
  • 3,301
75 votes
7 answers

Writing Tests for Existing Code

Suppose one had a relatively large program (say 900k SLOC in C#), all commented/documented thoroughly, well organized and working well. The entire code base was written by a single senior developer ...
Paul's user avatar
  • 1,025
69 votes
7 answers

Is it sufficient to use acceptance and integration tests instead of unit test?

Short introduction to this question. I have used now TDD and lately BDD for over one year now. I use techniques like mocking to make writing my tests more efficiently. Lately I have started a ...
twilker's user avatar
  • 908
41 votes
3 answers

How can I do TDD in real-world applications?

Doing TDD in a kata is simple. A red test, small amount of code, green test, and refactor. Repeat. And that's it. But, I work on a real application. With a REST controller, a service layer for ...
fluminis's user avatar
  • 573
40 votes
13 answers

How do we make unit tests run fast?

We have reached the point in our project where we have almost a thousand tests and people have stopped bothering with running them before doing a check in because it takes so long. At best they run ...
Ziv's user avatar
  • 3,016
39 votes
6 answers

Good example of complex code using TDD [closed]

What would be a good example of the use of TDD in large, real-life, complex, projects? All the examples I've seen so far are toy projects for the purpose of a book or a paper... Can you name an ...
Xavier Nodet's user avatar
  • 3,704
35 votes
12 answers

Has test driven development (TDD) actually benefited a real world project?

I am not new to coding. I have been coding (seriously) for over 15 years now. I have always had some testing for my code. However, over the last few months I have been learning test driven design/...
James's user avatar
  • 459