Showing posts with label Testing. Show all posts
Showing posts with label Testing. Show all posts

2026-07-18

Side Quest: Infrastructure Build-Out

My hobby programming project stalled out. Again. Because I still didn't want to npm install.

This time the issue was a test harness.

The project is a wannabe game engine. Or at least a wannabe animation engine for now: user interaction is still in the works. I had gotten far enough to be bothered by the ways the physics isn't working right.1 But the code is growing in size, and fixing the physics code will be fiddly. That is, after all, why it doesn't work right as things stand. Unit tests are part of my process for handing that kind of fiddly.

And when you search for pure JavaScript unit testing frameworks, they all request the forbidden incantation as step one. For the same perfectly valid reasons tall the language server did, I'm sure.

Now, I've written testing frameworks of various kinds in the past. A set of tests in Fortran for my dissertation analysis after the second attempt collapsed under it's own weight; a really kludgy mess of c-preprocessor and GNU-make just because I thought I was clever,2 and a command-line end-to-end driver at work. None of them are professional or polished but they all work in some sense, and that teaches a lesson: it doesn't have to be fancy to work.

With that sort of thing in mind I conceived a vague notion of a minimal test harness that would write its output into a webpage.3 Obviously I'm not the first person to have that idea, and a little searching got me an example to use as inspiration. Thanks, Alex!

Only I couldn't leave well enough alone. I made it part of my "learn to program with AI" effort, worked with Gemma4 to give it a fluent interface despite my misgivings about that whole idea and thus was TestOf born. Maybe it'll be useful for someone else.


1 Embarrassing for a physicist, I can assure you.

2 Please use something better than that!

3 We are talking JavaScript, after all.

2026-05-26

I wonder what the experts would think of my take?

Learned about "property based testing" today. A little. Initial impression: it's (at least in part) fuzzing at the unit test or integration test level instead of the end-to-end level.

Also I already do something like a lite version of that in a few cases. Indeed, I've been trying to formulate a good blog post about one of my practices that I don't see much in other discussions of unit testing. Alas, it seems there's a whole community out there stealing my thunder.

2023-08-05

What if it's untestable?

I've been working on evolving some code down in my project's foundation to enable to user visible improvements. My stategy involves the C++ standard library facility variant which allows the user to stores a single value at any given time but from multiple different types. For those of you with the proper background this is an improved union.1 It also provides some basic infrastructure for the situation when it does not hold a value at all, and I've been diligently covering my a all the bases as I go along.

Now I want to test so aspects of the work I've done so far.

Testing the "variant is in a bad, bad place" code means making a variant in a bad, bad place. Only it turns out that is not at all easy.2 There isn't a facility to make one. Not brand new to made-to-order, nor from an existing one by any usual means. cpp reference says

A variant may become valueless in the following situations:
  • (guaranteed) an exception is thrown during the initialization of the contained value during move assignment
  • (optionally) an exception is thrown during the initialization of the contained value during copy assignment
  • (optionally) an exception is thrown when initializing the contained value during a type-changing assignment
  • (optionally) an exception is thrown when initializing the contained value during a type-changing emplace
and it includs a sample of code to do the job, and a link to an online platform to compiler and run and see that it does the job. Now that code uses a custom type so I can't use it directly, but where I try to ape it using one of the types in my variant ... it doesn't work. I'm able write code that will hit all the last three conditions, but apparently my compiler is too smart for that.

Well, given how hard it is to access that state maybe testing the code that handles is houldn't be a high priority, but I"m annoyed.


1 Nor is it anything like a new idea, but it wasn't made part of the C++ standard library until the 2017 standard. Thankfully, by project has moved that far forward in time.

2 Of course this is a good thing. Except that it isn't quite impossible, so there is all that infrastructure there for handling the special case. Argh!

2021-10-25

How do I test a spreadsheet?

One of my hobby horses for up and coming science students has long been a recommendation that they learn to use a "real" analysis package fairly early on. Something that supports fitting things other than lines, knows about error intervals, and the like. A common counter-comment is that spreadsheets can do an awful lot and the students already know them. I don't disagree with the basic premise of those comments. Indeed I used to be very happy to show students who weren't going into science how to use a spread sheet to perform their lab analysis.1 I also stand by my recommendation because the domain specific support in spreadsheets runs out with roughly the tools that are also used by business majors and they scale poorly as programming environments (even the ones that are Turing complete).

Despite knowing this I've just run right up against that limit.

I've mentioned my daughter's honorary Grandma before. She's a friend who lives with us. She has a neurodegenerative disease and can't take care of herself and my wife holds her powers of attorney (with me as the backup).2 Now the good news here is that Grandma has sufficient financial resources to pay for plenty of high quality care. She could afford a really good nursing facility, but when presented with the choice she opted to stay with us.3 Even when I had to move the family cross-country for a new job. So, that care takes the form of full time aides, and for more than a year and half it's been a private pay arrangement instead of using an agency. Long story, but the result is that my wife is in effect a healthcare manager, HR department, and payroll department. I pitch in as much as I can, but the main burden falls on her.

Right now payroll is a highly manual thing. Hours are recorded on paper and collated at the end of each pay period, then individual spreadsheets are worked up taking into account various categories of overtime and PTO.4 Now, my wife passed the programming courses that were required of her in her engineering education and puts up with my rattling on about trade-offs and choices I encounter in my work, but she doesn't naturally reach for programming to solve her own problems.

I, however, do, and when I learned of the state of the payroll process last month I quickly banged out a spreadsheet template which I believe supports all our policies and can be printed as a clear and concise description of what is being payed how and why.

And we're not using it. Because it is untested.

Can I write a little suite of unit tests for a spreadsheet? If so, how?5

Can I, at least, create a few example cases that exercise all the parts? I suspect that this is my best bet.

Other options?


1 Though they mostly turned to their peers for this advice. Especially after the first night. Fine with me, of course, gave me more time for other things and once they start learning from one another the idea spreads.

2 There is a lawyer in my family, and they are as pedantic a bunch as physical scientists and computer nerds, so I've had it pounded into my little brain that the power of attorney is a document and a person exercising such a document is, contrary to popular usage, an attorney in fact. You didn't need to know that, but I needed to spread the pain.

3 She came to be living with us in the first place because we thought we were only hosting her through a period of rehab and recovery after a hospitalization and before we got the scary diagnosis.

4 Because Grandma can afford it and to hold good staff we offer higher wages and better benefits than are normal in this woefully underpaid line of work. More than half our carers are CNAs and the rest are well on their way to being skilled up to it. They are all tasked with skilled, often unpleasant, occassional physically demanding, and very responsible work. Now in a private care situation like at our house they get a fair amount of downtime, but they also have to do without partners for moving the patient and the like. Yet somehow PTO isn't a thing in the industry.

5 It's a Google doc, on the off chance that someone knows the answer for select programs.