logoalt Hacker News

jph • yesterday at 8:10 PM • 0 replies • view on HN

There's low-hanging fruit IMHO by testing using semantic naming vocabulary with semantic error vocabulary.

Example macro: assert_approx_eq_with_relative_error!(a, b, err). It's a semantic name that explains more about what it does, and the macro also provides a test failure message that guides the developer, or an AI, toward fixes and documentation.

I wrote the Rust crate Assertables to help with this. See https://crates.io/crates/assertables.

What I learned is writing semantic testing can help many more kinds of higher-value testing. As a specific example described by the article, I use enumeration testing for proving the UK National Health Service Number validator in Rust is accurate i.e. the test literally checks every number, then I can write tests such as assert_valid_nhs_number("111 111 1111").