How do you know your unit tests actually test the right thing?
#1
So I’ve been trying to get better at writing unit tests for my side project, but I keep hitting this weird mental block. I’ll write a test that passes, but then I stare at it and wonder if I’m actually testing the right thing or just confirming my code does what I wrote. How do you even know when a test is meaningful? I feel like I’m just going through the motions sometimes.
Reply
#2
I hear you. I still chase unit tests that feel like a signal from the future not a replay of code. I focus on the goal behind the feature and ask what would break that goal even if the code looks fine.
Reply
#3
Sometimes a test seems to confirm what you expect rather than what might go wrong with a real user. I try to test boundaries and failure modes for unit tests even if it hurts the tidy happy path.
Reply
#4
Another angle is to treat tests as a contract with an external caller. If the interface says X should produce Y under Z then test that rather than mirroring internal steps. unit tests become a shield not a diary.
Reply
#5
I do not always know if the test is meaningful in the moment. I jot down a tiny hypothesis and then rewrite the test to express the expectation without telling the code how to do it. unit tests win when they hint at intent.
Reply
#6
Challenging the frame helps. If you are worrying about meaning maybe the real task is to improve the design so the test reads like a story about outcomes not a checklist for lines of code unit tests then feel less hollow.
Reply
#7
Would testing for a user outcome help you move away from implementation details? That shift might make unit tests feel like a narrative about use rather than code checking.
Reply


[-]
Quick Reply
Message
Type your reply to this message here.

Image Verification
Please enter the text contained within the image into the text box below it. This process is used to prevent automated spam bots.
Image Verification
(case insensitive)

Forum Jump: