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
49
votes
14 answers

How to run unit-tests in all browsers?

I've never used Selenium but I guess it's for simulating user interaction in all browsers. That's like integration tests. But how do you test your js libraries/frameworks (unit testing) on all the browsers in an automated way?
ajsie
  • 77,632
  • 106
  • 276
  • 381
49
votes
7 answers

Why are TDD 'Spikes' called 'Spikes?

The test driven development guys refer to a quick, exploratory, investigation that involves coding something up to see if it works, a spike. Any ideas why they came up with that word? Update: The coinage by Kent Beck looks like the 'original' one to…
mackenir
  • 10,801
  • 16
  • 68
  • 100
49
votes
4 answers

Is there any framework for .NET to populate test data?

I am use c# and for unit testing and integration testing usually I need to populate fields automatically based on attributes. Lets say we will test if we can write and get back user data to database. I create a user object populate fields write…
ilker Aksu
  • 619
  • 1
  • 5
  • 8
49
votes
3 answers

.NET unit testing projects organisation

What would you say is the best way to manage the unit tests in a large .net application? Is it better to add a test project for each separate project in the solution or one large tests project for all the tests in the rest of the projects? For…
alxbrd
  • 1,675
  • 1
  • 15
  • 16
47
votes
14 answers

What is a good sample class to demonstrate TDD?

I need to give a short presentation (2-4 hours) on Test-Driven Development and need to come up with a small class that I can build using the TDD methodology. The class has to be relatively small, but "sell" the concept of TDD. If anyone has read…
SergioL
  • 4,905
  • 3
  • 26
  • 30
47
votes
9 answers

Why is design-by-contract not so popular compared to test-driven development?

You may think this question is like this question asked on StackOverflow earlier. But I am trying to look at things differently. In TDD, we write tests that include different conditions, criteria, verification code. If a class passes all these tests…
Perpetualcoder
  • 13,501
  • 9
  • 64
  • 99
47
votes
1 answer

How can I unit test my ASP.NET MVC controller that uses FormsAuthentication?

I'm working with a ASP.NET MVC solution in a test driven manner and I want to login a user to my application using forms authentication. The code I would like to end up with in the controller looks something like…
maz
  • 2,466
  • 1
  • 25
  • 32
47
votes
4 answers

Does TDD include integration tests?

I'm working on some code that includes database access. Does test-driven development include integration tests as well as the usual unit tests? Thanks!
Jon Onstott
  • 13,499
  • 16
  • 80
  • 133
47
votes
14 answers

TDD: Does it get in the way of good API design?

I've never written TDD code, but I've seen a decent amount of discussion about it here on SO. My biggest concern with it is that it seems like general good API design (for flexibility, ease of use, simplicity of interface, and performance) takes a…
dsimcha
  • 67,514
  • 53
  • 213
  • 334
46
votes
7 answers

How to force VS 2010 to skip "builds" of projects which haven't changed?

Our product's solution has more than 100+ projects (500+ksloc of production code). Most of them are C# projects but we also have few using C++/CLI to bridge communication with native code. Rebuilding the whole solution takes several minutes.…
Ladislav Mrnka
  • 360,892
  • 59
  • 660
  • 670
46
votes
5 answers

Fake DbContext of Entity Framework 4.1 to Test

I'm using this tutorial to Fake my DbContext and test: http://refactorthis.wordpress.com/2011/05/31/mock-faking-dbcontext-in-entity-framework-4-1-with-a-generic-repository/ But i have to change the FakeMainModuleContext implementation to use in my…
Acaz Souza
  • 8,311
  • 11
  • 54
  • 97
46
votes
2 answers

Moq - mock.Raise should raise event in tested unit without having a Setup

I have a presenter class, that attaches an event of the injected view. Now I would like to test the presenter reacting correctly to the event. This is the view interface IView: public interface IView { event EventHandler MyEvent; void…
Yannik
  • 709
  • 1
  • 7
  • 11
46
votes
6 answers

Mocking Static methods using Rhino.Mocks

Is it possible to mock a static method using Rhino.Mocks? If Rhino does not support this, is there a pattern or something which would let me accomplish the same?
abhilash
  • 5,605
  • 3
  • 36
  • 59
46
votes
3 answers

How to attach a message to RSpec check?

In RSpec: Can I attach a message to a check the same way as I would do in xUnit style test frameworks? How? assert_equal value1, value2, 'something is wrong'
Alexey
  • 9,197
  • 5
  • 64
  • 76
46
votes
2 answers

Rspec: expect vs expect with block - what's the difference?

Just learning rspec syntax and I noticed that this code works: context "given a bad list of players" do let(:bad_players) { {} } it "fails to create given a bad player list" do expect{ Team.new("Random", bad_players) }.to…
Amit Erandole
  • 11,995
  • 23
  • 65
  • 103