Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TDD, How to write tests that will compile even if objects don't exist

I'm using VS 2012, but that's not really important.

What is important is that I'm trying to do some TDD by writing all my tests first and then creating the code.

However, the app will not compile because none of my objects or methods exist.

Now, to my mind, I should be able to create ALL my tests but still run my app so I can debug etc. The tests shouldn't prevent compilation because objects and methods are missing.

I thought the whole point of it was that as you develop your tests you can begin to see duplications etc so that you can refactor before writing a single line of code.

So the question is, is there a way to do this or am I doing this wrong?

EDIT I am using VS2012 and C#

like image 584
griegs Avatar asked Nov 23 '12 04:11

griegs


People also ask

Which type's of tests do you typically write when doing TDD?

With developer TDD you write a single developer test, sometimes inaccurately referred to as a unit test, and then just enough production code to fulfill that test. The goal of developer TDD is to specify a detailed, executable design for your solution on a JIT basis. Developer TDD is often simply called TDD.

Which two techniques are used in test strategy in TDD?

Testing Techniques in Agile Software Development TDD, BDD and AMDD are the techniques in software testing that can be applied to any methodology. TDD is Test-Driven Development. The unit tests are written first, then a code is written to make the tests pass.


1 Answers

I see a small problem with

writing all my tests first and then creating the code.

You don't need to write ALL your tests first, you just need one, make it fail, make it pass and repeat. That means ideally at any point you should have ideally one failing test.

A compile failure counts as a failed test in that sense. So the next step is to make it pass - i.e. add stubs or return default values to make it compile. The test would then be red.. then work at getting it to green.

like image 157
Gishu Avatar answered Sep 19 '22 15:09

Gishu