views:

31

answers:

1

Hi All, This is probably a noob question that I will get slated for but here goes... Sorry for the length tried to keep it as short as possible.

BackGround

I'm working on tidying up a code base that I inherited in my new role. So I'm introducing tests as I work on sections/Bugs/New Features. One of these features is an invoice printing function the invoice is generated from a crystal report rpt file. There was already a small wrapper for the underlying Crystal functions, I'm just wanting to test it out and make sure we produce the files as required.

Problems Firstly, I know that anything using file IO should not be part of unit testing but can I cover this with Integration Tests / System tests? Do I just run the wrapper with preloaded data and check it spits a file out? Can I interrogate the PDF programatically and make sure details are correct?

I have also tried to mock out some of the IO so that I could unit test the wrapper but here I have problems with moq not liking the crystal ReportDocument class. Also I had to really change the structure of the Class to allow for testing, should I really be doing this (sort of feel like I should) but making privates public just so I can insert test data seems a bit wrong.

I haven't posted code as this is more a theoretical debate at the minute... I'd love to get some code coverage but not sure if I'm over thinking things can somebody please advise me on these type of situations.

Thanks ever so much.

A: 

I wouldn't worry about unit testing this class, because its a integration class by nature. The implementation should be fairly simple (just wiring methods to the underlying crystal reports objects etc), so I wouldn't even bother to have a dedicated integration test for this single class. You should however cover it by acceptance/higher level integration tests. I am not sure how Crystal Reports works, but ideally you would like to compare the pdf in a binary way with a known good version (this will only work if the generated files are always the same).

Grzenio
Thanks for that Grzenio. Sounds like the way I had started to look at it got a bit side lined with coverage, testing the wrapper really wouldn't give me anything. Do you have any info on comparing the binary info for higher level tests? Not to bothered about the Crystal side but I like the sound of testing against a known good pdf.
Andyroo