Unit testing rendering?

I’m working on a small 2d-game engine and I’ve run in to some trouble. So far I’ve been very strict on coding test first programming and using JUnit to test everything. But now I’ve come to the point where I’m rendering simple graphics, but I have no idea how to test this. ???

I’m guessing I should use some how BufferdImage.createGraphics(); to create a Graphics2D, render and then check the image for result. But beyond that I have no idea how to do things. Is there any one here that has had any experience with unit testing rendering that can give me a pointer or two in the right direction? :-\

Just f’ing google it, for a start. But, beyond that, I would suggest you probably don’t need to bother. Rendering unit testing takes a lot of effort and is worth the pain on large projects with many artists and toolchain and rendering and systems coders, but not so great on small projects.

you can try something like this

http://oddlabs.com/blog/?p=20

It’s not exactly unit test, but it will save you time and it’s very easy to implement

I have yet to see a good method of unit testing graphics, other than the badly flawed “take a picture and compare it to a canned result” method.

I think you should be able to put the surrounding code under test (eg. image loaders, sprite priority management, etc.). But if you’re using Java2D most of these are already written so you’re only really writing the glue to put it together. I might have a MockRenderer which just checks that certain objects are actually calling into the renderer at the correct times/places, but even that might be overkill.

Thanks! It wasn’t really what I was looking for but it gave me some (hopefully good) ideas. If there was just some way to log Graphics2D. DebugGraphics has a functionality like this, but only for Graphics and I need the Graphics2D transformation stuff. Maybe I can implement a wrapper myself doing something like this on all Graphics2D methods:



public void drawString(String str, int x, int y) {
   someList.add("public void drawString("\" + str + "\", "+x+", "+y+") ");   
   realGraphics2D.drawString(str, x,  y);
}


Of course, doing this manually for all functions would be insane (in a bad way). Maybe it could be made with automated code generation. I’ll Google it and see if I can figure something out. Thanks again :smiley:

you’re welcome :slight_smile:

keep us posted on the solution

Out of interest, why do you consider this mechanism to be badly flawed?
(barring the obvious task of ensuring the canned result itself is loaded in correctly)

In the world of J2ME I very much wish Sun HAD done this kind of unit testing of the reference implementations primitive & image drawing methods, as alot of them mis-behave in embarrassingly simple scenarios.

Well for a game I don’t want all my graphics unit tests to break just because I tweeked the shader and traded some accuracy for performance. Practically all pc-style hardware rendering can give slightly different results based on drivers, hardware, colour depth, etc. etc. but will all still look ‘correct’. Then you start getting into %age difference between the test result and the reference, and it all gets a little icky.

However now you mention in, for JME and other low-level pixel pushing APIs this method would probably work pretty well. You should be able to get much more reproducable results when you’re just talking about basic sprite blitting.