This post originated from an RSS feed registered with .NET Buzz
by Darrell Norton.
Original Post: FileAssert - comparing 2 binary files using NUnit
Feed Title: Darrell Norton's Blog
Feed URL: /error.htm?aspxerrorpath=/blogs/darrell.norton/Rss.aspx
Feed Description: Agile Software Development: Scrum, XP, et al with .NET
At the beginning of this month I blogged about the Code of the Month. For July the program we are looking at is NUnit. As part of the code reading, I wrote an extension (sort of) that compares two files to determine if they are equal. The code uses NUnit internally, calling Assert.Fail if the files are not equal.
The FileAssert class has two basic methods for comparing files. One method takes in two FileStreams, with an optional overload for the message if the test should fail.
I tried to match the NUnit coding and commenting style as much as possible. All XML comments are included (the file is C#). And of course I wrote unit tests for everything! I tested this on files as large as 189MB. On my 2.8ghz machine with 512MB RAM, the comparison took under 4 seconds. A 10MB file comparison took under a half-second.
You can download this, and other extensions coming soon, from the NUnitExtensions workspace on GotDotNet.
This Blog Hosted On: http://www.DotNetJunkies.com/