Stacks Dev Blog -- Integration Testing a Plugin

After writing about the success I had building a test-fixture to profile my plugins in Instruments, it struck me that profiling was only the tip of the iceberg.

Another pain-point for the past ten years of building Stacks has been the lack of complete integration testing.

I can do unit-testing, sure. And that’s great. As Stacks has matured I’ve leaned on unit-testing more and more. But opening a complex page and running a full export required RapidWeaver. Of course I can test against the RapidWeaver app, but it’s difficult to do controlled testing on an opaque app.

I did write a weird command line app that force-feeds RapidWeaver a file and tells it to export. But it’s very much a hack and as soon as it was written, the private calls used to make it work were already stale and failing. Things that stop working suddenly and often tend to fall into disrepair very quickly.

But my profiling app works great for as a stand-alone test-bench. I can finally do complete exports!

Well… Sort of…

Any place in the code I bump into the RapidWeaver API things break, of course. Even linking in the RapidWeaver API frameworks isn’t a fix – exporting needs the private parts of the app too.

But years ago, probably to buffer Stacks from the vast RapidWeaver 6.0 API changes, I built an API “shim”. It’s my own interface that does the work of talking to the RapidWeaver API. My shim knows about all the little RapidWeaver API changes in each version, but presents a consistent interface to the rest of Stacks. Stacks never calls the RapidWeaver API directly. Only the shim.

So… I just wrote a mock for the other side of my shim that imitates the basics and fakes the rest. And boom! I’m in business. Now I can do complete integration and speed testing on full scale exports. I know this may seem like a really boring detail, but I just did a literal happy dance in my office.

Now I’m kicking myself for having not done this years ago. I guess I thought it would be a lot more work, or maybe even impossible. But a bunch of things like this shim have been in place for years – I just hadn’t ever really pieced them together in a complete test-fixture.

isaiah @isaiah