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
113
votes
1 answer

QUnit vs Jasmine?

What are the main differences between these two testing frameworks? I am a totally new to Test Driven Development and starting from the very beginning.
Sahat Yalkabov
  • 32,654
  • 43
  • 110
  • 175
109
votes
3 answers

What is the purpose of @SmallTest, @MediumTest, and @LargeTest annotations in Android?

I'm new to Android and I've seen example code using these annotations. For example: @SmallTest public void testStuff() { TouchUtils.tapView(this, anEditTextView); sendKeys("H E L P SPACE M E PERIOD"); assertEquals("help me.",…
Eric Palakovich Carr
  • 22,701
  • 8
  • 49
  • 54
108
votes
6 answers

How to MOQ an Indexed property

I am attempting to mock a call to an indexed property. I.e. I would like to moq the following: object result = myDictionaryCollection["SomeKeyValue"]; and also the setter value myDictionaryCollection["SomeKeyValue"] = myNewValue; I am doing this…
Ash
  • 5,057
  • 7
  • 35
  • 49
108
votes
7 answers

F# development and unit testing?

I just got started with F#, which is my first functional language. I have been working quasi-exclusively with C#, and enjoy a lot how F# leads me to re-think how I write code. One aspect I find a bit disorienting is the change in the process of…
Mathias
  • 15,191
  • 9
  • 60
  • 92
104
votes
4 answers

What is the expected syntax for checking exception messages in MiniTest's assert_raises/must_raise?

What is the expected syntax for checking exception messages in MiniTest's assert_raises/must_raise? I'm trying to make an assertion something like the following, where "Foo" is the expected error message: proc { bar.do_it }.must_raise…
kfitzpatrick
  • 2,425
  • 4
  • 19
  • 11
100
votes
10 answers

How do I write unit tests in PHP?

I've read everywhere about how great they are, but for some reason I can't seem to figure out how exactly I'm supposed to test something. Could someone perhaps post a piece of example code and how they would test it? If it's not too much trouble :)
letgo
  • 1,009
  • 2
  • 8
  • 3
97
votes
18 answers

What Makes a Good Unit Test?

I'm sure most of you are writing lots of automated tests and that you also have run into some common pitfalls when unit testing. My question is do you follow any rules of conduct for writing tests in order to avoid problems in the future? To be…
Spoike
  • 119,724
  • 44
  • 140
  • 158
91
votes
13 answers

Should Private/Protected methods be under unit test?

In TDD development, the first thing you typically do is to create your interface and then begin writing your unit tests against that interface. As you progress through the TDD process you would end-up creating a class that implements the interface…
Raj Rao
  • 8,872
  • 12
  • 69
  • 83
89
votes
17 answers

How do you unit test a unit test?

I was watching Rob Connerys webcasts on the MVCStoreFront App, and I noticed he was unit testing even the most mundane things, things like: public Decimal DiscountPrice { get { return this.Price - this.Discount; } } Would have a…
FlySwat
  • 172,459
  • 74
  • 246
  • 311
88
votes
17 answers

How deep are your unit tests?

The thing I've found about TDD is that its takes time to get your tests set up and being naturally lazy I always want to write as little code as possible. The first thing I seem do is test my constructor has set all the properties but is this…
Johnno Nolan
  • 29,228
  • 19
  • 111
  • 160
88
votes
7 answers

Best Practices of Test Driven Development Using C# and RhinoMocks

In order to help my team write testable code, I came up with this simple list of best practices for making our C# code base more testable. (Some of the points refer to limitations of Rhino Mocks, a mocking framework for C#, but the rules may apply…
Kevin Albrecht
  • 6,974
  • 7
  • 44
  • 56
84
votes
4 answers

how to write django test meant to fail?

I have a model called Thing with an attribute called name, and I want name to be a char field that's only 3 characters long. How do I write a test for that? class TestCase1(TestCase): def test1(self): thing = Thing(name='1234') that…
Alexander Bird
  • 38,679
  • 42
  • 124
  • 159
83
votes
8 answers

NSURL to file path in test bundle with XCTest

I am trying to write an iOS app using TDD and the new XCTest framework. One of my methods retrieves a file from the internet (given a NSURL object) and stores it in the user's documents. The signature of the method is similar to: - (void)…
Eduardo Arenas Prada
  • 1,072
  • 1
  • 7
  • 14
81
votes
7 answers

What do programmers mean when they say, "Code against an interface, not an object."?

I've started the very long and arduous quest to learn and apply TDD to my workflow. I'm under the impression that TDD fits in very well with IoC principles. After browsing some of TDD tagged questions here in SO, I read it's a good idea to program…
delete
79
votes
2 answers

Using object types with Jasmine's toHaveBeenCalledWith method

I've just started using Jasmine so please forgive the newbie question but is it possible to test for object types when using toHaveBeenCalledWith? expect(object.method).toHaveBeenCalledWith(instanceof String); I know I could this but it's checking…
screenm0nkey
  • 18,405
  • 17
  • 57
  • 75