Skip to main content

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
50 votes
9 answers
11k views

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-...
2 votes
5 answers
427 views

How to follow Outside-In TDD with Micro-services and Micro-frontends?

I was exploring TDD, specifically the Outside-In TDD pattern, where we need to write the acceptance (integration) test and then jump on to granular unit tests to implement the feature and make the ...
6 votes
5 answers
2k views

With Kent Beck's "test && commit || revert" (TCR), do you skip the "red" of "red, green, refactor"?

If you haven't heard of Kent Beck's TCR, it can be summarized with this: any time your tests go green, you commit; anytime your tests go red, you git reset --hard. This post is about how to practice ...
0 votes
4 answers
271 views

TDD and code reusability

Let's say that I've been iterating over my feature A with TDD. After several red-green-refactor cycles, I ended up with a nicely polished implementation with a part of the SUT encapsulated into some ...
2 votes
3 answers
428 views

How do you square TDD with non-testable requirements?

I admire Bob Martin's Clean Code. Lately, however, I realized an apparent contradiction. One of the three rules of TDD, which Bob Martin advocates for in his book, is to never write more code that is ...
77 votes
6 answers
16k views

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 ...
0 votes
2 answers
286 views

Setting up private properties for unit testing

I'm doing some TDD practice for my own learning. I'm trying to figure out how to transparently set up private properties of an object to support testing. I have a binary tree node: internal class Node ...
40 votes
12 answers
26k views

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 ...
3 votes
3 answers
1k views

TDD when removing long lived feature

Suppose I had some Manager class that I need to change in regards to existing functionality by removing code. The Manager always sends an initial message after a connection was established to do an ...
38 votes
12 answers
7k views

How do unit tests facilitate refactoring without introducing regressions?

We all know the standard TDD cycle: I first write a unit test, the smallest unit test that fails; then I write some production code, again the smallest amount of production code that is sufficient to ...
0 votes
3 answers
392 views

Would you test this piece of configuration code? How do I determine which code is worth testing?

