frontpage.
newsnewestaskshowjobs

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•1y ago

Comments

recroad•1y 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•1y 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•1y 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•1y 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•1y 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•1y 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.

jeremyscanvic•1y 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•1y 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•1y ago
Fail as early as you can, if you can't recover.
just6979•1y 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•1y 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•1y ago
Something's seriously messed up with the font on that page for me.
hyperpape•1y 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•1y 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•1y 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!

Meta Ignores Brazilian Court Order to End Bolsonaro Favoritism

https://www.panamericandispatch.org/p/meta-ignores-brazilian-court-order
218•vrganj•2h ago•142 comments

We should be more ambitious with the software we build

https://danluu.com/ambitious/
465•ltratt•13h ago•411 comments

Cerebras Deploys Trillion-Parameter AI Models

https://www.cerebras.ai/blog/how-we-deploy-trillion-parameter-frontier-models-on-cerebras
194•gmays•10h ago•64 comments

Samsung running a TensorFlow lite model on 960x540 image to track you

https://twitter.com/mike64_t/status/2114150399406202896
26•mashally•58m ago•11 comments

How Japanese Dried Bonito Is Made

https://kottke.org/26/10/how-japanese-dried-bonito-is-made
56•bookofjoe•3d ago•20 comments

The Goose Programming Language

https://aardappel.github.io/goose/
430•bobbydigitales•16h ago•263 comments

Rewriting a Commercial Engine in Jai

https://polygonjs.com/blog/why-i-rewrote-polygon-from-scratch
33•frading•2d ago•20 comments

France asked ISPs to prepare temporary DNS blocks for major social platforms

https://www.blast-info.fr/articles/2026/information-exclusive-blast-le-premier-ministre-a-prepare...
74•noplay•1h ago•55 comments

SpeedCrunch 1.1

https://www.speedcrunch.org/
161•LordNibbler•16h ago•29 comments

Small Programs and Languages

https://ratfactor.com/cards/pl-small
126•andsoitis•13h ago•17 comments

Reverse engineer of PC-98 Touhou games retires

https://rec98.nmlgc.net/blog/2026-10-05
10•mimasama•2d ago•2 comments

Why Gopher in 2026?

https://gopher.muffinlabs.com/sdf.org/users/nervtoji/phlog/001.txt
83•andsoitis•12h ago•34 comments

America has lost 200k of jobs in media, film and the arts. How much is AI?

https://www.apricitas.io/p/ai-and-the-fall-of-the-creative-class
380•gnabgib•12h ago•388 comments

Local Wikipedia: Wikipedia, but only for things a half hour walk from you

https://edjefferson.com/localwiki/
1603•sohkamyung•2d ago•247 comments

Node2Shell evolves to HTTP2Shell, blast radius affects many HTTP libs and apps

https://www.aikido.dev/blog/python-packages-vulnerable-node2shell-brotli-cve-2026-111497
333•theanonymousone•1d ago•158 comments

I don't understand quantum physics (2018)

https://www.southampton.ac.uk/~doug/quantum_physics/index.html
321•rramadass•1d ago•257 comments

I Built a Stereo Vision Board for Hardware Hackers

https://rootkitlabs.com/2026/10/06/i-built-a-stereo-vision-board-for-hardware-hackers/
86•machinehum•4d ago•15 comments

The Importance of Limitations for Creativity and Learning (2023)

https://ratfactor.com/cards/limitations
81•andsoitis•13h ago•22 comments

FreeDNS

https://freedns.afraid.org/
301•esher•20h ago•83 comments

Social dynamics of toxic metal industry in medieval Europe

https://www.cambridge.org/core/journals/antiquity/article/social-dynamics-of-toxic-metal-industry...
55•XzetaU8•4d ago•26 comments

A story of a Figma bug that wasn't a bug at all (2021)

https://aresluna.org/this-is-a-story-of-a-figma-bug/
39•jllyhill•3d ago•3 comments

Nikon photography contest winner loses title after scientists spot signs of AI

https://www.techspot.com/news/114171-nikon-photography-contest-winner-loses-title-after-scientist...
10•thunderbong•1h ago•0 comments

GPU-unlock: FP/BF16 instruction issue rate on Nvidia 3000's cards

https://github.com/Zagitta/gpu-unlock
262•fragebogen•1d ago•73 comments

Neural chip decodes interactions between brain regions

https://actu.epfl.ch/news/neural-chip-decodes-interactions-between-brain-r-2/
111•giuliomagnifico•19h ago•43 comments

The St. Helena 5 pence coin shows Jonathan, a roughly 190 year old tortoise

https://de.numista.com/9866
121•schleck8•18h ago•39 comments

Physicists trap a single antimatter particle for a month

https://www.scientificamerican.com/article/physicists-trap-a-single-antimatter-particle-for-a-month/
313•mooreds•3d ago•89 comments

Online censorship is crushing indie webcomics

https://xtramagazine.com/culture/online-censorship-indie-webcomics-284463
72•Tomte•2h ago•57 comments

Bbtree: Fastest Ordered Map

https://bbtree.xiangpeng.systems/post/
120•aoli-al•17h ago•15 comments

Pragtical v3.14 Lua-based text editor adds menus, floating views, and sessions

https://pragtical.dev/blog/pragtical-v3140-release
19•rd07•4d ago•3 comments

Roku developer repositories moved from GitHub to GitLab

https://blog.roku.com/developer/gitlab-move
288•cxr•19h ago•203 comments