2

I have some chart rendering tasks that I want to cover with tests. I used svg renderer in my tests. At first run I generate some files. At next runs I want to compare output with first run results. If they are different tests should fail. It was just fine. The issue is that such rendering is platform depended. So that I cannot run same tests on Linux and Windows. I don't like it at all. How can I write cross platform tests for stuff that used JFreeChart?

Stan Kurilin
  • 15,614
  • 21
  • 81
  • 132
  • Why not compare the SVG files, without rendering? – Dmitri Feb 03 '12 at 15:47
  • @Dmitri I compare new render result with old one. How I can do it without rendering? – Stan Kurilin Feb 03 '12 at 15:59
  • I misunderstood, thought you were rendering the SVG to bitmap images before comparing. You could always save platform-specific test files and detect the platform when testing. – Dmitri Feb 03 '12 at 16:18
  • @Dmitri Ok. I have some module that produces SVG files. In my tests I produce some files using this module. At first run I produce some files. In next runs I want to compare new files to old ones. If there are difference they should fail. – Stan Kurilin Feb 03 '12 at 16:24
  • I'm with you now. So, can you generate the reference files on both platforms, so you can compare the correct one based on where you're running the tests? – Dmitri Feb 03 '12 at 16:31
  • @Dmitri I doesn't like this approach. It can be more than two platform. There can be different behavior on Macs or in other Linux distributions. Anyway, I use Java to write platform independent code. Why I should write tests for each platform/configuration separately? – Stan Kurilin Feb 03 '12 at 16:37
  • Also, just because the two outputs match, that doesn't mean that _either one_ is correct. I mean, if you pass it data that should result in a chart/image, but due to internal bugs it gives you a blank one, your test wouldn't necessarily be able to detect incorrect behaviour. – Clockwork-Muse Feb 03 '12 at 16:53
  • @X-Zero I can watch results myself. But I want to do it only once. On first run. I don't want to verify it for each platform. Also, currently both results are correct. But they are different. – Stan Kurilin Feb 03 '12 at 16:59
  • See also [*Image comparison—fast algorithm*](http://stackoverflow.com/q/843972/230513). – trashgod Feb 04 '12 at 01:40

1 Answers1

0

Ok. I solve this issue. If someone have same issue keep in mind next hints

  1. JFreeChart use platform specific fonts by default. So you should distribute your ttf font and set it explicitly for each label. You can load font by Font.createFont.
  2. Use specific locale. You can set default locale for your test by next code Locale.setDefault(Locale.US);
Stan Kurilin
  • 15,614
  • 21
  • 81
  • 132