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.

learn more… | top users | synonyms (2)

3
votes
2answers
77 views

How would one test a function with a large number of scenarios?

I've heard that it's ideal to have one assert (or expect or should, etc) per aspect of a component's behavior you're trying to test. Is this how it works? An addOne function would be tested like this, ...
58
votes
10answers
6k views

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 ...
4
votes
3answers
163 views

Role and importance of static method in OOP

Background Thinking about OOP I feel that it binds data and behavior together, taking the real world example we already have array data type which is a collection of homogeneous type but in Java we ...
0
votes
0answers
30 views

Testing a factory service, am I doing it right?

I'm trying to integrate Pagerfanta in my Symfony application, so instead of creating the paginator objects in the controllers, I created an factory for instantiating the Pagerfanta objects: <?php ...
0
votes
0answers
38 views

What to do to during unit testing [duplicate]

I have trouble understanding what to do when unit testing. All over the web I find tutorial for how to use unit testing but it is always just tutorials about how the unit testing tools are working but ...
0
votes
1answer
82 views

Dependency Injection (DI) and Dependency Inversion Principle (DIP) for built-in functions and external libraries

Question I apologize if this question has already been posted. I tried searching but I couldn't find the answer. I often find myself trying to use DI and DIP where I need to open a file or a socket. ...
0
votes
0answers
51 views

Designing a DOM dependent library

Suppose for fun and learning purpose I need to write a library for forms then, how should I start? to be more descriptive let me summarize my doubts: For beginning I want to restrict myself to just ...
18
votes
5answers
623 views

Agile without unit tests

