Does TDD mean not thinking about class design?

前端 未结 8 1843
生来不讨喜
生来不讨喜 2021-02-06 01:17

I am making a role playing game for fun and attempting to use TDD while developing it. Many of the TDD examples I see focus on creating the test first, then creating objects tha

相关标签:
8条回答
  • 2021-02-06 02:04

    A balanced approach is the way to go.

    However, the balance is Driven by the need to test.

    You can map out the possible classes and hierarchy. But, you'll need to drive the design by (1) thinking about testability and (2) writing the tests before writing too much code.

    For your tests to even compile, you need some class definitions. They don't have to work, but they have to compile.

    In a few cases your class may be so simple, you actually write all (or almost all) of it first.

    0 讨论(0)
  • 2021-02-06 02:06

    I think you're missing the point of TDD. TDD is not about writing tests - it's about designing your classes to be testable. This naturally leads to a better design and implementation.

    It sounds like you're doing it backwards.

    Your steps should be:

    1. Design your domain model
    2. Design your classes
    3. Write some tests
    4. Implement some class logic
    5. Refactor your classes to make them more testable where necessary
    6. Repeat Steps 3-5
    0 讨论(0)
提交回复
热议问题