Re:Ask HN: Do you write tests before the implementation?
by shhsshs on Friday November 15, 2019 @10:34AM
(#21545640)
I see a test as a declaration of intended outcome. By writing a test to expect an intentional failure (say you have a bug in a divide: “int -> int -> Maybe int” function that causes it to return 0 when you divide by 0 instead of “None”) you are declaring that is actually intentional behavior. So I would never write a test like this - I think I would prefer committing the fix and the new test at once. I don’t see the value in reviewing them separately, because they are related and dependent changes.
Obviously if you view tests differently (eg. as a declaration of current behavior rather than intended behavior) then my argument dies.
Re:Ask HN: Do you write tests before the implementation?
by jackweirdy on Friday November 15, 2019 @11:29AM
(#21546182)
Keep in mind the test is written with the correct behaviour and annotated to be failing — in a hypothetical language and framework your test would be
@failing testDivZero() { assertEquals(None, div(1, 0)) }
This expresses both the intent and the reality
Re:Ask HN: Do you write tests before the implementation?
by thrownaway954 on Friday November 15, 2019 @08:14AM
(#21544463)
this is why i love HN. that is such an outstanding idea.
That way you can commit the test, bisect works, and the test begins "failing" when the bug is really fixed, and you can commit the fix as well as a one-line change to amend the test from being failure-expected to just a normal test.