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
79
votes
9 answers

How to test JSON result from Ruby on Rails functional tests?

How can I assert my Ajax request and test the JSON output from Ruby on Rails functional tests?
William Yeung
  • 10,368
  • 9
  • 36
  • 42
78
votes
12 answers

Unit tests on MVC validation

How can I test that my controller action is putting the correct errors in the ModelState when validating an entity, when I'm using DataAnnotation validation in MVC 2 Preview 1? Some code to illustrate. First, the action: [HttpPost] public…
Matthew Groves
  • 25,181
  • 9
  • 71
  • 121
77
votes
10 answers

How do you mock a Sealed class?

Mocking sealed classes can be quite a pain. I currently favor an Adapter pattern to handle this, but something about just keeps feels weird. So, What is the best way you mock sealed classes? Java answers are more than welcome. In fact, I would…
Brett Veenstra
  • 47,674
  • 18
  • 70
  • 86
74
votes
3 answers

GoogleTest vs CppUnit: The facts

In the process of setting our C++ unit testing framework for the next years we shortlisted GoogleTest and CppUnit. I have some experience with both and my heavy preference is GoogleTest. Anyways to convince my boss I need some facts so I did some…
EstuansInterius
  • 849
  • 1
  • 7
  • 5
74
votes
5 answers

Unit Tests vs. Acceptance Tests

Are you for one or the other? Or both? My understanding is unit tests: validate the system from the developer's point of view help developers practice TDD keep code modular assist in detecting errors at low levels of granularity Acceptance…
Calvin
  • 825
  • 1
  • 8
  • 5
72
votes
11 answers

BDD and TDD for node.js?

What is used for BDD and TDD with node.js? I'm used to use Cucumber + RSpec. What's a good combo for node.js? thanks
donald
  • 23,587
  • 42
  • 142
  • 223
72
votes
8 answers

How to set execution order of mocha test cases in multiple files

I have two javascript files which contain mocha test cases. //----------abc.js ------------- describe("abc file", function(){ it("test 1" , function(){ assert.equal(20 , 20); }); }); //---------xyz.js-------------- describe("xyz file",…
tnishada
  • 1,315
  • 1
  • 16
  • 24
72
votes
4 answers

PHPUnit: how do I mock multiple method calls with multiple arguments?

I am writing a unit test for a method using PHPUnit. The method I am testing makes a call to the same method on the same object 3 times but with different sets of arguments. My question is similar to the questions asked here and here The questions…
Thomas
  • 962
  • 1
  • 6
  • 12
70
votes
6 answers

How to do TDD and unit testing in powershell?

With MS ramming powershell into all new server products, I'm starting to (reluctantly) think I need to take it seriously. Part of "taking it seriously" is TDD. Have you found good methods to unit test power shell scripts? I've found samples of…
Precipitous
  • 5,253
  • 4
  • 28
  • 34
70
votes
19 answers

Unit test adoption

We have tried to introduce unit testing to our current project but it doesn't seem to be working. The extra code seems to have become a maintenance headache as when our internal Framework changes we have to go around and fix any unit tests that hang…
Burt
  • 7,680
  • 18
  • 71
  • 127
70
votes
17 answers

What does regression test mean?

Could anyone explain the word regression test in an understandable way?
never_had_a_name
  • 90,630
  • 105
  • 267
  • 383
70
votes
7 answers

Best way to create a test database and load fixtures on Symfony 2 WebTestCase?

I have a WebTestCase that executes some basic routes in my application. I want to, on the setUp method of PHPUnit, create a test database identical to my main database, and load fixtures into it. I'm currently doing some workaround and executing…
Daniel Ribeiro
  • 10,156
  • 12
  • 47
  • 79
65
votes
4 answers

How can I load this file into an NUnit Test?

I have the following IntegrationTest project structure ... If i wish to use that test data 126.txt in an NUnit Test, how do I load that plain txt file data? NOTE: The file is -linked- and I'm using c# (as noted by the image). cheers :)
Pure.Krome
  • 84,693
  • 113
  • 396
  • 647
65
votes
6 answers

How do I test database-related code with NUnit?

I want to write unit tests with NUnit that hit the database. I'd like to have the database in a consistent state for each test. I thought transactions would allow me to "undo" each test so I searched around and found several articles from 2004-05 on…
Michael Haren
  • 105,752
  • 40
  • 168
  • 205
65
votes
18 answers

When to rewrite a code base from scratch

I think back to Joel Spolsky's article about never rewriting code from scratch. To sum up his argument: The code doesn't get rusty, and while it may not look pretty after many maintenance releases, if it works, it works. The end user doesn't care…
Jack Marchetti
  • 15,536
  • 14
  • 81
  • 117