Poor Man’s PiTest

Unit testing, as important as it is, is still treated as an afterthought. First, we write production code and then tests — if we have enough time and, more importantly, the will. Unfortunately, the natural result of this process is missing coverage, weak or absent assertions, and, more importantly, a lack of real exercise of the production code. I believe these issues are well known, but somehow they’re still not important enough to change the process. After all, we have production code; let’s ship it — “Damn the torpedoes, full speed ahead!”


In my opinion, this issue is well addressed by Kent Beck and Robert C. Martin (Uncle Bob), who emphasize starting with a test. Unfortunately there seems to be lots of fluff, buzz and general misunderstanding of TDD. No, it is not Test-First. No, there is no magic sauce. No, there is no need to read tons of books or go to fancy lectures. After reading a few books, watching a few videos, attending a few fancy lectures and a few years of relentless practice, I can definitely say that all you essentially need is to read Kent Beck’s book – Test-Driven Development: By Example, watch Robert C. Martin and stick to The Three Rules of TDD. While Kent and Robert do not address every single scenario and issue, the above resources are more than enough to extrapolate and adapt the technique, let’s say to microservice architecture (which is not originally addressed). Now I’m not saying those are all the resources that you will ever need, but those are essential for TDD! Last but not least, if you don’t know how to do dependency injection without @Autowire (unfortunately I’ve seen that), it does not mean TDD sucks, it means you lack knowledge. TDD is not magic or a Swiss Army knife, it is a specialized technique for writing code independent of any specific platform, framework or language.

Example of useless 100% code coverage

Unfortunately TDD is not widely adopted, and even if it was, we are still subject to mistakes — we are only human. Under these conditions we need a solution that does not rely on a human. One bad solution is code coverage. Code coverage has been around forever and is loved by managers as it neatly translates to charts, means little, and can easily be faked by developers. Code coverage has its uses, but it is useless in determining how well production code is actually tested. But don’t despair, we do have a solution — mutation testing. Mutation testing has a simple premise: change production code, see if any tests fail. If nothing is failing after the change, that means insufficient testing. In an inverted way it sure resembles TDD. While the premise is simple, execution is quite expensive! See how long your test set takes, then see how many logical and state changes can be applied in production code, multiply those numbers and you see how much time mutation testing will take — in short, a while for a sufficiently large project. That is probably the reason we don’t see mutation testing everywhere.

Mutation testing is hard to fool

Fortunately the Java world is blessed with a modern tool for mutation testing – PiTest. It provides lots of features in its open source form. Even more features come with the commercial extensions, which integrate into a modern pipeline (or dev machine) and provide quick feedback to developers waiting for code review on their code changes. I wholeheartedly suggest buying a license and using the full power of mutation testing if code quality is important. Unfortunately my company, for various reasons, isn’t quick to sign up, despite claims to strive for quality. After a proof of concept, presentations, near begging and a final rejection, I fell into depression. I really wanted to use PiTest for tangible results and partly because it would have made my life a lot easier and the life of junior developers a lot harder – since I would not have to spend any time figuring out if their test code actually tested enough or anything at all (yeap, I’ve seen those cases too).

Finally, I realized I’m an engineer; my realm of possibilities lies far beyond microservices. I decided to build a “Poor Man’s PiTest”: a small tool that takes the open-source core and combines it with the power of Bash, Git, and a few other Linux commands. That gave me the ability to build only the projects that are needed, run PiTest only on the changed classes in a multi-module Maven project with a mix of JUnit 4 and JUnit 5 modules, perform timing analysis, log everything for debugging purposes, and optionally skip builds and/or focus on a single module if needed. So far it works well and, let me tell you, junior developers just “love it” — especially when I give them a long report of everything that’s been missed.

I figured someone might be in a similar situation, perhaps needs a bit of inspiration or an example, so I created a GitHub repository to share the script.

Thank you, and I hope the script will be of some use.

15 years or 300k kilometres with Accent

It’s hard to believe, but it’s been almost 15 years since I bought my Hyundai Accent. Quite a few things happened along the way: marriage, fatherhood, a house, Covid, a Miata, the war in Ukraine, October 7th, economic ups and downs — but one thing remains the same: my main drive.

