开发者

Testing File Creation Wrapper C#.Net - Thoughts

开发者 https://www.devze.com 2023-01-09 09:23 出处:网络
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 aspossible.

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开发者_StackOverflow社区 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.


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).

0

精彩评论

暂无评论...
验证码 换一张
取 消