Is there a way to do unit test for module which does not return anything. My function is a void function and it formats the output and write it to a text file.
I am not sure how do unit testing for such a method.
Any suggestions…
Thanks
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Pass in the dependency!
Instead of directly writing to a file, have your method write to a stream instead.
This abstraction allows you to execute the method on a file stream for normal program operation, but for your unit tests you could pass in a memory stream and then verify that the appropriate text has been written to the stream after the method call.
Alternatively you could separate writing to the stream or file from preparing the actual content to write. This would allow you to assert that the correct content is prepared independently from actually writing it out.