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

How do you unit test regular expressions?

I'm new to TDD, and I find RegExp quite a particular case. Is there any special way to unit test them, or may I just treat them as regular functions?
Jader Dias
  • 88,211
  • 155
  • 421
  • 625
63
votes
10 answers

Useful design patterns for unit testing/TDD?

Reading this question has helped me solidify some of the problems I've always had with unit-testing, TDD, et al. Since coming across the TDD approach to development I knew that it was the right path to follow. Reading various tutorials helped me…
Phillip B Oldham
  • 18,807
  • 20
  • 94
  • 134
63
votes
7 answers

Unit Testing of private methods in Xcode

I'm trying out test driven development in a toy project. I can get the tests working for the public interface to my classes (although I'm still on the fence because I'm writing more testing code than there is in the methods being tested). I tend to…
Abizern
  • 146,289
  • 39
  • 203
  • 257
62
votes
2 answers

Mock objects - Setup method - Test Driven Development

I am learning Test Driven Development and trying to use Moq library for mocking. What is the purpose of Setup method of Mock class?
meckrt
  • 765
  • 1
  • 5
  • 7
60
votes
1 answer

Unit Testing ASP.Net MVC 4 apps thoroughly

I realize this is a duplicate of about 20 different posts, but none of them are specific to MVC4, and none that I've seen really answer all of my questions. So far my first foray into the world of TDD has been frustrating to say the least. Most of…
Ben Lesh
  • 107,825
  • 47
  • 247
  • 232
60
votes
2 answers

PHPUnit: expects method meaning

When I create a new mock I need to call the expects method. What exactly it does? What about its arguments? $todoListMock = $this->getMock('\Model\Todo_List'); $todoListMock->expects($this->any()) ->method('getItems') …
thom
  • 691
  • 1
  • 5
  • 5
60
votes
4 answers

Why should I practice Test Driven Development and how should I start?

Lots of people talk about writing tests for their code before they start writing their code. This practice is generally known as Test Driven Development or TDD for short. What benefits do I gain from writing software this way? How do I get started…
Mike Minutillo
  • 54,079
  • 14
  • 47
  • 41
60
votes
7 answers

Team Foundation Build or TeamCity?

We are a mostly MS shop at work doing .NET LOB development. We also use MS Dynamics for our CRM app... all the devs are currently using VS/SQL Server 2008. We also use VSS, but everyone hates it at work and that is quickly on its way out. We are…
dferraro
  • 6,357
  • 11
  • 46
  • 69
60
votes
2 answers

Mocking virtual readonly properties with moq

I couldn't find a way to do this, though this can be done by hand so why not with moq?
gkdm
  • 2,375
  • 4
  • 21
  • 27
58
votes
6 answers

Running Rake tasks in Rspec Tests

I am building up an integration test suite and there is one bit of logic that I need to have a clean database for. How can I run the db:test:purge task inside of one of my tests? I am using: ruby 1.9.2, rails 3.0.9, rspec 2.6
xentek
  • 2,555
  • 2
  • 20
  • 12
58
votes
1 answer

What does "spec" mean in Javascript Testing

I'm fairly new to the Javascript world (coming from Android) so I've been reading up on how to setup Mocha/Jasmine to get my test environment in place. I've noticed a convention of "spec" in reference to test directories, file suffix, suite names,…
basudz
  • 997
  • 1
  • 6
  • 14
58
votes
4 answers

How to mock File in javascript?

I'm developing some small project to exercise my TDD skills. The project consists of an audio player which has the ability to drag'n'drop files in a playlist. I'm using Jasmine as a testing framework. The problem I faced is that I can't mock…
Eriendel
  • 911
  • 1
  • 9
  • 23
58
votes
5 answers

Moq - How to verify that a property value is set via the setter

Consider this class: public class Content { public virtual bool IsCheckedOut {get; private set;} public virtual void CheckOut() { IsCheckedOut = true; } public virtual void CheckIn() { //Do Nothing for now as…
Anton P
57
votes
10 answers

TDD and BDD Differences

I honestly don't see the difference between BDD and TDD. I mean, both are just tests if what is expected happens. I've seen BDD Tests that are so fleshed out they practically count as TDD tests, and I've seen TDD tests that are so vague that they…
Jon Abaca
  • 821
  • 1
  • 9
  • 14
57
votes
6 answers

Python library 'unittest': Generate multiple tests programmatically

Possible Duplicate: How do you generate dynamic (parameterized) unit tests in Python? I have a function to test, under_test, and a set of expected input/output pairs: [ (2, 332), (234, 99213), (9, 3), # ... ] I would like each one of these…
Nick Heiner
  • 119,074
  • 188
  • 476
  • 699