Does it make sense to talk about "agile development" or claiming that you are applying an "agile methodology" if the code base you are working on has 0% unit test coverage? (And you, as a team, are ...
7
votes
3answers
248 views

How to combine strict TDD and DDD?

TDD is about designing code, guided by tests. Thus, typical layers aren't usually built upfront; they should slightly appear through refactoring steps. Domain-driven design involves a lot of ...
20
votes
6answers
2k views

How to remove a function or feature when using TDD

In texts about TDD I often read about "remove duplication" or "improve readability" during the refactoring step. But what makes me remove an unused function? For example let's say there is a class C ...
2
votes
4answers
150 views

Unit Test for Void which copies data from one location to another

Still learning and getting my head around Unit Testing, (also trying to get into TDD, though I appreciate it isn't the same thing) and in many ways it is changing/improving my code. But I come across ...
5
votes
3answers
185 views

Should unit tests always overlap

This is a test design question. I have a class 'handler' that accepts a 'validator' that checks some business logic on what's passed to the handler. I made the unit tests for the validator and now I'...
7
votes
3answers
261 views

In test-driven development, are there good reasons not to write multiple failing tests and only then to make them pass?

Uncle Bob's three rules of test-driven development state the following: You are not allowed to write any production code unless it is to make a failing unit test pass. You are not allowed to ...
0
votes
3answers
110 views

Determining the optimal amount of unit tests?

I think I may be writing -too- many unit tests. For example, say I was doing a coursework management system, and I coded a feature for submitting coursework on behalf of a student. If invalid ...
0
votes
3answers
126 views

How to write testcases for a piece of logic? [closed]

I want to learn how to write testcases for a piece of logic like unit tests. Now I am not concerned about any specific framework or language, just wanted to know how can I get learn to write input-...
2
votes
2answers
145 views

Are DDD aggregates a good boundary for unit testing?

An aggregate can represent a somewhat stable system boundary. Does it make sense to write input and output test aggregates to do most testing? In theory we could use an aggregate as a data driven way ...
4
votes
1answer
212 views

How to Structure Simple C++ projects for TDD

I am introducing Google Test into our development environment at work, and would like to encourage a TDD mindset, making this as accessible as possible for new developers to start using. I am looking ...
2
votes
0answers
61 views

Should I TDD correct view returned from controller?

I have been reading the following Uncle Bob post on TDD. He explains that there are cases where TDD is not needed. Mainly in a case where your tests and code are both very specific, and your code is ...
3
votes
0answers
86 views

How to think about a schedule that pulls from a database as objects

I am working on a personal project using Python. I have been using version control to the best of my abilities and if you would like to check it out and run the app https://github.com/CodeAmend/old-...
3
votes
3answers
245 views

Unit Testing and 3rd party packages. Do I mock or not?

I'm just getting used to unit testing and on my new project I decided to adopt a TDD approach. My code below is to test the UserServices class which is responsible for creating a user, deleting a ...
0
votes
2answers
217 views

Should a Junior programmer add TDD tests to mvc project

I'm a junior programmer near to my 6 month probation, following my initial career changing 3 month assignment in which I added TDD tests and wondering whether I should add tests to my current work. ...
-2
votes
3answers
182 views

What is the most elemental workflow for TDD?

Gradle is such an interesting build tool that it prompted me to look at Spock and JUnit -- which I've never done before. What is the basic workflow with TDD? My approach has been to do frequent ...
4
votes
2answers
101 views

How do you evaluate automated testing for a particular product/project?

Automated testing is pretty hyped-up in recent years, with particular emphasis on TDD at the "unit" level. The touted advantages include things like: Stabilizing existing code: breaking changes are ...
3
votes
2answers
349 views

Differences between Given When Then (GWT) and Arrange Act Assert (AAA)?

In TDD there is Arrange Act Assert (AAA) syntax: [Test] public void Test_ReturnItemForRefund_ReturnsStockOfBlackSweatersAsTwo_WhenOneInStockAndOneIsReturned() { //Arrange ShopStock shopStock =...
0
votes
3answers
128 views

At what point in a projects life-cycle do you begin writing tests? [duplicate]

I'm not in the field, so I don't have any professional experience from projects following the TDD design. I am trying to adopt this pattern, but I'm confused as to when I start actually writing the ...
0
votes
1answer
95 views

TDD with a half baked Java EE application

I am a second year Computer Science student currently on a placement and I am currently developing a Java EE application that collects meta data from several sources and then visualises the data. This ...
6
votes
2answers
343 views

How does breaking up a big method into smaller methods improve unit testability when the methods are all private?

I'm presently reading Building Maintainable Software by Joost Visser and some of the maintenance guidelines they recommend include: A) each unit/method should be short (less than 15 lines per method) ...
3
votes
1answer
121 views

How to move Python doctest examples into another unit test framework?

Years ago AFAIK the mathematitician and software developer Tim Peters discovered that very often the documentation of APIs tends to get out of date over time during the software live cycle, because ...
5
votes
5answers
364 views

Can we add methods which is easier for assertion in test and which is only used in tests when TDD?

Here let me take a simple parking boy example. A parking boy can manage several parking lots, and when a car comes, he will park the car into some parking lot and can also help to un-park the car. ...
9
votes
2answers
503 views

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 ...
0
votes
1answer
72 views

Reusing array with static test data across test classes

I have a Map which takes in an a String key, and an array of custom objects as the value. the map usually contains two entries, and the arrays for both entries never change in terms of data; once they ...
0
votes
1answer
166 views

Testing a function that only calls one or two other functions [duplicate]

The short version The code As part of TDD, we often end up with functions that follow this pattern: function onSendRequestForSelected() { this.deselectStepsWithRequest(); this....
-1
votes
1answer
123 views

What is the difference between a mock and a test double? [closed]

I was reading an article here on Mocks. I would like to conclude to make my understanding more clear. Anything that can be placed in place of a real object while testing is called a Test Double. ...
1
vote
1answer
54 views

What is the preferred way of preparing data in automatic testing

Lets say I want to test a method of a class representing a user account. I have a fixture which contains several user records from which I want to choose one. What is the preferred method here? Pick ...
0
votes
1answer
132 views

TDD - Outside In developemnt

I'm pretty comfortable with the core concepts of Outside In (especially from this question). However one thing eludes me concerning the mocks you created at each level which then lead to creating the ...
1
vote
2answers
178 views

Ways of creating expected object for assert

Recently, I started to use TDD. It's really cool and fun but creating expected object for assertEquals is very boring and tedious. At the moment I see only two way for that: Straightforward Creating ...
0
votes
1answer
260 views

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? ...
-2
votes
3answers
160 views

TDD/BDD: Mocks with expectations: bad? [closed]

Is using mocks in the following way a bad idea: writing tests where mocks expect certain calls from the subject under test Or even just writing mocks that return values to the subject under test if/...
2
votes
1answer
172 views

TDD: How to test domain model

When practicing TDD, how do you test a domain model? If you don't test, how do you account for code coverage? We want to have 100% coverage (or as much as possible), but despite hours of training ...
2
votes
1answer
162 views

TDD/BDD - Properly defining tests, adjusting tests, putting describe blocks inside it blocks

I am coming around with TDD/BDD. I am a bit confused though, when it comes to initially writing my BDD tests and then adding more tests after the very broad tests. For Example, lets say that I am ...
1
vote
1answer
197 views

How to test a REST service without being excessive

So I have a REST backend (in node.js or Java doesn't matter but the example is in js). I try to have a service for each endpoint so that the /users endpoint has two files: usersRouter.js which ...
3
votes
2answers
214 views

Writing your test assertions in your function comments (just before the code)?

I'm using PHP and PHPUnit. Something bothers me: the fact that the assertions are in another class (too easy to forget or to ignore, for any new programmer in the project). If the test assertions ...
2
votes
1answer
63 views

TDD Duplicate Testing on Related Classes

In following the principle of testing only the exported functions on a package (using Go - or for others languages, the public functions on a class), I'm running into a scenario where related packages ...
1
vote
2answers
187 views

Better application design - where to place interfaces

Where to place interfaces in a typical multi-layered app with DataAccess, BusinessLogic and an Endpoint modules? I propose 2 options In both cases there's only dependency from abstractions, but in ...
4
votes
1answer
142 views

Refactoring numerical code for TDD and encapsulation

I am coming to terms with TDD, and the fact that I need to re-factor some code that I'm (re)writing. I am having a problem that I think is a classic conflict---TDD vs. encapsulation of private methods/...
0
votes
2answers
72 views

Best practices for testing deep objects?

I'm writing in javascript with 'should' library, but this doesn't matter. I should write test for method, which returns a quite big object with a lot of fields. How I should write my expected result? ...
9
votes
3answers
286 views

Cross-language Test-Driven Development

The short question: How do you follow Test-Driven Development on a project that spans multiple languages? Specifically, I'm writing a web application that uses JavaScript and PHP, and I want to ...
35
votes
7answers
4k views

Is there a need to keep tests for simple (self-contained) functions?

Consider this: public function polynominal($a, $b, $c, $d) { return $a * pow($x, 3) + $b * pow($x, 2) + $c * $x + $d; } Suppose you write various tests for the above function and prove to ...
4
votes
1answer
455 views

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 ...