frontpage.
newsnewestaskshowjobs

Made with ♥ by @iamnishanth

Open Source @Github

fp.

Open in hackernews

Using tests as a debugging tool for logic errors

https://www.qodo.ai/blog/java-unit-testing-how-to-use-tests-as-a-debugging-tool-for-logic-errors/
38•simplesort•9mo ago

Comments

recroad•9mo ago
This article seems like a very long-winded and complicated way to say that we should write tests. Am I missing something here? Wouldn't most developers write tests when creating algorithms, let alone something relating to finance as tax calculations? Yes, you should reproduce a defect by writing a failing tests first.

Where I hoped/thought this piece would go was to expand on the idea of error-prone[1] and apply it to the runtime.

https://github.com/google/error-prone

simplesort•9mo ago
I thought it was interesting - not revolutionary but updated my thinking a bit.

Writing a failing test that reproduces a bug is something I learned pretty early on.

But I never consciously thought about and approached the test as a way to debug. I thought about it more of a TDD way - first write tests, then go off and debug/code until the test is green. Also practically, let's fill the gap in coverage and make sure this thing never happens again, especially if I had to deal with it on the weekend.

What was interesting to me about this was actively approaching the test as a way of debugging, designing it to give you useful information and using the test in conjunction with debugger

whynotmaybe•9mo ago
I'm happy for you that you learned something and sad for me because you made me feel old and stupid.

I tend to forget that people don't know stuff I learned decades ago and consider them as general knowledge.

Before TDD became what it was, we used to create specific files for specific bug cases, or even get the files from the users themselves.

JadeNB•9mo ago
> I tend to forget that people don't know stuff I learned decades ago and consider them as general knowledge.

While all of us who are lucky to be around long enough meet the problem of general knowledge changing under our feet, it's hard for me to imagine how saying this to someone can be a productive contribution to the conversation. What can it accomplish other than making someone feel worse for not knowing something that you consider general knowledge?

whynotmaybe•9mo ago
I don't think anyone should feel bad for not knowing something.

My "general" knowledge is built on my experience.

The first comment before OP answer's was kinda condescending about the article and I felt the same way when reading it but then op's comment made me realise I was in the wrong because I forgot that my "general" knowledge is not general at all.

OP had to defend why he posted it. I wanted to tell OP that it was a good idea to post it, not for the article content, but for my teaching moment.

Jtsummers•9mo ago
> What was interesting to me about this was actively approaching the test as a way of debugging, designing it to give you useful information and using the test in conjunction with debugger

I'm curious, if you're using TDD weren't you already doing this? A test that doesn't give you useful information is not a useful test.

hyperpape•9mo ago
I think the distinction is that if you write a test that reproduces the bug, that's a binary signal and doesn't by itself tell you anything about why the bug is happening.

In contrast, if you write tests that rule out particular causes of a bug you're incrementally narrowing down the potential causes of the bug. So each test gives you information that helps you solve the bug, without directly stepping through the code.

Unfortunately, I don't think the post is a great primer on the subject.

Jtsummers•9mo ago
> Unfortunately, I don't think the post is a great primer on the subject.

It isn't, nor is it intended to be. It's an advert:

>> While mastering unit tests as debugging tools takes practice, AI-powered solutions like Qodo can significantly accelerate this journey. Qodo’s contextual understanding of your Java codebase helps it automatically generate tests that target potential logic vulnerabilities.

gavmor•9mo ago
> then go off and debug/code until

Yes, this is a missed opportunity! Well said. I try to write tests in place of print statements or debuggers, using assertions like xray glasses. Fun times!

jeremyscanvic•9mo ago
This reminds me of a talk that Leslie Lamport (author of LaTeX & prominent figure in the field of distributed computing) gave recently [1]. I remember him arguing that the difficult part in writing code is not to determine what code to write to compute something, but to determine what this something is in the first place. "Logic errors" are really about valid algorithms that end up computing the wrong thing - they're gonna compile, they're gonna run, but they won't do what you want them to do.

One example he gives is computing the maximum element in a sequence of numbers. This is something trivial to implement but you need to decide what to do with the obvious edge case: empty sequences. One solution is to return some kind of error or exception, but another is to extend what we mean by the largest element in a sequence the way mathematicians typically do. Indeed, the maximum function can be extended for empty sequences by letting max([]) := -infinity, the same way empty sums are often defined as 0, and empty products as 1. The alleged benefit of following the second approach is that it should lead to simpler code/algorithms, but it also requires more upfront thinking.

[1] https://www.youtube.com/watch?v=tsSDvflzJbc

pkoird•9mo ago
Closely related are in-code assertions. I remember when I used to liberally use asserts inside a code (and you could disable them for production) to check pre-conditions, post-conditions, or any invariants. Nowadays, I don't think the pattern is recommended anymore, at least in certain popular languages.
esafak•9mo ago
Fail as early as you can, if you can't recover.
just6979•9mo ago
It's not recommended as much anymore because of unit tests. Instead of peppering the code with asserts, you build tests based on those assertions. You don't have to worry about turning it off in production because the tests are separate, and you also don't have to worry about manually triggering all the various asserts in a dev build, because the test runs are doing that for you even before a build is published.
pfdietz•9mo ago
How do you determine if your tests are good at finding logic errors?

Mutation testing. Introduce artificial logic errors and see if your tests find them.

