I’m writing some blog entries that show how to write tests for non trivial pieces of code. This is part 2.
In part 1 I introduced the code that we’re going to write a test for. Now we’ll move towards the all important first test. The first test is, in my opinion, vitally important; the first test proves that you can build a test harness that can create the object. This sounds easy, but try picking a class from your current project at random and writing a test that constructs an instance of that class.
I’m writing some blog entries that show how to write tests for non trivial pieces of code. This is part 1.
The code that we’re going to test is CCallbackTimer. This is a class that lives in our Win32Tools library. It’s used by users of our SocketTools library. The class provides a very light-weight timer manager that gets around the various issues we had with using standard Win32 timers.
The timer is designed to be used in vast quantities.
One of the common complaints about TDD and unit testing that I see is that the examples used aren’t real. People often say that the examples used are toys and that writing such tests adds little or no value. To be honest, I often find myself agreeing with them.
Last updated 25th April 2023
41 - GoogleTest - Moving to GoogleTest.
One of the problems of adding unit tests to an existing code-base or driving a new project with TDD is deciding exactly where to spend your testing efforts.
I was discussing the performance of The Server Framework with someone the other day and realised that there was a reasonably easy way to speed up some types of servers.
I coded a first cut of the solution last night and, so far, it shows a small, but noticeable performance gain for no changes to functionality or code outside of the framework.
The IOCP server framework was always designed for ease of use over performance.
We managed to get in two skate sessions this weekend, which was nice. The weather was lovely and on Saturday we spent some time at Kensington Gardens. This was our third skate this year and we finally started to feel we’d got our legs back. On Sunday we were in Ilford, visiting my family, and just happened to have the skate gear in the car… We skated in Valentines Park for an hour or so; it was good.
Back in January I was writing a TCP/IP server for a client that acted as a connection gateway. Just as this project was coming to an end we started on another project which, at first, seemed quite similar; it was a TCP/IP server that provided gateway services. Just as we were starting out with this new project I made a fairly stupid decision and, well, four months later I’ve almost finished cleaning things up…
I’m currently re-reading The Mythical Man Month 20th Aniversay Edition and I’ve just finished watching Apocolypse Now Redux. Both seem to have as much to say now about their respective subjects as they did in the day. Brooks’ treatment of the “Joys” and “Woes” of The Craft as poignant as Coppola’s tale of the lies and horror of war.
Been a busy week, I meant to post this on The Day. I’ve been writing this stuff for just over a year now. I didn’t really know what to expect when I started, I just wanted a place to ramble on about this and that. During the year I’ve learned a few things about blogging….
I actually do do this for me more than for anyone else. I’ve found that I understand things more when I’ve written about them.
Where did the last three days go?
I’ve been working on this project for a client since February, on and off. They had some delays which meant that hardware that I needed wasn’t ready when expected, so we slipped. Then other commitments got in the way, so we slipped. Then I decided to work around the lack of hardware and make one final push for the finish line…
That was Wednesday.
I’ve spent the past month or so helping a corporate client improve code quality in a sprawling application. It’s non-trivial, the code-base is huge, the quality is, at best, questionable and the coupling is excessive and made worse by the fact that much of the system is coupled together using a single huge blob of relatively unstructured XML. Fun, fun, fun…
As with the refactoring project, the first tests have taken some time to build.