We have a piece of code that decorates an interface to transparently add retry logic. Inversion of Control configuration service.AddOurRestApiClient() .AddResilienceHandler("Retry", ...
61 votes
15 answers
14k views

Does TDD really work for complex projects?

I’m asking this question regarding problems I have experienced during TDD projects. I have noticed the following challenges when creating unit tests. Generating and maintaining mock data It’s hard ...
2 votes
2 answers
440 views

How to practice TDD when I constantly need to ditch my current test?

I'm learning and trying TDD recently, and I constantly encounter a situation when I need to ditch my current test because it's too broad. I don't know how to deal with it. To be more specific, let's ...
11 votes
4 answers
2k views

Should you define acceptance tests for vital yet simple behavior?

I'm trying to practice BDD by applying it to a simple problem—in this case, the flocking algorithm, better known as "boids". Before any of the rules (cohesion, alignment, etc.) comes the ...
1 vote
3 answers
427 views

Is low code quality and lack of testing the norm in B2B software development?

I've been working at this company for about a year now. it's a growth company working in B2B. I'm one year out of university, with a major in computer science. I work in the web team, using an Angular ...
1 vote
2 answers
241 views

How do I test a method which interacts with a database?

So I have a database class which has methods dedicated to specific actions. For example I have below method which accesses and writes to a table in the database: def trackUserPerformance(self, ...
58 votes
12 answers
6k views

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 ...
6 votes
4 answers
4k views

Does TDD formally use black box testing to supplement unit tests?

Unit tests are never perfect at capturing functionality, particularly in certain parts of an application (such as the GUI), so everyone needs some measure of black box testing. Does TDD have anything ...
0 votes
1 answer
67 views

Load Testing for Large-Scale Architecture Involving Cloud Servers and Switches

We currently have an architectural setup as described below. Our plan is to conduct a load test, but we face a challenge due to the high cost of real switches. We have two options: either build the ...
1 vote
2 answers
194 views

Can TDD be suitable for a small team with overlapping but not identical domain knowledge

I am trying to get a better understanding of TDD. From a quick google I've found this: In layman’s terms, Test Driven Development (TDD) is a software development practice that focuses on creating ...
53 votes
10 answers
7k views

How should I test "Glue Functions" without testing that "the code I wrote is the code I wrote"?

I usually write my code in a test driven style. I write tests as specifications and then my code. It's great and useful. I always try to ignore implementation when testing and only test behaviour. I ...
43 votes
8 answers
14k views

How do you keep your unit tests working when refactoring?

In another question, it was revealed that one of the pains with TDD is keeping the testing suite in sync with the codebase during and after refactoring. Now, I'm a big fan of refactoring. I'm not ...
0 votes
4 answers
403 views

How to test a service that only connects other services

I'm currently scratching my and my colleagues head about whether and how we could test SyncService::syncFoo in any meaningful way that does not involve basically recreating the whole call tree as ...
50 votes
8 answers
13k views

How do I really write tests without mocking/stubbing?

I have been using TDD when developing some of my side projects and have been loving it. The issue, however, is that stubbing classes for unit tests is a pain and makes you afraid of refactoring. I ...
20 votes
5 answers
5k views

TDD Mock call verification - is it an anti-pattern?

I've been doing TDD for a while now, I feel pretty good about it, I love my test suites and all. However I've noticed that lately I've been doing a lot of mock call verification. For example I'd have ...
1 vote
3 answers
216 views

TDD - What to do when adding a new function on a dependency causes many previous tests to fail?

I was programming today and encountered something that just feels like I'm doing something wrong (maybe?). I've encountered this situation before, but I wanted to reach out and ask if there's a better ...
163 votes
13 answers
38k views

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 ...
2 votes
2 answers
534 views

Does the "Pyramid of tests" contradict the idea of tests focusing on behaviour?

I am talking about these two testing strategies : Have a pyramid of tests (with many more unit tests than high-level tests), because high level tests are harder to maintain and slower (see also : ...
-1 votes
3 answers
116 views

Code Coverage and Unit Tests nomenclature [closed]

About tests: I have the following view on nomenclature: Unit tests are the kind of testes where you have a function ExtractBacon, where there is a function with an entry parameter Pig and a return of ...
60 votes
5 answers
36k views

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 ...
5 votes
4 answers
426 views

How can Behavior-Driven Development be a form of Testing-Driven Development/Unit Testing?

When looking and Behavior-Driven development, "Behavior-driven development is an extension of test-driven development" (From Wikipedia). Researching around various articles, behavior-driven ...
2 votes
3 answers
248 views

Method that returns an object is it adequate for TDD?

Let's suppose I want to follow TDD (Test driven development) and I want to implement a class that is supposed to return a considerable object. It starts to get really complex in my opinion and doesn't ...
143 votes
12 answers
13k views

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 ...
0 votes
3 answers
242 views

Test driven reduction of technical debt

Suppose you have been put in charge of an already existing project. As you are starting to familiarize yourself with the repository, you notice a few technical debt issues (insufficient test coverage, ...
9 votes
5 answers
3k views

Do test-driven and behavior-driven development belong to the "verification" category?

In university, we were introduced to the two terms "verification" and "validation". The definitions can be summarized as follows: Validation checks that the specifications and ...
5 votes
7 answers
527 views

How to apply TDD to very high level functionality?

Another name for this question could be: How to TDD the main function? My situation: I'm writing a program from scratch that runs a sort of simulation, and I want to apply TDD to the whole development ...
2 votes
2 answers
631 views

Where do unit tests stop and integration tests begin according to the classical school of unit testing?

There are two schools of thought on how unit tests should be written. The first is the Classical/Chicago school, which focuses on the isolation of unit tests, describes a unit as a class or set of ...
40 votes
10 answers
5k views

How baby are your baby-steps in TDD?

Today we were training TDD and found the following point of misunderstanding. The task is for the input "1,2" return sum of numbers which is 3. What I have written (in C#) was: numbers = input.Split(...
38 votes
13 answers
7k views

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 ...
13 votes
4 answers
2k views

How should factored-out code be tested as part of the TDD refactoring step?

When in the refactoring step of a TDD process, if we "factor out" some common functionality from two (or more) code modules, how do we avoid that "factored out" code not being ...
46 votes
5 answers
5k views

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 ...
2 votes
1 answer
303 views

How to avoid class-proliferation when creating a unit-testable system?

I've been working on a personal project for some time, and I believe that I'm at that point where, if I don't embrace unit tests (and ideally TDD) now, it may be too late, so I want to make the right ...
154 votes
11 answers
24k views

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 ...
19 votes
5 answers
1k views

How do you efficiently keep your tests working as you redesign?

A well-tested codebase has a number of benefits, but testing certain aspects of the system results in a codebase that is resistant to some types of change. An example is testing for specific output--...
6 votes
3 answers
6k views

What is recommended way to create test data for unit test cases?

I am new to TDD/unit testing. I am going to write a complex scheduling algorithm in Java. As this module is a core part of our application and there are number of scenarios in it, I want to write ...
158 votes
15 answers
26k views

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 ...
1 vote
4 answers
3k views

Should test resource files be stored inside the Java class source directories?

In a TDD (Test-Driven Development)-based Java project built by maven, lots of classes needs to be tested with text-based input files such as .csv. At the beginning, I put them into the src/test/...
2 votes
2 answers
266 views

How would I use TDD / BDD when my webapp interacts with an external REST API?

I'm following roughly the TDD style as explained in the "Obey the Testing Goat" book: You have a functional test for your (Django, in my case) web app that tests the observable behaviour via ...
1 vote
1 answer
241 views

TDD verifying dependency method invoked correctly

I am trying to follow TDD in my proj but I can't get my head around how to verify I am calling a dependency correctly or even if I should be trying to verify it. Here's the requirement: Write an ...
2 votes
5 answers
516 views

Does not testing internals entail diligent refactoring and/or rely on developer talent?

I'm not asking here what the arguments are for/against testing internal methods (though I'll restate some, and don't mind hearing others). My questions relate to the implications of only testing ...

1
2 3 4 5
14