My typical practice is to work out an API, write early scratches of implementation and test only simple cases. Then I can inspect two things: how the API works in real code and what else should be tested. In other words tests help to establish an API, then to stabilize the implementation.
Ask HN: Do you write tests before the implementation?
261–270 of 329 posts
Re: Ask HN: Do you write tests before the implementation?
#262Re: Ask HN: Do you write tests before the implementation?
#263At the new feature level, I have found not a lot of use for TDD.
Re: Ask HN: Do you write tests before the implementation?
#264I used to write a lot of tests and discovered over summer that it costs too much in terms of time spent writing, changing, and debugging tests for what you tend to get out of it.
I do think writing a lot of tests for a legacy or relatively old system is a great way to uncover existing bugs and document expected behaviours. With that done, refactoring or rebuilding is possible and you gain a great understanding of the software.
Re: Ask HN: Do you write tests before the implementation?
#265I find literal TDD distracting and unhelpful, but having a list of things I need to handle that doubles as tests I can't forget to write is a really nice balance.
Re: Ask HN: Do you write tests before the implementation?
#266Re: Ask HN: Do you write tests before the implementation?
#267No. Tests are like any other code. They incur technical debt and bugs at the same rate as other code. They also introduce friction to the development process. As your test suite grows, your dev process often begins to slow down unless you apply additional work to grease the wheels, which is yet another often unmeasured cost of testing in this fashion. So, in short, I view tests as a super useful, but over-applied too…
From what I understand about TDD it's more about getting the design right then testing for bugs.
Re: Ask HN: Do you write tests before the implementation?
#268However, when I need to overhaul something that already exists, e.g. the core of a game engine, I've gotten into the habit of writing tests for current behavior, so that when I rip it out its replacement works the same way, or at least retains the same interface, so I don't have to replace the whole pyramid on top before I can compile again. :)
This has also helped me realize the value of tests, but later on in the development cycle, not as the base before actually writing anything.
Re: Ask HN: Do you write tests before the implementation?
#269Earlier quoted context omitted.
Can you give a run down on formal verification?
So say you were writing a sorting algorithm and with unit tests (perhaps with TDD) you wrote tests like: - sort([]) should produce [] - sort([1]) should produce [1] - sort([1,3,2]) should produce [1,2,3] - sort([1,5,6,2,3,4]) should produce [1,2,3,4,5,6] You would test a few values and edge cases until you were confident it works for all lists. However, you can't be 100% sure that there's some list out there like [5,…
For the curious, something like this has happened before - and was found with formal verification: http://www.envisage-project.eu/proving-android-java-and-pyth...
Re: Ask HN: Do you write tests before the implementation?
#270Plus writing HDL without tests is basically guaranteed to create something nonfunctional.
I hate unit testing in for example Java though, individual functions are typically very basic and don't do much. A service? Integration tests? Sign me up, but unit testing to 100% coverage a function with ten lines that reads a bytestream to an object and sets some fields is boring, and fairly difficult to mock.