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.
617
questions
13
votes
3answers
1k views
How do you push Design changes in TDD in late development stage
I was recently part of a TDD development team. At certain point I realized that there is a design mistake instead of Object Oriented Design and Structural design the problems were solved via statuses. ...
-4
votes
2answers
89 views
What is the most complete way to test an imperative function?
What is the most complete way to test an imperative function? By "complete" I mean, something that is robust, that tests all the edge cases of the function, that so much as "proves"...
6
votes
3answers
340 views
Is there a logical complexity beyond which TDD doesn't work?
All the books which talk about test-driven development (TDD) illustrate it with only very basic examples, less than 100 LOC.
The algorithms I wrote using TDD were larger, but still relatively small in ...
0
votes
2answers
92 views
How to write the test for a class function which depends on another function to be tested in TDD approach?
I have a class
class A {
List<int> a;
A() {
this.a = [];
}
void add(int x) {
a.append(x)
}
List<int> display() {
return a;
}
}
This is a simple class I want to ...
-2
votes
3answers
105 views
Can TDD and White-box testing be combined directly?
I am getting started with software testing in Java and was wondering if test-driven dev and white-box testing could be combined directly... If not, what ways can we extend TDD to combine white box ...
0
votes
1answer
58 views
Properly testing UI presenters without duplicating tests of subcomponents
I am writing the embedded firmware for an effect pedal. The pedal's ui consists of a few knobs
a few buttons and a few leds and it consists of various control modes each corresponding to a seperate ...
-6
votes
1answer
114 views
Why is automatically generating automated tests frowned upon?
First, the most obvious grouse someone has against this I can think of is the intricacies of an actual method. It's not enough to merely ensure no errors are thrown. Functions usually contain ...
-1
votes
3answers
111 views
Should methods with business logic be made private? [duplicate]
So I am writing a project using Spring Boot. All of my logic resides in @Service classes. I have separated each service class based on entity. For example - If I have two independent entities A and B, ...
1
vote
2answers
120 views
C++ Organizing classes for easy unit testing (but with some restrictions)
Mild pickle. I have a project which has components that are difficult to test/mock. It might look something like this:
class Contenxt;
class Server : public SomeOtherClass
{
public:
ServerPlugin(...
11
votes
2answers
2k views
Does TDD contradict the open-closed principle?
My understanding of the TDD methodology is that (failing) test cases are written promptly after finalizing the requirements.
My understanding of the open-closed principle (in the context of OOP) is to ...
0
votes
1answer
79 views
How do I plan my refactor of my android app for better architecture?
The current structure of my app is as follows:
One activity and multiple fragments (about 25 fragments)
One huge monolithic repository
One huge monolithic viewmodel
Databinding is being used but with ...
1
vote
1answer
530 views
Test driven development on front end?
When reading through internet, I've seen people are really into testing the front end applications. Some of them also say that they will never hire someone on front end who doesn't have testing ...
41
votes
7answers
8k 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 ...
0
votes
6answers
274 views
TDD - Make the test work quickly, committing whatever sins necessary in process
Red-Green-Refactor
Green stage says, Make the test work quickly, committing whatever sins necessary in process
Having an idea of writing a test & make it work quickly, does not look intuitive ...
-1
votes
1answer
132 views
Is the self-shunt pattern the same as stubbing in TDD?
I am reading the book TDD by Example and one of the patterns demonstrated was the self-shunt pattern.
Basically, if I am not mistaken, if I have a test like this:
test("list of users should receive ...
-2
votes
1answer
52 views
Xunit TDD - second rule
What is the meaning of:
You are not allowed to write any more of a unit test than is sufficient to fail; and compilation failures are failure
by Robert Martin on TDD? Is it write only the needed ...
0
votes
0answers
37 views
Unit testing an inductive problem? [duplicate]
I am developing a function that produces an inherently inductive output (calculating periods based on a start and end date).
E.g., period n depends on the calculation on period n-1 and so forth.
...
-1
votes
1answer
100 views
How to do test-driven front end development?
I'm trying to rapidly develop my frontend, but every time I change my code I find myself refreshing my browser and running some macro to test whether the changes in my code solved the problem.
I ...
1
vote
3answers
243 views
How does TDD behave when the tested unit needs to be expanded?
I want to write some invoicing logic, and I start coding it, using TDD.
The following example is silly, but I'm confident it represents well the everyday dilemma I'm facing
function ...
3
votes
3answers
208 views
TDD and GIT workflow. How big should branches be?
Let's say we are using TDD while developing some Calculator class (the simplest case - it should provide add, sub, mul and div public methods). We initially start with develop branch. The following ...
-1
votes
2answers
73 views
Code Review for Automated Unit Tests [duplicate]
Writing automated unit tests is followed as a part of our development process.
We also do have an established code review process for the development code that is written.
Should the test code be ...
1
vote
1answer
116 views
Persistence layer in the automated testing of an API
The automated tests of an API should be stable and simple.
When writing automated tests for an API, we often have to check that the data created with a program implementing this API is persistent. If ...
-4
votes
2answers
117 views
Why use Assertion Library when there is print and console.log?
I'm new to TDD. That begin said, I'm trying to understand why would I have to use assertion library when there is console.log/print?
In-fact, I can see more detailed error log thru console.log in ...
4
votes
3answers
328 views
Testing unexpected inputs for unit tests and loops?
I'm working on an enterprise that has some Angular/Typescript projects and to avoid repeating code (basically copying and pasting) between them, we decided to go for Monorepo and start write an util ...
-4
votes
2answers
58 views
TDD Implementation
How do you successfully adopt TDD in an organization? Training alone is not enough in my opinion as I feel it requires a change in process and mindset. If TDD has been implemented in your organization ...
2
votes
3answers
110 views
How to write Given/When/Then Scenarios without Given and When being the same
Given that I want to write a Given/When/Then scenario
When I write a Given/When/Then scenario
Then my Given and When are generally the same thing
I've been trying to practice writing user stories in ...
0
votes
1answer
197 views
How to avoid “mock returning mock” when using factory pattern
I have recently encountered multiple articles with title Everytime a mock returns a mock a fairy dies And I ran into exact same situation while using factory class in my code. I am writing a sample ...
2
votes
1answer
409 views
What is the origin of TDD?
I have seen people point me to many different "origins" of TDD. Some will point me to Kent Beck's rediscovery in the late 1990s with XP. Others will mention the 1960s best practice of annotating the ...
125
votes
14answers
30k views
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 ...
2
votes
3answers
1k views
How to maintain XML/JSON serialization tests?
It is quite common to test JSON / XML producing methods against file-stored expected output (at least in Java world, but probably in other environments, too).
For instance there's a method that ...
1
vote
3answers
1k views
In TDD, is it bad practice to write helper class for unit tests?
Sometimes when writing a unit test using Test Driven Development (TDD) one may find that checking if the result is the correct one is "more complicated than one line of code", probably deserving its ...
35
votes
10answers
9k views
In TDD, should I add unit tests to refactored code?
While refactoring my code using Test Driven Development (TDD), should I keep making new test cases for the new refactored code I am writing?
This question is bases on the following TDD steps:
Write ...
1
vote
2answers
253 views
How to convert from TDD scripts to BDD?
There are TDD automation scripts ready and running. TDD tests are written in granular level(class, functions, module) and BDD is written in Behavior level. Is it feasible convert this TDD script to ...
0
votes
1answer
142 views
Does it make sense to write one unit test and loop it through similar components?
I have a situation where I have different forms, each with 4 or 5 steps (components), and I decided to write one unit test per step.
After doing it, I noticed they were very similar and I could just ...
1
vote
2answers
78 views
Laravel Controller Testing
This is the first time I tried TDD.
At the first time, my controller tests looks like this
use RefreshDatabase;
class ControllerCustomerIndustryTest extends TestCase
{
use RefreshDatabase;
...
24
votes
3answers
6k views
Struggling with cyclical dependencies in unit tests
I'm trying to practice TDD, by using it to develop a simple like Bit Vector. I happen to be using Swift, but this is a language-agnostic question.
My BitVector is a struct that stores a single UInt64,...
2
votes
3answers
2k views
TDD: Create a Game logic using Test-First Programming
I'm implementing a simple command line game using TDD principles and Unit Testing. My goal is to implement the whole game using Test-First Programming, so every behaviour/class is created from a test.
...
0
votes
1answer
80 views
Is it bad practice to have a helper package in go for testing purposes. Or is this introducing dependence's
I find myself repeating the same code when writing unit tests, for example... When writing functions that work with files, In the setup for the test i often write some code to create a file (in a ...
0
votes
1answer
119 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, ...
1
vote
4answers
538 views
Is it bad practice to repeat logic being tested in unit tests?
Often I find myself writing a unit test for code and repeating some or a lot of the logic in the unit test to make the unit test DRY.
For example, consider the following piece of code:
function ...
1
vote
1answer
325 views
Applying BDD accross multiple microservices
I'm involved in a microservices based application. I'm trying to apply the BDD process for this. I need a recommendation how to apply this process correctly given this type of architecture. It is ...
2
votes
4answers
555 views
In TDD, should we specifiy all classes to implement before start coding
My team is interested to apply TDD in our next software project. We have a discussion about how many details should be specified in design specs before the developers start coding.
Some of us propose ...
0
votes
2answers
540 views
How to avoid ad hoc constructor for unit testing
According to the answer in this post Should my classes have separate constructors just for unit testing?
ad hoc constructor is not good and should be avoided.
Unfortunately, I have the same problem ...
1
vote
4answers
437 views
Is it still TDD if I follow the cycle for each method alone?
The question is not very expressive, anyway what I was wondering is if, if I follow the red-green-refactor cycle for each method is still TDD or if it has to be done globally.
I mean, let's say I have ...
1
vote
3answers
213 views
What are the criterion to understand if someone used TDD?
I'm approaching the TDD methodology for software development, reading guides and writing simple applications, because a client of my company wants a software and asked to develop it using TDD ...
-3
votes
1answer
2k views
What should I test with unit tests for data access layer? (MongoDB)
I'm working in TDD for my data access layer in MongoDB and I don't know what should I test?
I think that I shouldn't test if the queries return what they have to return because It's a MongoDB concern....
0
votes
3answers
177 views
Is is worth the time to create a list of manual regression tests for a legacy application?
I am part of a new dev team that is assigned to work on a legacy app. The app currently has no regression or automated unit, integration and system tests.
Due to technical debt and convoluted ...
2
votes
2answers
229 views
TDD how to avoid test duplication across team
Our team has decided to develop using BDD/TDD in an effort to become the Agile team we're supposed to be. Vertical slicing appears to be an important part of agile working and gaining the quick ...
-2
votes
1answer
213 views
Unit Tests - correct approach to test system with multiple layers
I'm wondering about Unit Tests. Let say i got a code ( in C#, but language is not important here):
public class SOT: ISOT
{
List<string> _internalCollection = new List<string>();
...
1
vote
1answer
127 views
Should BDD/Gherkin be used only for user visible behaviour?
We're a small team of 3 senior and 1 junior developers and I've been tasked with introducing BDD within our development process.
To say there's a lot of confusion about BDD is an understatement and ...