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
152
votes
6 answers

What is a "Stub"?

So, carrying on with my new years resolution to get more in to TDD, I am now starting to work more with Rhino Mocks. One thing I am keen to do is to make sure I really grok what I am getting into, so I wanted to check my understanding of what I have…
Rob Cooper
  • 28,567
  • 26
  • 103
  • 142
148
votes
3 answers

Jest: how to mock console when it is used by a third-party-library?

I am trying to mock console.warn/error but I can't. I use a third-party-library which calls console.warn inside it. I need to test was it called or wasn't. In my test case I was trying to stub console.warn but it didn't help. After that I was trying…
Errorpro
  • 2,253
  • 2
  • 16
  • 17
135
votes
12 answers

What are the primary differences between TDD and BDD?

Test Driven Development has been the rage in the .NET community for the last few years. Recently, I have heard grumblings in the ALT.NET community about BDD. What is it? What makes it different from TDD?
NotMyself
  • 29,209
  • 17
  • 56
  • 74
134
votes
16 answers

NUnit Test Run Order

By default nunit tests run alphabetically. Does anyone know of any way to set the execution order? Does an attribute exist for this?
Riain McAtamney
  • 6,342
  • 17
  • 49
  • 62
133
votes
11 answers

Why use JUnit for testing?

Maybe my question is a newbie one, but I can not really understand the circumstances under which I would use junit? Whether I write simple applications or larger ones I test them with the System.out statements and it seams quite easy to me. Why…
Artem Moskalev
  • 5,748
  • 11
  • 36
  • 55
129
votes
11 answers

Is there hard evidence of the ROI of unit testing?

Unit testing sounds great to me, but I'm not sure I should spend any time really learning it unless I can convince others that is has significant value. I have to convince the other programmers and, more importantly, the bean-counters in…
raven
  • 18,004
  • 16
  • 81
  • 112
128
votes
36 answers

How do you know what to test when writing unit tests?

Using C#, I need a class called User that has a username, password, active flag, first name, last name, full name, etc. There should be methods to authenticate and save a user. Do I just write a test for the methods? And do I even need to worry…
Mike Roosa
  • 4,752
  • 11
  • 40
  • 52
127
votes
6 answers

Unit Test? Integration Test? Regression Test? Acceptance Test?

Is there anyone that can clearly define these levels of testing as I find it difficult to differentiate when doing TDD or unit testing. Please if anyone can elaborate how, when to implement these?
127
votes
10 answers

How can I test that a value is "greater than or equal to" in Jasmine?

I want to confirm that a value is a decimal (or 0), so the number should be greater than or equal to zero and less than 1. describe('percent',function(){ it('should be a decimal', function() { var percent = insights.percent; …
Bryce Johnson
  • 6,689
  • 6
  • 40
  • 51
125
votes
22 answers

Mocha breakpoints using Visual Studio Code

Is it possible to add breakpoints to Mocha tests using Visual Studio Code? Normally when debugging code, one needs to configure the launch.json, setting the program attribute to the Javascript file to execute. I am not sure how to do this for Mocha…
André Vermeulen
  • 1,774
  • 4
  • 17
  • 26
124
votes
9 answers

How do I mock a class without an interface?

I am working on .NET 4.0 using C# in Windows 7. I want to test the communication between some methods using mock. The only problem is that I want to do it without implementing an interface. Is that possible? I just read a lot of topics and some…
Vinicius Seganfredo
  • 1,704
  • 3
  • 15
  • 21
123
votes
15 answers

TDD/BDD screencast/video resources

I've recently finished watching the Autumn of Agile screencasts and I'm looking for more material of similar scope. Basically, I'm looking for screencasts that present TDD/BDD process while developing somewhat "real life" applications (or parts of…
Ree
  • 6,061
  • 11
  • 48
  • 50
122
votes
1 answer

What's the difference between RSpec and Cucumber?

I have 6 months of Rails development experience. I've built a web application that's in use now with authentication and authorization and postgresql db. I'm moving on to my second Rails application but this time, after lessons learnt, I would like…
banditKing
  • 9,405
  • 28
  • 100
  • 157
120
votes
17 answers

TDD vs. Unit testing

My company is fairly new to unit testing our code. I've been reading about TDD and unit testing for some time and am convinced of their value. I've attempted to convince our team that TDD is worth the effort of learning and changing our mindsets…
Walter
  • 2,540
  • 2
  • 30
  • 38
120
votes
13 answers

Meteor test driven development

I don't see how to do test driven development in meteor. I don't see it mentioned anywhere in documentation or FAQ. I don't see any examples or anything like that. I see that some packages are using Tinytest. I would need response from developers,…
Rubycut
  • 1,646
  • 2
  • 16
  • 24