Posts Tagged ‘NavigateToTest’

NavigateToTest VS2013 extension

Saturday, July 26th, 2014
Extension is available for other Visual Studio versions:

You can download the extension here:
NavigateToTest Visual Studio 2013 extension

Here’s the latest version that supports Visual Studio 2013.

Extension is convention based. It matches ClassName file with ClassNameTest or ClassNameTests and vice-versa, so you can easily navigate to the test file and back.

Here are some screenshots:

Here’s the toolbar and two opened files:

You can download the extension here:
NavigateToTest Visual Studio 2013 extension

NavigateToTest VS2012 extension

Sunday, August 26th, 2012
Extension is available for other Visual Studio versions:

You can download the extension here:
NavigateToTest Visual Studio 2012 extension

Here’s the latest version that supports Visual Studio 2012.

Extension is convention based. It matches ClassName file with ClassNameTest or ClassNameTests and vice-versa, so you can easily navigate to the test file and back.

Here are some screenshots:

Here’s the toolbar and two opened files:

You can download the extension here:
NavigateToTest Visual Studio 2012 extension

NavigateToTest VS extension

Monday, May 3rd, 2010
Extension is available for other Visual Studio versions:

You can download the extension here:
NavigateToTest Visual Studio extension

Recently I decided to create a Visual Studio 2010 extension.

Extension is convention based. It matches ClassName file with ClassNameTest or ClassNameTests and vice-versa, so you can easily navigate to the test file and back.

Here are some screenshots:

You’ll need to add toolbar manually:

Here’s the toolbar:

And two opened files:

You can download the extension here:
NavigateToTest Visual Studio extension

GoToTest macro for VisualStudio

Wednesday, September 23rd, 2009
Extension is available for other Visual Studio versions:

4

When you are doing Test Driven Development (TDD) you are constantly switching back and forth between production code and test classes.

As it’s good idea to have those files in separate projects, it’s sometimes very hard to find test code for a class and vice-versa.

Some time ago I decided to write a simple Visual Studio macro, that solves this problem.
It’s based on the convention that all your test classes have Test or Tests suffix (e.g. CSVReader.cs and CSVReaderTests.cs)

I’m far from being VB expert, so the code is not perfect (Why does VS use Visual Basic for Macros?):

Imports System
Imports EnvDTE
Imports EnvDTE80
Imports System.Diagnostics
Imports System.IO

Public Module MainModule
    Dim _patterns As String() = {"{0}Test", "{0}Tests"}
    Dim _reversePatterns As String() = {"Tests", "Test"}

    Sub GoToTest()
        If DTE.SelectedItems.Count = 0 Then
            Return
        End If

        Dim fullFileName As String = DTE.ActiveDocument.Name
        Dim fileName As String = Path.GetFileNameWithoutExtension(fullFileName)
        Dim extension As String = Path.GetExtension(fullFileName)

        If IsTestFile(fileName) Then
            For Each reversePattern As String In _reversePatterns
                If fileName.Contains(reversePattern) Then
                    TryOpen(fileName.Replace(reversePattern, "") + extension)
                End If
            Next
        Else
            For Each pattern As String In _patterns
                TryOpen(String.Format(pattern, fileName) + extension)
            Next pattern
        End If
    End Sub

    Function IsTestFile(ByVal fileName As String)
        For Each reversePattern As String In _reversePatterns
            If fileName.Contains(reversePattern) Then Return True
        Next
        Return False
    End Function

    Function TryOpen(ByVal fileName As String) As Boolean
        Dim item As EnvDTE.ProjectItem
        item = FindItem(FileName)
        If Not (item Is Nothing) Then
            OpenItem(item)
            Return True
        End If
        Return False
    End Function

    Function FindItem(ByVal fileName As String) As EnvDTE.ProjectItem
        If String.IsNullOrEmpty(fileName) Then
            Return Nothing
        End If
        Dim item As EnvDTE.ProjectItem = DTE.Solution.FindProjectItem(fileName)
        Return item
    End Function

    Sub OpenItem(ByVal item As EnvDTE.ProjectItem)
        item.Open()
        item.Document.Activate()
    End Sub

End Module

How to install:

Start Visual Studio and go to Tools/Macros/Load Macro Project…:
1

Right click on the Visual Studio toolbar, and select customize:
2

Select ‘Macros’ category and find ‘GoToTest’ Macro:
3

Of course you can change the name of the button.
4

And finally the macro itself:
GotoTestMacro