Questions tagged [tdd]

Test-Driven Development (TDD) involves writing a failing automated test to specify what is to be built. The test is then made to pass by writing code which satisfies the tested condition. Finally, the code is refactored.

Test-Driven Development (TDD) is a software development process that relies on the repetition of a very short development cycle: first the developer writes a failing automated test case that defines a desired improvement or new function, then produces code to pass that test and finally refactors the new code to remove duplication and to improve its design.

TDD tends to lead to low-coupled, highly-cohesive designs, with no more functionality than necessary to satisfy requirements. The test serves as the first consumer of the new interface, and provides immediate feedback on its clarity and usability. Developers give themselves an incentive to write easily testable, stateless, simple modules; all hallmarks of good design according to the SOLID design principles.

It is one of the practices of Extreme Programming. It is often said that TDD is not about testing, but rather about design.

Hello World:

def test_hello_world
  assert.are_equal "hello world", hello_world
end
6135 questions
57
votes
4 answers

How to write testable controllers with private methods in AngularJs?

Alright, so I have been stumbling upon some issue for a long time and I would like to hear an opinion from the rest of community. First, let's look at some abstract controller. function Ctrl($scope, anyService) { $scope.field = "field"; …
ŁukaszBachman
  • 33,595
  • 11
  • 64
  • 74
56
votes
8 answers

Is there a difference between TDD and Test First Development (or Test First Programming)?

Both ideas sound very similar to me, but there might be subtle differences or the exact same thing, explained in different ways. What is the relationship between TDD and Test First Development/Programming?
Thomas Owens
  • 114,398
  • 98
  • 311
  • 431
56
votes
3 answers

How do I unit test django urls?

I have achieved 100% test coverage in my application everywhere except my urls.py. Do you have any recommendations for how I could write meaningful unit tests for my URLs? FWIW This question has arisen as I am experimenting with Test-Driven…
meshy
  • 8,470
  • 9
  • 51
  • 73
55
votes
3 answers

Unit testing Scala

I just recently started learning the Scala language and would like to do it in TDD-way. Could you share your experiences on the unit testing frameworks there are for Scala and the pros/cons of them. I'm using IntelliJ IDEA for Scala development, so…
Kaitsu
  • 4,094
  • 3
  • 30
  • 37
54
votes
8 answers

How do I put new List {1} in an NUNIT TestCase?

I have the method: public static int Add(List numbers) { if (numbers == null || numbers.Count == 0) return 0; if (numbers.Count == 1) return numbers[0]; throw new…
xaisoft
  • 3,343
  • 8
  • 44
  • 72
53
votes
9 answers

Applying TDD when the application is 100% CRUD

I routinely run into this problem, and I'm not sure how to get past this hurdle. I really want to start learning and applying Test-Driven-Development (or BDD, or whatever) but it seems like every application I do where I want to apply is it pretty…
Wayne Molina
  • 19,158
  • 26
  • 98
  • 163
53
votes
4 answers

When to use mocking versus faking in C# unit testing?

Can anyone come up with guidelines suggesting the ideal scenarios to choose mocking versus faking, i.e., setting up the essentials manually? I am a bit confused with how to approach this situation.
vijaysylvester
  • 4,750
  • 7
  • 29
  • 41
53
votes
5 answers

Is it impossible to use Guard with RubyMine?

For some inexplicable reason, RubyMine autosaves every change you make and so every key stroke will trigger Guard to run your tests! And the most ridiculous thing is that there's apparently no way to disable this autosaving "feature". I'm just…
yiinewbie
  • 1,055
  • 2
  • 12
  • 19
52
votes
3 answers

How to use RSpec without Rails?

What is the process for doing TDD in Ruby with RSpec without Rails? Do I need a Gemfile? Does it only need rspec in it? Ruby 1.9.3
B Seven
  • 44,484
  • 66
  • 240
  • 385
51
votes
11 answers

"Web interface" to PHPUnit tests?

Is there a simple "Web interface" to running PHPUnit test suites? i.e. a PHP script that runs the test on the command line, and outputs a nicely formatted HTML result. I develop web applications, and the day-to-day workflow usually switches between…
Pekka
  • 442,112
  • 142
  • 972
  • 1,088
51
votes
4 answers

Test-Driven Development - How to write a test before none of implementation code exists

I'm learning TDD but struggling to adopt it as it's not straightforward. The question I cannot answer is "How to write a test before any of implementation code exists?". If our target class / target method / target parameter type / target return…
phanin
  • 5,327
  • 5
  • 32
  • 50
50
votes
7 answers

Test driven development book

What book would you recommend to learn test driven development? Preferrably language agnostic.
Jakub Arnold
  • 85,596
  • 89
  • 230
  • 327
50
votes
10 answers

How do I unit test persistence?

As a novice in practicing test-driven development, I often end up in a quandary as to how to unit test persistence to a database. I know that technically this would be an integration test (not a unit test), but I want to find out the best strategies…
Jon Limjap
  • 94,284
  • 15
  • 101
  • 152
50
votes
8 answers

Bash and Test-Driven Development

When writing more than a trivial script in bash, I often wonder how to make the code testable. It is typically hard to write tests for bash code, due to the fact that it is low on functions that take a value and return a value, and high on functions…
Chen Levy
  • 15,438
  • 17
  • 74
  • 92
49
votes
3 answers

How to include Rails Helpers on RSpec

I'm trying to include some helpers to test with rspec but no luck. What I did: created a support/helpers.rb file under my spec folder. support/helpers.rb module Helpers include ActionView::Helpers::NumberHelper include…
Kleber S.
  • 8,110
  • 6
  • 43
  • 69