Unit testing graphics code is hard, really hard. When you take a good look at your code, a lot of it won’t even call into your renderer, that code can be tested with standard approaches. For testing your actual renderer, you can write to frame buffers and read back the results, comparing against some known truth. Even something this basic is a good sanity check for running on different cards or if your renderer does something spiffy (e.g. automatically set shaders uniforms). Ultimately, you are going to run into issues with different cards, drivers, operating systems, configurations (AA or no AA), etc. The best we’ve done is allow different ways to compare images and different tolerances.
This is a great point. I’ve never tried it but I’ve always thought that if you have your renderer abstracted, you could write one for “dependency injection” for unit tests. For example, when you know your code is correct. you run it with a renderer that writes the calls to disk, then when the unit tests are ran, it verifies the same calls are made. I’m sure this would be quite involved but I’m curious if anyone has ever experimented.