Jean-Paul S. Boodhoo

Sponsors

The Lounge

Wicked Cool Jobs

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
Updated BDD Naming Macro

After an awesome session pair programming with Scott the other day, I am going to start taking advantage of natural sentence style naming for not just my test method names, but the names of the test fixtures themselves.

The name of the fixture will now become the context for the tests inside of that fixture. It is actually surprising what level of detail this allows you to express yourself.

I had to change my test naming macro to support classes also. Here is the fix:

 

Imports System Imports System.Windows.Forms Imports EnvDTE Imports EnvDTE80 Imports System.Diagnostics Public Module CodeEditor Sub ReplaceSpacesInTestNameWithUnderscores() If DTE.ActiveDocument Is Nothing Then Return Dim wrCS As Boolean = DTE.Properties("TextEditor", "CSharp").Item("WordWrap").Value Try DTE.Properties("TextEditor", "CSharp").Item("WordWrap").Value = False Dim selection As TextSelection = CType(DTE.ActiveDocument.Selection(), EnvDTE.TextSelection) Dim index As Integer selection.SelectLine() If selection.Text = "" Then Return Dim methodIndex As Integer = selection.Text.IndexOf("public void ") Dim classIndex As Integer = selection.Text.IndexOf("public class ") index = CType(IIf(methodIndex >= 0, methodIndex, classIndex), Integer) Dim prefix As String = CType(IIf(methodIndex >= 0, "public void ", "public class "), String) prefix = selection.Text.Substring(0, index) + prefix Dim description As String = selection.Text.Replace(prefix, String.Empty).Trim selection.Text = prefix + description.Replace(" ", "_").Replace("'", "_") + vbCrLf selection.LineDown() selection.EndOfLine() Catch ex As Exception MsgBox(ex.Message) Finally DTE.Properties("TextEditor", "CSharp").Item("WordWrap").Value = wrCS End Try End Sub End Module

Develop With Passion


Posted Thu, Nov 29 2007 2:15 AM by bitwisejp
Filed under:

[Advertisement]

Comments

Casey wrote re: Updated BDD Naming Macro
on Thu, Nov 29 2007 6:57 AM

Thanks for the inspiration!

I found that the idea was great, but didn't tie in to my typing conventions, so I have posted a version that splits the words based on a Regex ...

blog.goinsane.co.uk/.../AlternativeVersionOfJPsTestNamingMacro.aspx

cmyers wrote re: Updated BDD Naming Macro
on Thu, Nov 29 2007 9:03 AM

@JP, Can you give an example fixture class name and a test method name that you're using?  I've been using the test-method-naming style that Scott and you have both talked about it and it's working wonderfully.  I just want to make sure I'm doing it 'right' (i.e. I'm getting as much value out of it as I can).

GrabBag wrote Converting tests to specs is a bad idea
on Thu, Jan 10 2008 5:40 PM

When I first started experimenting with BDD , all the talk about the shift in language led me to believe

Devlicio.us