Does TDD mean not thinking about class design?

前端 未结 8 1853
生来不讨喜
生来不讨喜 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 01:49

    Should my class design really come out of continually refining my tests?

    Yes.

    Does TDD mean not thinking about class design?

    Absolutely not. It means thinking about class design in the course of writing your tests, and the rest of your code. Class design is at play throughout the Red-Green-Refactor TDD life cycle.

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

    TDD is about design! So doing TDD you will be sure that your design is completely testable.

    Also, the "balanced approach" is the way to go IMO. You already know a high level architecture and TDD will drive this architecture to be testable.

    EDIT: Although, if you want just to practice TDD I would not do the "balanced approach". I would just do TDD with "baby steps" and maybe coding Dojos

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

    I think the balanced approach is the one you need to take. First model the classes of your domain, because without them, how do you even know what to test?

    Then, you'll probably create stubs or shells of these classes, with mostly empty implementations, just to let you write some test structures.

    Once that's done, your test cases will likely illuminate the need for new methods / classes / properties that weren't in the original design, but are discovered as being necessary.

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

    TDD leans toward thinking about and experimenting with class design concretely using running code rather than abstractly with pencil and paper.

    Both approaches are useful. Even hardcore TDD zealots use pencil-and-paper (or perhaps a whiteboard) at times, and BDUF-ueber-alles types will bang out the occasional prototype. The question then is where you tend to fall: ponderer or more hands-on?

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

    I think it's generally assumed (even by the TDD purists) that a programmer designing an application by writing tests already knows something about design and architecture. Otherwise you can just paint yourself into programming chaos and anarchy by writing tests to the abandonment of any design principles.

    Consequently, a developer writing an application "tests first" already has a fair idea of what his final class structure will look like, and that vision guides him when he is writing his tests.

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

    TDD is about letting the tests drive your design, including your class design. This is valuable because the tests are meant to prove that the code "works". That means you'll wind up with a class design of a program that works, as opposed to a class design of a program which may or may not work.

    0 讨论(0)
提交回复
热议问题