News for hackers. Stuff that matters.
Re:Ask HN: What's the largest amount of bad code you have ev... by TickleSteve on Wednesday November 14, 2018 @07:17AM (#18449286)
Always test "outside-in", i.e. integration tests first, then if you can afford it, unit tests.

Integration tests test those things you're going to get paid for... features & use-cases.

Having a huge library of unit tests freezes your design and hampers your ability to modify in the future.

Re:Ask HN: What's the largest amount of bad code you have ev... by mercer on Wednesday November 14, 2018 @08:07AM (#18449536)
While I see some value in the red-green unit testing approach, I've found the drawbacks to often eclipse the advantages, especially under real-world time constraints.

In my day to day programming, when I neglect writing tests, the regret is always about those that are on the side of integration testing. I'm okay with not testing individual functions or individual modules even. But the stuff that 'integrates' various modules/concerns is almost always worth writing tests for.

Re:Ask HN: What's the largest amount of bad code you have ev... by mooreds on Wednesday November 14, 2018 @07:32AM (#18449353)
Love the idea of this.

In my experience it's far easier to introduce testing by focusing on unit testing complicated, stateless business logic. The setup is less complex, the feedback cycle is quick, and the value is apparent ("oh gosh, now I understand all these edge cases and can change this complicated code with more confidence"). I think it also leads to better code at the class/module/function level.

In my experience once a test (of any kind) saves a developer from a regression, they become far more amenable to writing more tests.

That said I think starting with integration tests might be a good area of growth for me.

Re:Ask HN: What's the largest amount of bad code you have ev... by TickleSteve on Wednesday November 14, 2018 @08:19AM (#18449613)
In general, I test those things that relate to the application, not those about the implementation.

i.e. Test business logic edge-cases, don't test a linked-list implementation... that's just locking your design in.

Re:Ask HN: What's the largest amount of bad code you have ev... by int_19h on Wednesday November 14, 2018 @06:49PM (#18455437)
Writing functional tests is easy when you have a clear spec. If you do, tests are basically the expression of that spec in code. Conversely, if they're hard to write, that means that your spec is underspecified or otherwise deficient (and then, as a developer, ideally, you go bug the product manager to fix that).
Re:Ask HN: What's the largest amount of bad code you have ev... by mooreds on Wednesday November 14, 2018 @10:58AM (#18450810)
Right, like I said "complicated business logic". I agree completely, I have no desire to test a library or framework (unless it's proven to need it).
Re:Ask HN: What's the largest amount of bad code you have ev... by macca321 on Wednesday November 14, 2018 @10:26AM (#18450518)
For those who want to know more about this approach: see Ian Cooper - TDD, Where Did It All Go Wrong https://www.youtube.com/watch?v=EZ05e7EMOLM

I post this all the time, it's like free upvotes :)