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.
668
questions
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 ...
-1
votes
0
answers
77
views
How to write lots of unit tests while remaining productive? [duplicate]
The second and last question in my current series of questions about TDD and unit tests...
For the purpose of this question, a 'unit test' is defined as a test that focuses only on a particular method ...
-1
votes
0
answers
69
views
Should we prefer tests at a higher level of integration, or at a lower level of integration?
When talking about integration level of automated tests, I suppose that end-to-end tests lie at the first extreme: they know absolutely nothing about the internals of the app they test, they just run ...
0
votes
3
answers
286
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", ...
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
411
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 ...
0
votes
1
answer
65
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
181
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 ...
0
votes
4
answers
258
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 ...
1
vote
3
answers
207
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 ...
-1
votes
3
answers
115
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 ...
2
votes
2
answers
456
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 : ...
0
votes
3
answers
232
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, ...
2
votes
3
answers
245
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 ...
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
498
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
545
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 ...
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 ...
2
votes
1
answer
257
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 ...
2
votes
2
answers
229
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 ...
2
votes
6
answers
2k
views
TDD: testing an abstract class. Test all concrete classes or create mock sub-class to test the behavior?
Well, I'm developing a personal project using TDD and Clean Architecture, and I chose to build an abstract class to gather all use-cases behavior in one single class. My question is: What you think ...
0
votes
0
answers
78
views
Unit test coverage and abundant glue code [duplicate]
How do I solve this riddle of contradicting "good practices" to properly cover my app with unit-tests?
These are principles I found about writing unit-tests:
Pyramid of testing says unit-...
0
votes
1
answer
403
views
What should I write before the tests in Clean Architecture with TDD?
Well, we all know the main concept of TDD: write a failing test, then implement the testing component to make your test pass.
I've been working on a personal project in Clean Architecture following ...
0
votes
1
answer
190
views
Whats a better TDD flow for this problem?
I have a domain entity called a "Booking Window" that has a Start Date and End Date, and defines a period in which a Member can make a Booking. The business is a mobile car wash, and ...
0
votes
4
answers
575
views
Should i write tests if it takes more time than testing manually?
Im making a website and trying to learn Test Driven Development (TDD)
I'm doing one of CS50 projects, were we need to make a website to trade stocks. I decided to use this oportunity to learn TDD. I ...
41
votes
3
answers
7k
views
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 ...
0
votes
2
answers
208
views
Is it worth testing simple details? [closed]
In front-end projects(made in frameworks like Angular or React), when we correctly encapsulate complex functionalities, the components that really have some relation to the business logic normally ...
3
votes
2
answers
161
views
In TDD, should a CLI menu be tested?
I have to create a CLI application following TDD. The app should present a menu of items that can be added to an internal structure, and process those items according some rules.
My question is if I ...
1
vote
3
answers
1k
views
How should you start applying TDD in a clean architecture?
I'll be using Uncle Bob's terms, so i'll call the use cases "interactors" and the domain entities "entities". As far as I understand, the most specific business rules that are most ...
1
vote
4
answers
2k
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/...
-4
votes
3
answers
173
views
is it bad practise to go back to your last backup when you encounter an unneccessary bug? [closed]
I find when I am programming and I fix a bug in one area of the codebase, sometimes something slightly related or maybe unrelated breaks, and as a result I usually copy and paste the fix to a ...
2
votes
3
answers
343
views
Is it good practice to check the requirement multiple times?
When writing tests for TDD is it good (or bad) practice to write multiple test for the same requirement ? If it's good how many times should it be repeated? If it's bad is it it the QA engineers work ...
5
votes
2
answers
664
views
Should you write unit tests for templates and frameworks, such as in .NET?
How much (if any) unit tests should be written when you start a new templated project? In particular, let's take as an example a typical .net framework template for asp.net mvc or other similare ones ...
-1
votes
1
answer
150
views
Checking a related aggregate existence is Domain concern?
This is my specific situation:
I am following DDD and Event sourcing to implement my application (using C#). I have a Domain layer that contains Aggregates' implementation. I write unit tests for this ...
0
votes
3
answers
543
views
Should test cases show desired behavior or actual/current behavior, or can they do both?
Let's say I want to add tests to a software that has some flaws/bugs.
I want to add the tests before I fix the bugs. And I want to actually merge them in the main branch, not just have them in a ...
-2
votes
2
answers
91
views
Should application state be tested when testing Api?
I am trying to adpot a TDD process. I am a bit confused when it comes to testing an Api. I know for sure that the status and the response should be tested.
But I am thinking if whether or not I should ...
2
votes
2
answers
435
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 ...
3
votes
3
answers
346
views
TDD and Unit Testing for new code, but existing patterns
How should I go about using TDD and writing tests in this scenario?
Suppose we have request handler classes. In short, a handler applies a "request" (e.g. Update details) to an entity then ...
5
votes
3
answers
932
views
Where to specify mock behavior in Given-When-then syntax?
I am unsure where/how to specify the behavior of a mock in a test scenario when using the Given-When-Then syntax.
It seems to me both Given and When could be correct.
Consider the following example:
...
2
votes
2
answers
605
views
Testing edge cases in TDD? [duplicate]
When doing TDD "by the book" we should only -- as far as I understand -- write failing tests. This means tests for unimplemented functionality.
I often find myself wanting to add tests for ...
5
votes
3
answers
1k
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 ...
4
votes
4
answers
406
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
233
views
Given a function that has already been unit tested, but is present in another unit, should I bother testing it again?
Say, for instance, I have this simple function in my domain layer:
function canCreateNewUsers (principal: User): boolean {
return principal.isSuperAdmin || principal.isAdmin // || ... a bunch of ...
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 ...
3
votes
1
answer
198
views
Simulation Testing: how to test something that depends on its previous state
I'm practicing test driven development while implementing a network simulator: devices communicate with each other and implement little bits of functionality that respond to messages. Each device has ...
0
votes
4
answers
340
views
Change architecture design to API to reduce coupling
I was reading articles about TDD and I found the following one. https://blog.cleancoder.com/uncle-bob/2017/03/03/TDD-Harms-Architecture.html
In order to answer this question I think someone should ...
1
vote
1
answer
320
views
How to write tests in TDD for downloading and unpacking a file?
So I want to write this function that downloads a file and unpacks it in python using TDD.
The function will look like this approximately
import urllib.request
import tarfile
def download_and_unpack(...
1
vote
2
answers
274
views
Best Practice: Unit test coverage vs. in-method sanity checks [duplicate]
I have a code-coverage requirement of of a certain percentage, and face the following tradeoff:
Should I sacrifice in-method sanity checks and error handling for ease of (unit-) testability?
Lets ...
0
votes
1
answer
336
views
How to make the tests run faster?
I develop my current project with a very strict approach to TDD and try to make it as close to Kent Beck's TDD By Example book. So right now I've got code coverage of 93%, with 1290 unit test cases, ...
1
vote
2
answers
346
views
Mock part of a static method
I am designing a test for an existing static method:
public static boolean hasPermissions(String username, int pageid) {
PermissionsService s = new PermissionsService();
int[] pages = s....