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
3189
votes
59 answers

How do I test a class that has private methods, fields or inner classes?

How do I use JUnit to test a class that has internal private methods, fields or nested classes? It seems bad to change the access modifier for a method just to be able to run a test.
MattGrommes
  • 11,974
  • 9
  • 37
  • 40
906
votes
7 answers

How to verify that a specific method was not called using Mockito?

How to verify that a method is not called on an object's dependency? For example: public interface Dependency { void someMethod(); } public class Foo { public bar(final Dependency d) { ... } } With the Foo test: public class…
beluchin
  • 12,047
  • 4
  • 24
  • 35
716
votes
13 answers

JavaScript unit test tools for TDD

I've looked into and considered many JavaScript unit tests and testing tools, but have been unable to find a suitable option to remain fully TDD compliant. So, is there a JavaScript unit test tool that is fully TDD compliant?
Mark Levison
  • 788
  • 3
  • 9
  • 22
645
votes
10 answers

C# "internal" access modifier when doing unit testing

I'm trying to figure out if I should start using more of internal access modifier. I know that if we use internal and set the assembly variable InternalsVisibleTo, we can test functions that we don't want to declare public from the testing…
Hertanto Lie
  • 8,832
  • 7
  • 28
  • 27
507
votes
32 answers

How do you unit test private methods?

I'm building a class library that will have some public & private methods. I want to be able to unit test the private methods (mostly while developing, but also it could be useful for future refactoring). What is the correct way to do this?
Eric Labashosky
  • 29,484
  • 14
  • 39
  • 32
225
votes
11 answers

Unit testing void methods?

What is the best way to unit test a method that doesn't return anything? Specifically in c#. What I am really trying to test is a method that takes a log file and parses it for specific strings. The strings are then inserted into a database. Nothing…
jdiaz
  • 7,354
  • 12
  • 42
  • 51
203
votes
31 answers

Unit testing Anti-patterns catalogue

anti-pattern : there must be at least two key elements present to formally distinguish an actual anti-pattern from a simple bad habit, bad practice, or bad idea: Some repeated pattern of action, process or structure that initially appears to be…
Gishu
  • 134,492
  • 47
  • 225
  • 308
201
votes
31 answers

Disadvantages of Test Driven Development?

What do I lose by adopting test driven design? List only negatives; do not list benefits written in a negative form.
IanL
  • 636
  • 4
  • 9
  • 23
182
votes
20 answers

Random data in Unit Tests?

I have a coworker who writes unit tests for objects which fill their fields with random data. His reason is that it gives a wider range of testing, since it will test a lot of different values, whereas a normal test only uses a single static…
Adam V
  • 6,256
  • 3
  • 40
  • 52
182
votes
8 answers

Mocking vs. Spying in mocking frameworks

In mocking frameworks, you can mock an object or spy on it. What's the difference between the two and when would/should I use one over the other? Looking at Mockito, for example, I see similar things being done using spies and mocks, but I am unsure…
Vivin Paliath
  • 94,126
  • 40
  • 223
  • 295
167
votes
7 answers

How to get started on TDD with Ruby on Rails?

I am familiar with the concepts (took testing classes in college), but I am not sure how to really use them yet since I never worked on a "real" TDD project. I am about to start the development of a project using Ruby on Rails (most likely using…
marcgg
  • 65,020
  • 52
  • 178
  • 231
160
votes
16 answers

Unit testing Bash scripts

We have a system that has some Bash scripts running besides Java code. Since we are trying to test everything that could possibly break, and those Bash scripts may break, we want to test them. The problem is it is hard to test Bash scripts. Is there…
nimcap
  • 10,062
  • 15
  • 61
  • 69
158
votes
5 answers

eslint should be listed in the project's dependencies, not devDependencies

Either I don't understand dependencies vs. devDependencies in node 100% yet or eslint is just wrong here (not capable of analyzing this correctly): 3:1 error 'chai' should be listed in the project's dependencies, not devDependencies …
PositiveGuy
  • 17,621
  • 26
  • 79
  • 138
156
votes
6 answers

test a file upload using rspec - rails

I want to test a file upload in rails, but am not sure how to do this. Here is the controller code: def uploadLicense #Create the license object @license = License.create(params[:license]) #Get Session ID sessid =…
user727403
  • 1,967
  • 3
  • 13
  • 14
153
votes
23 answers

Can unit testing be successfully added into an existing production project? If so, how and is it worth it?

I'm strongly considering adding unit testing to an existing project that is in production. It was started 18 months ago before I could really see any benefit of TDD (face palm), so now it's a rather large solution with a number of projects and I…
djdd87
  • 67,346
  • 27
  • 156
  • 195
1
2 3
99 100