Darrell Norton's Blog [MVP]

Sponsors

The Lounge

News

  • Darrell Norton pic

    MVP logo

    View Darrell Norton's profile on LinkedIn

    Currently Reading:

    weewar.com

Advertisement

Images in this post missing? We recently lost them in a site migration. We're working to restore these as you read this. Should you need an image in an emergency, please contact us at imagehelp@codebetter.com
FileAssert - comparing 2 binary files using NUnit

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.

static public void AreEqual(FileStream expected, FileStream actual, string message)

The other method takes two FileInfo objects, again with a message overload.

static public void AreEqual(FileInfo expected, FileInfo actual, string message)

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.


Posted 07-20-2004 11:02 AM by Darrell Norton

[Advertisement]

Comments

Jonathan de Halleux wrote re: FileAssert - comparing 2 binary files using NUnit
on 07-21-2004 12:40 AM
Hi Darrel,

I would like to add this functionality to MbUnit. Would you like to contribute ?

Jonathan
Darrell wrote re: FileAssert - comparing 2 binary files using NUnit
on 07-21-2004 1:40 AM
Certainly!
Jason Row wrote re: FileAssert - comparing 2 binary files using NUnit
on 07-21-2004 2:47 PM
Well done Darrell .... guess you'll have less time to devote to URLScan Watcher now <grin>
Darrell wrote re: FileAssert - comparing 2 binary files using NUnit
on 07-23-2004 5:14 AM
Nah, I just have to coordinate my source files. URLScanWatcher is on my laptop at home (current client prohibits us from using our company laptops) and the FileAssert I whipped up here at work in an hour or so. Doh!

It would also help if while I am home I am not *sick*. I blame it all on moving... :)
TrackBack wrote re: Unit Testing and Isolation
on 03-21-2005 7:11 AM