3 ms·
For designing APIs, my favorite approach is a hybrid of the two. I'm not sure if there's an official name, but I've taken to calling them walking skeleton tests
by bunderbunder 2y ago
For designing APIs, my favorite approach is a hybrid of the two. I'm not sure if there's an official name, but I've taken to calling them walking skeleton tests.
The gist is that you start by writing example client code demonstrating small but useful interactions with the API, including explanatory comments. They won't work yet, because the API hasn't been implemented. But you're already in a position to talk them over with your team and start thinking about user experience issues. And they give you a nucleus around which you can start building high-quality user documentation.
And they're your automated end-to-end acceptance tests.
Once things look good (not perfect), then you can start implementing the API. For this portion I don't necessarily do TDD, because I remain unconvinced that writing unit tests first is inherently better than writing unit tests afterward. But I might. Depends on my mood. But I do keep running the walking skeleton tests, which serve as my primary feedback mechanism for evaluating implementation progress and success.
The more important thing is that I can start stepping through those walking scenario tests and seeing how well the interaction actually works in practice. And I can use those observations to help inform an ongoing conversation about the API's design and functionality. I can also get quick feedback on whether some aspect of the high-level design isn't going to work as well as we had hoped. Ongoing updates to the design are memorialized and communicated by updating the walking skeleton tests.
- hitchstory 2y agoI built a Python/YAML framework around the ability to build these tests and then generate documentation from them. E.g. https://github.com/hitchdev/hitchstory/blob/master/examples%2Frestapi%2Fhitch%2Fstory%2Fcorrect-my-spelling.story https://github.com/hitchdev/hitchstory/blob/master/examples%... which generates https://github.com/hitchdev/hitchstory/blob/master/examples%2Frestapi%2Fhitch%2Fdocs%2Fcorrect-my-spelling.md https://github.com/hitchdev/hitchstory/blob/master/examples%... When you show this stuff to other people and gather feedback - that's essentially what BDD is, too.
- bbojan 2y ago> For this portion I don't necessarily do TDD, because I remain unconvinced that writing unit tests first is inherently better than writing unit tests afterward. I would argue that TDD doesn't imply writing unite tests - it's about writing any tests first. If you have acceptance tests already written out, you're already doing TDD.