Using TDD: “top down” vs. “bottom up”

后端 未结 7 1440
野趣味
野趣味 2021-01-31 18:57

Since I\'m a TDD newbie, I\'m currently developing a tiny C# console application in order to practice (because practice makes perfect, right?). I started by making a simple sket

7条回答
  •  面向向阳花
    2021-01-31 19:25

    "bottom up" can save you a lot of work cos you already have low-level classes (tested) and you can use them in higher level tests. in opposite case you'd have to write a lot of (probably complicated) mockups. also "top down" often doesn't work as it's supposed: you think out some nice high-level model, test and implement it, and then moving down you realize that some of your assumptions were wrong (it's quite typical situation even for experienced programmers). of course patterns help here but it's not silver bullet too.


    to have complete test coverage, you'll need to test your Main in any case. I'm not sure it's worth the effort in all cases. Just move all logic from Main to separate function (as Marcus Lindblom proposed), test it and let Main to just pass command-line arguments to your function.


    console output is a simplest possible testing ability, and if you use TDD it can be used just to output the final result w/o any diagnosis and debug messages. so make your top-level function to return solid result, test it and just output it in Main

提交回复
热议问题