1

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

Dave Schweisguth
  • 36,475
  • 10
  • 98
  • 121
asuppa
  • 571
  • 1
  • 11
  • 27
  • Do you use NLog loggers to implement your custom logger? Are you writing to file yourself or do you use NLog to do that? – k.m Jan 12 '15 at 14:00

1 Answers1

1

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
DrKoch
  • 9,556
  • 2
  • 34
  • 43
  • I guess I worded that poorly, Only one line is written in each test, as I didnt want to run write tests in parallel, the file is cleared after each time, I just wasnt sure the best method to test the contents outside of a read the file and compare, – asuppa Jan 12 '15 at 13:51
  • Well, most Unit-Test frameworks will run your tests in parallel, and you should design your tests in a way that this is possible. – DrKoch Jan 12 '15 at 13:53