How do you do TDD in a non-trivial application? [c

2020-05-19 02:16发布

I've read a number of books and websites on the subject of TDD, and they all make a lot of sense, especially Kent Beck's book. However, when I try to do TDD myself, i find myself staring at the keyboard wondering how to begin. Is there a process you use? What is your thought process? How do you identify your first tests?

The majority of the books on the subject do a great job of describing what TDD is, but not how to practice TDD in real world non-trivial applications. How do you do TDD?

标签: tdd agile
8条回答
姐就是有狂的资本
2楼-- · 2020-05-19 02:47

I start with thinkig of requirements.

foreach UseCase

  1. analyze UseCase
  2. think of future classes
  3. write down test cases
  4. write tests
  5. testing and implementing classes (sometimes adding new tests if I missed sth at point 4).

That's it. It's pretty simple, but I think it's time consuming. I like it though and I stick to it. :)

If I have more time I try to model some sequential diagrams in Enterprise Architect.

查看更多
一纸荒年 Trace。
3楼-- · 2020-05-19 02:51

I used to have the same problem. I used to start most development by starting a window-designer to create the UI for the first feature I wanted to implement. As the UI is one of the hardest things to test this way of working doesn't translate very well to TDD.

I found the atomic object papers on Presenter First very helpful. I still start by envisioning user actions that I want to implement (if you've got usecases that's a great way to start) and using a MVP or MVC-ish model I start with writing a test for the presenter of the first screen. By mocking up the view until the presenter works I can get started really fast this way. http://www.atomicobject.com/pages/Presenter+First here's more information on working this way.

If you're starting a project in a language or framework that's unknown to you or has many unknown you can start out doing a spike first. I often write unit tests for my spikes too but only to run the code I'm spiking. Doing the spike can give you some input on how to start your real project. Don't forget to throw away your spike when you start on your real project

查看更多
登录 后发表回答