Unit Testing Practices

Debates on software testing strategies, including isolation vs integration testing, testing private methods, whether tests should drive design changes, and avoiding implementation-coupled tests.

📉 Falling 0.4x Programming Languages
2,823
Comments
19
Years Active
5
Top Authors
#6417
Topic ID

Activity Over Time

2008
9
2009
19
2010
33
2011
51
2012
105
2013
114
2014
175
2015
114
2016
174
2017
212
2018
152
2019
128
2020
251
2021
206
2022
337
2023
304
2024
211
2025
221
2026
7

Keywords

main.go TDD IMO CRUD OOP linkedrecords.com DI IO API DRY test tests code testing value value value functions refactor unit unit test

Sample Comments

robertlagrant Apr 24, 2023 View on HN

Your tests are part of your code. Your implementation code should not make writing your test code difficult.

kamaal Feb 7, 2018 View on HN

If you are developing your code as a small tiny functions getting stitched later. Then writing unit test cases will solve this problem too.

PeterisP Sep 15, 2023 View on HN

Tests effectively freeze requirements; you should test those things which should be preserved throughout any changes, and not test those things which should be open to change. In this case, it seems that is no real requirements for any of these 9 steps - perhaps the implementer could figure out how to do the same outcome by skipping a step or merging two steps, and the existence of unit tests for these 9 functions somehow encodes the idea that these 9 functions each are inherently needed, which

user_id3 Sep 9, 2014 View on HN

Can someone explain to me how integrating your test into the same code that your testing is a good idea?

ajuc Jan 13, 2020 View on HN

The problem with abstractions in testing is - you should test it :)

robertlagrant Feb 12, 2025 View on HN

That's interesting - I can sort of see it both ways. Would applying unit tests to the exposed functions not have sufficed?

paledot Nov 21, 2022 View on HN

I'd go so far as to say if your test is doing something crafty, you're doing tests wrong. Maybe in a mock or fixture, but that's a write-once sort of affair.I also don't apply DRY (don't repeat yourself) to tests. Tests should be independently readable beginning to end, no context needed. After all, the true value of a unit test is to take a block of code too complicated to easily fit in your mind, and break it down into a series of examples simple enough to fit.

philipodonnell Jan 2, 2018 View on HN

Honest question: can you expand on why this is bad? Doesn't efficiency outweigh respecting feature boundaries in tests?

Chris2048 Mar 18, 2016 View on HN

I think the tests should adapt to the design, not the design to the tests..

kissgyorgy Feb 17, 2023 View on HN

It seems like you need to call this function :) and not surprisingly, your comment is totally incorrect, tests can be implemented independent of each other regardless of the quality of the code they are testing. This doesn't mean they can run in parallel, but every test should be running independently from each other no matter what.