I’m not sure where to start. I guess I’ll start at the beginning: I bought the Accent because my old car was pretty worn out and I had just gotten my first corporate job. I needed to show up every day, and to do so, I had to drive a bit of a distance on the highway. My main criteria were quite simple: reliability and economy. After some consideration and monetary incentives from Hyundai, I purchased the Accent for $16,500 Canadian dollars out the door. Looking at today’s market and back at that price, I can’t believe I got a new car for $16.5K all inclusive! Oh, and it wasn’t a base trim either — it was the GL trim (power windows, AC, cruise control) with automatic transmission. I know those features don’t look like much nowadays, but back then they were all options, especially for compact cars.

The car performed very well, considering that during the week I averaged around 100 kilometres per day and every other weekend took a trip to Toronto. So the miles were adding up quite rapidly. Ah, and the road trips — the biggest one was across the USA, from Detroit to New Orleans to Florida and back. I maintained the car rigorously but didn’t baby it. A few years back, I even used it for construction — loading up bags of gravel and concrete blocks in the back. The car looked like it was lowered, and I thought the shocks would finally give out — and yet, here it is, still on the original shocks. Are they in good shape? Nope. But they haven’t blown yet!

Funny enough, as inconvenient as a 3-door hatchback might look when it comes to children, in a way it’s quite safe — no doors (or windows) to open in the back — security by default. Somehow we got through all the baby seats without much hassle. Yes, the car is small and there are no back doors to open and stick a child in, but somehow it never bothered me.

As far as repairs go, there were a few. Some due to mileage and some due to stupidity on my part. I replaced the power steering fluid with the incorrect one… well, the car didn’t like it. I didn’t realize it and figured the steering pump went bad, so I replaced it — to no avail. Once the fluid got replaced, it became painfully evident that the new pump was completely unnecessary… oops. I replaced the valve gasket that started leaking sometime last year or two ago, but I didn’t notice it until the throttle cable snapped. Both jobs were pretty easy and DIY-friendly, even though the gasket took a lot longer since I wasn’t entirely sure what I was doing.

Speaking of DIY, the Accent is pretty simple and straightforward — you can do all of the maintenance yourself and even some minor repairs. Moreover, since the drivetrain is small, it doesn’t take much — engine oil capacity is about 3.4 litres. That leads me to an interesting thought: since original parts last so long and most of the work can be DIYed, you can purchase spare parts from the dealership. Yes, they cost considerably more, but you know they’ll last and, more importantly, fit properly when you install them yourself.

I must add one honourable mention: the Accent loves ignition coils — can’t get enough of them. Each coil lasts about 70,000 kilometres, then it burns out. So I always keep one in the car, just in case a coil decides to give out.

I must admit, the Hyundai Accent is a no-frills car — super basic, without even ABS or traction control. But in a way, that makes it quite unique nowadays. I wish I had bought it with a manual transmission; it would have been even more amusing today. Actually, manual roll-down windows would give it extra charm — you just don’t see them anymore. I think I put it well in “A Decade with Accent” when I said: “If I needed personal transportation, I would buy an Accent again.” I still stand by that statement, even though I wish the Accent had a bit more comfort in the seats — I guess age is talking now. On the other hand, I’ve found that noise-cancelling headphones make any long trip in any car a lot more comfortable.

So what’s the plan for the future? The car is actually in pretty good shape. It has one rust spot on the body that I can’t seem to eradicate, and some minor rust on the subframe (which I treat every so often), but otherwise, it looks good. Don’t get me wrong — it has paint chips (highway driving) and dents (thanks to my mom and local stores), but hey, which car doesn’t at 300K kilometres?

So the plan is to drive it as long as I can and see how far I can take it. The engine is still good, no burning oil, even though it shakes somewhat noticeably on idle and throttle body cleaning didn’t help — but I’m sure I’ll figure it out eventually. The transmission is still shifting just as it did when new (which wasn’t smooth on second gear). No major issues to speak of, only a few small things like the light switch in the trunk that doesn’t seem to work anymore (I should replace it). So, let’s see if it can make it to 20 years — and perhaps beyond.