New Snippet New Snippet Recent Snippets Recent Snippets My Snippets My Snippets Web Code Search Snippets Search
Sign inor Register
Language: VB.NET

Statlight Test Runner Macro

60 Views
Copy Code Show/Hide Line Numbers
Imports System
Imports EnvDTE
Imports EnvDTE80
Imports EnvDTE90
Imports EnvDTE100
Imports System.Diagnostics
Imports System.IO
Imports System.Threading
Imports System.ComponentModel
 
Public Module TeamUtilities
    Dim WithEvents t As Timers.Timer
    Dim TestName As String
    Dim XapPath As String
 
    Sub RunSingleSilverlightTest()
        GetTestAndXapNames()
        DTE.ExecuteCommand("Build.BuildSelection")
        t = New Timers.Timer
        t.Interval = 1000
        t.Start()
    End Sub
 
    Private Sub FinishRunningSingleSilverlightTest(ByVal ee As Object, ByVal dd As Timers.ElapsedEventArgs) Handles t.Elapsed
        If DTE.Solution.SolutionBuild.BuildState = vsBuildState.vsBuildStateDone Then
            t.Stop()
 
            Dim statlightCmd As String
            statlightCmd = """C:\Program Files (x86)\Statlight\statlight.exe"" -x=" + xapPath + " -t=" & testName
            Shell("cmd /k" & statlightCmd, AppWinStyle.NormalFocus)
 
            'TODO: Get path of xap file in a more robust way
            'Dim test As DirectoryInfo
            'test.GetFiles()
        End If
    End Sub
    Private Sub GetTestAndXapNames()
        Dim codeElement As EnvDTE.CodeElement
        Dim sel As EnvDTE.TextSelection
        Dim editPoint As EnvDTE.EditPoint
 
        sel = DTE.ActiveWindow.Selection
        editPoint = sel.ActivePoint.CreateEditPoint
        codeElement = GetCurrentCodeElement(editPoint)
        If codeElement Is Nothing Then
            MsgBox("The cursor was not in a class or function.  Place cursor in a silverlight TestMethod or TestClass and run again")
            Exit Sub
        End If
 
        'TODO: Look for attributes [TestClass] and [TestMethod] associated with function
 
        Dim assemblyName As String
        XapPath = DTE.ActiveDocument.Path
        XapPath = XapPath.Substring(0, XapPath.IndexOf(".Tests") + 6)
 
        assemblyName = XapPath.Substring(XapPath.LastIndexOf("\") + 1, XapPath.Length - XapPath.LastIndexOf("\") - 1)
        XapPath += "\Bin\Debug\" + assemblyName + ".xap"
 
        TestName = codeElement.Name
    End Sub
 
    Private Function GetCurrentCodeElement(ByVal editPoint As EnvDTE.EditPoint) As EnvDTE.CodeElement
        Dim elem As EnvDTE.CodeElement
        Dim types As vsCMElement() = _
            {vsCMElement.vsCMElementFunction, _
             vsCMElement.vsCMElementClass}
 
        Dim type As vsCMElement
 
        For Each type In types
            elem = GetCodeElement(editPoint, type)
            If Not elem Is Nothing Then
                If type = vsCMElement.vsCMElementAttribute Then
                    MsgBox(elem.Name)
                End If
                Exit For
            End If
        Next
 
        GetCurrentCodeElement = elem
    End Function
 
    Private Function GetCodeElement(ByVal editPoint As EnvDTE.EditPoint, ByVal type As vsCMElement) As EnvDTE.CodeElement
        Dim elem As EnvDTE.CodeElement
 
        Try
            elem = editPoint.CodeElement(type)
        Catch ex As Exception
            elem = Nothing
        End Try
 
        GetCodeElement = elem
    End Function
End Module
by Keith
  May 31, 2010 @ 5:32pm
Tags:
Comment:
This is a macro for Visual Studio that allows you to run individual (or class of) silverlight unit tests using Statlight (statlight.codeplex.com)

Add a comment


Report Abuse
brought to you by:
West Wind Techologies


If you find this site useful and use it frequently please consider making a donation to support this free service.
Donate