Kevin Isom

Just a good ol' boy, by-God Virginia-proud and country-sophisticated -- sort of like a John Deere tractor with air conditioning and satellite radio.

Visual Basic.Net and NUnit Gotcha

I like the NUnit 2.4 Constraint based syntax. So In my new role I am having to implement Unit Testing so I decided on going with NUnit to begin with despite my preference for MbUnit. But once I got started writing my tests, I discover Is is a keyword in VB (I'm more of a C# person, but hey I'm no language bigot). I kinda freak out a little. Did I do something wrong? Forget to add something? Google a bit and still no joy. Then I remember the code examples installed with NUnit and have a look and what do you know? Is is now Iz in VB. Not exactly as clear as Is but you gotta do what you gotta do. So now in VB a Unit Test looks like this

   1:  Imports NUnit.Framework
   2:  Imports NUnit.Framework.SyntaxHelpers
   3:  <TestFixture()> _
   4:  Public Class MyVIsualBasicSampleTests
   5:   
   6:      <Test()> _
   7:      Public Sub TestBlankForSyntax()
   8:          Assert.That(something.IsSomething(), Iz.False)
   9:      End Sub
  10:   
  11:      <Test()> _
  12:      Public Sub AnotherSampleTestForSomethingElse()
  13:          Assert.That(something.IsSomethingElse(), Iz.True)
  14:      End Sub
  15:   
  16:  End Class

And there you go.

Published Thursday, February 28, 2008 8:41 AM by kevinisom

Comments

# re: Visual Basic.Net and NUnit Gotcha@ Wednesday, February 27, 2008 5:51 PM

Doesn't [Is].True work?

# re: Visual Basic.Net and NUnit Gotcha@ Thursday, February 28, 2008 7:55 PM

Yes, the [Is] does work. However I don't think it makes any more readable however.

# re: Visual Basic.Net and NUnit Gotcha@ Wednesday, February 04, 2009 12:48 AM

Haha I just noticed this myself kind of inadvertently. I was trying to create my own custom constraints but needed my own version of the Is static class. I needed a name for my static class that wouldn't clash with NUnit's Is class, so I tried "Iz" and found it was already taken by Nunit.

by CBP

Leave a Comment

(required) 
(required) 
(optional)
(required)