Disappointed the article didn't go into this. You can even use mutation as part of a test generator, saving the (minimized) first test input that kills a mutant. You still need some way of determining what the right answer was (killing the mutant just involves seeing it does something different from the unmutated program.)

codr7•9mo ago
Something's seriously messed up with the font on that page for me.

Mac mini will be made at a new facility in Houston

https://www.apple.com/newsroom/2026/02/apple-accelerates-us-manufacturing-with-mac-mini-production/
80•haunter•44m ago•52 comments

Looks like it is happening

https://www.math.columbia.edu/~woit/wordpress/?p=15500
52•jjgreen•39m ago•20 comments

I'm helping my dog vibe code games

https://www.calebleak.com/posts/dog-game/
458•cleak•4h ago•136 comments

Hacking an old Kindle to display bus arrival times

https://www.mariannefeng.com/portfolio/kindle/
86•mengchengfeng•2h ago•17 comments

Nearby Glasses

https://github.com/yjeanrenaud/yj_nearbyglasses
150•zingerlio•4h ago•59 comments

Show HN: Emdash – Open-source agentic development environment

https://github.com/generalaction/emdash
62•onecommit•3h ago•28 comments

HuggingFace Agent Skills

https://github.com/huggingface/skills
102•armcat•4h ago•34 comments

I pitched a roller coaster to Disneyland at age 10 in 1978

https://wordglyph.xyz/one-piece-at-a-time
361•wordglyph•8h ago•133 comments

Manjaro website off-line again due to lapsed certificate

https://distrowatch.com/dwres.php?resource=showheadline&story=20140
34•hexagonsuns•2h ago•11 comments

How we rebuilt Next.js with AI in one week

https://blog.cloudflare.com/vinext/
81•ghostwriternr•1h ago•11 comments

Show HN: Recursively apply patterns for pathfinding

https://pattern-pathfinder.vercel.app/?fixtureId=%7B%22path%22%3A%22site%2Fexamples%2F_intro.fixt...
3•seveibar•7m ago•0 comments

Steel Bank Common Lisp

https://www.sbcl.org/
105•tosh•3h ago•29 comments

IRS Tactics Against Meta Open a New Front in the Corporate Tax Fight

https://www.nytimes.com/2026/02/24/business/irs-meta-corporate-taxes.html
165•mitchbob•9h ago•179 comments

Build Your Own Forth Interpreter

https://codingchallenges.fyi/challenges/challenge-forth/
23•AlexeyBrin•3d ago•6 comments

We installed a single turnstile to feel secure

https://idiallo.com/blog/installed-single-turnstile-for-security-theater
236•firefoxd•2d ago•98 comments

Verge (YC S15) Is Hiring a Director of Computational Biology and AI Scientists/Eng

https://jobs.ashbyhq.com/verge-genomics
1•alicexzhang•4h ago

Diode – Build, program, and simulate hardware

https://www.withdiode.com/
423•rossant•3d ago•92 comments

Show HN: Chaos Monkey but for Audio Video Testing (WebRTC and UDP)

https://github.com/MdSadiqMd/AV-Chaos-Monkey
20•MdSadiqMd•1d ago•2 comments

Variable interpolatable smooth curves and outlines

https://thottingal.in/blog/2026/02/20/var-interpolatable-smooth-curves/
5•sthottingal•4d ago•0 comments

Extending C with Prolog (1994)

https://www.amzi.com/articles/irq_expert_system.htm
51•Antibabelic•2d ago•17 comments

IDF killed Gaza aid workers at point blank range in 2025 massacre: Report

https://www.dropsitenews.com/p/israeli-soldiers-tel-sultan-gaza-red-crescent-civil-defense-massac...
843•Qem•9h ago•196 comments

Osaka: Kansai Airport proud to have never lost single piece of luggage (2024)

https://japannews.yomiuri.co.jp/features/japan-focus/20241228-229891/
188•thunderbong•5h ago•75 comments

Open Letter to Google on Mandatory Developer Registration for App Distribution

https://keepandroidopen.org/open-letter/
299•kaplun•4h ago•238 comments

λProlog: Logic programming in higher-order logic

https://www.lix.polytechnique.fr/Labo/Dale.Miller/lProlog/
133•ux266478•3d ago•35 comments

The Missing Semester of Your CS Education – Revised for 2026

https://missing.csail.mit.edu/
348•anishathalye•1d ago•106 comments

We Are Changing Our Developer Productivity Experiment Design

https://metr.org/blog/2026-02-24-uplift-update/
6•ej88•1h ago•2 comments

Samsung Upcycle Promise

https://www.xda-developers.com/samsung-promised-make-old-phones-useful-galaxy-upcycle/
157•1970-01-01•1d ago•93 comments

Why High FOV Sucks – Fixing It with Panini Projection

https://www.youtube.com/watch?v=LE9kxUQ-l14
26•Eduard•1h ago•8 comments

Goodbye InnerHTML, Hello SetHTML: Stronger XSS Protection in Firefox 148

https://hacks.mozilla.org/2026/02/goodbye-innerhtml-hello-sethtml-stronger-xss-protection-in-fire...
309•todsacerdoti•8h ago•142 comments

OpenAI, the US government and Persona built an identity surveillance machine

https://vmfunc.re/blog/persona/
359•rzk•3h ago•110 comments