Reputation: 718
I have custom QWidgets where all the painting is done manually (fillRect, drawRect, drawText, drawPixmap..) . There are up to 120 properties affecting what's going to be paint, how it's blinking and so on. Legacy spaghetti code.
When I'm changing something I would like to first test cover old functionality. Is there a recommended way how to cover QWidget::paintEvent(QPaintEvent* event)
with unit tests? Do I have to mock QPainter, or is there a way for checking paintEvent output?
How you are covering paintEvetnt with tests?
Upvotes: 0
Views: 410
Reputation: 718
Finally storing and comparing images like:
auto configuredImage = widgetUnderTest->grab().toImage();
QImage sampleImage;
sampleImage.load("src/Images/configuredImage.png");
QCOMPARE(configuredImage, sampleImage);
Upvotes: 1