Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TDD, What are your techniques for finding good tests?

I am writing a simple web app using Linq to Sql as my datalayer as I like Linq2Sql very much. I have been reading a bit about DDD and TDD lately and wanted to give it a shot.

First and foremost it strikes me that Linq2Sql and DDD don't go along too great. My other problem is finding tests, I actually find it very hard to define good tests so I wanted to ask, What is your best techniques for discovering good test cases.

like image 572
terjetyl Avatar asked Dec 18 '22 09:12

terjetyl


2 Answers

Test Case discovery is more of an art than a science. However simple guidelines include:

  • Code that you know to be frail / weak / likely to break
  • Follow the user scenario (what your user will be doing) and see how it will touch your code (often this means Debugging it, other times profiling, and other times it simply means thinking about the scenario) - whatever points in your code get touched by the user, those are the highest priority to write tests against.
  • During your own development the tests you ran that resulted in bugs you found - write tests to avoid the code regressing again with the same behavior.

There are several books on how to write test cases out there, but unless you are working in a large organization that requires documented test cases, your best bet is to think of all the parts in your code that you don't like (that aren't "pure") and make sure you can test those modules thoroughly.

like image 176
Rajat Arya Avatar answered Dec 24 '22 00:12

Rajat Arya


Well, going by the standard interpretation of TDD is that the tests drive your development. So, in essence you start with the test. It will fail, and you will write code until that test passes. So it's kind of driven by your requirements, however you go about gathering those. You decide what your app/feature needs to do, write the test, then code until it passes. Of course, there are many other techniques but this is just a brief statement about what is typically thought in the TDD world.

like image 44
BobbyShaftoe Avatar answered Dec 24 '22 01:12

BobbyShaftoe