Unit Test Graphics

Is there a standard best practice for unit testing code that generates graphics? I work specifically with Java and jUnit, but I think this concept will be applied in other languages.

So far, the best I can think of is to use Mockito to mock an object Graphicsand claim pre-calculated things like (pseudo-code):

assert that graphics.drawString was called with ("abc", 50, 100)
assert that graphics.setBackgroundColor was called with Color.RED

While all of this is good and good, I was wondering if this was the right thing to do, or if there was a more common practice of testing graphic code.

+5
source share
3 answers

, , SVGGraphics2D Batik SVG.

, SVG XML , , , , , .

, SVG (, ), .

+3

- Mockito . , drawString setBackgroundColor.

- :

import static org.mockito.Mockito.*;


Graphics graphics= mock(Graphics.class);
//Run you code .... 

//verification that the methods were called 

verify(mockedList).drawString ("abc", 50, 100);
+1

, api. . api ( ), . , (, -) , . , (, " " ). , -

+1

All Articles