Unit-testing – How to write tests that make sense for visualization software

softwaretestingunit testing

I have a fairly large piece of software which takes certain file types and visualizes them / creates a host of buttons for manipulation of the image plotted. I feel like I'm finding bugs / pieces of code that don't actually work once a week, but I'm struggling with understanding how can I write tests for this software?

I understand how tests are important for projects like libraries and API's, you simply write tests that use these functions.

But what about visualization software? It seems to require a different approach due to the visual element(s) involved.

Do I need to write a test program or test harness which runs and manually calls every operation provided that I can use on the data?

What approach should I use in order to start writing tests in order to validate that I fixed the bugs and to alert me if the code breaks again?


There is a related but not duplicate question regarding when you should unit test. Since I'm discovering bugs, I want to write tests in order to help prevent the software from regressing again.

Best Answer

There are a couple of things you can do to make testing software like that easier. First, try to abstract as much as you can into layers that aren't visual. That will let you just write standard unit tests on those lower layers. For example, if you have a button that performs a certain calculation, make sure you have a way to perform that calculation in a unit test with a regular function call.

The other suggestion for testing graphics-heavy programs is to create some output that a tester can easily manually verify. A minecraft example is:

minecraft test output

I've also worked on projects that had a bunch of tests that rendered something on the screen, then prompted the tester to manually verify it matched the description. This makes sure you don't forget test cases later.

Testing is often extremely difficult if you didn't originally design with testing in mind. Just work on putting your most fragile code under test first. When you find a bug, make a test that will catch that bug if it happens again. That often prompts writing related tests while you're at it.

Related Topic