AAA- Unit testing file IO - logging

226 Views Asked by At

I am writing a custom logger for a program. I am using NLog as much as possible. I am looking to verify functionality and have written some unit tests using the AAA pattern.

However this causes the problem with Assert.... How can I/Whats the best method for Asserting a file write happened... and it wrote out correctly.

I mean I can do a file.read to get the last line, and assert it is equal to the param written out... I just dont know if that defeats the AAA purpose....

1

There are 1 best solutions below

2
On

One Unit Test should not influence the outcome of another unit test.

AND

unit tests may run in parallel

So: you should not log from several tests to the same file.

  • Try to use a private logger/logfile in each test
  • Clear the logfile in the Arrange phase
  • Check contents of complete file, not just the last line