2012-01-13 5 views
2

나를 위해 프로세스 (nunit.exe)에 첨부하는이 매크로를 기록했습니다. 이제 내가 붙이고있는 프로세스의 창에서 "Run"이라는 버튼을 누르기를 원합니다. 나는이 매크로를 기록한 :다른 프로세스에서 단추 누르는 방법 (nunit.exe)

UPDATE
Sub DebugNUnit() 
DTE.ExecuteCommand("Tools.ExternalCommand6") 
'need a short delay for nunit process to appear in process list: 
Threading.Thread.Sleep(200) 

Try 

    Dim dbg2 As EnvDTE80.Debugger2 = DTE.Debugger 

    Dim trans As EnvDTE80.Transport = dbg2.Transports.Item("Default") 

    Dim dbgeng(1) As EnvDTE80.Engine 

    dbgeng(0) = trans.Engines.Item("Managed (v4.0)") 

    Dim proc2 As EnvDTE80.Process2 = dbg2.GetProcesses(trans, "myPC").Item("nunit.exe") 

    proc2.Attach2(dbgeng) 

Catch ex As System.Exception 

    MsgBox(ex.Message) 

End Try 
End Sub 

:이

Sub DebugNUnit() 
    DTE.ExecuteCommand("Tools.ExternalCommand6") 
    'need a short delay for nunit process to appear in process list: 
    Threading.Thread.Sleep(200) 

    Try 

     Dim dbg2 As EnvDTE80.Debugger2 = DTE.Debugger 

     Dim trans As EnvDTE80.Transport = dbg2.Transports.Item("Default") 

     Dim dbgeng(1) As EnvDTE80.Engine 

     dbgeng(0) = trans.Engines.Item("Managed (v4.0)") 

     Dim proc2 As EnvDTE80.Process2 = dbg2.GetProcesses(trans, "myPC").Item("nunit.exe") 

     proc2.Attach2(dbgeng) 

     'added this because we may need a short delay for nunit gui to load 
     '(would prefer to replace it with a wait on some loaded event or something) 
     Threading.Thread.Sleep(5000) 

     'use Process.Handle or Process.MainWindowHandle? anyway, both do not seem to work.. are the parameters incorrect? 
     Dim ButtonHandle As IntPtr = FindWindowEx(System.Diagnostics.Process.GetProcessById(proc2.ProcessID).Handle, 0, "Button", "Run") 
     'Dim ButtonHandle As IntPtr = FindWindowEx(System.Diagnostics.Process.GetProcessById(proc2.ProcessID).MainWindowHandle, 0, "Button", "Run") 

     SendMessage(ButtonHandle, &HF5, 0, 0) 

    Catch ex As System.Exception 

     MsgBox(ex.Message) 

    End Try 

End Sub 

같은 대답하지만 출시 된 NUNIT 사용자 인터페이스에 "실행"버튼을 (를 기반으로 스크립트를 조정 한 Tools.ExternalCommand6에 의해) 여전히 눌러지지 않습니다. 그 버튼 핸들은 항상 0 인 것처럼 보이기 때문에 이해가됩니다. 왜? 해결책이있는 사람이 있습니까?

업데이트 : 난 당신이 NUNIT 에이전트에 연결해야 작동하는 내가 NUNIT 2.5.7을 사용하고이

Option Strict Off 
Option Explicit Off 
Imports System 
Imports EnvDTE 
Imports EnvDTE80 
Imports EnvDTE90 
Imports EnvDTE90a 
Imports EnvDTE100 
Imports System.Diagnostics 
Imports System.Runtime.InteropServices 
Imports System.Windows.Forms 

Public Module RecordingModule 

<DllImport("user32.dll", SetLastError:=True, CharSet:=CharSet.Auto)> _ 
    Private Function PostMessage(ByVal hWnd As IntPtr, ByVal Msg As UInteger, ByVal wParam As IntPtr, ByVal lParam As IntPtr) As Boolean 
End Function 

Sub DebugNUnit() 
    DTE.ExecuteCommand("Tools.ExternalCommand6") 
    'need a short delay for nunit processes to appear in process list: 
    Threading.Thread.Sleep(1000) 

    Try 

     Dim dbg2 As EnvDTE80.Debugger2 = DTE.Debugger 
     Dim trans As EnvDTE80.Transport = dbg2.Transports.Item("Default") 
     Dim dbgeng(1) As EnvDTE80.Engine 
     dbgeng(0) = trans.Engines.Item("Managed (v4.0)") 
     Dim proc2nunitagent As EnvDTE80.Process2 = dbg2.GetProcesses(trans, Environment.MachineName).Item("nunit-agent.exe") 
     Dim proc2nunit As EnvDTE80.Process2 = dbg2.GetProcesses(trans, Environment.MachineName).Item("nunit.exe") 
     proc2nunitagent.Attach2(dbgeng) 

     PostMessage(System.Diagnostics.Process.GetProcessById(proc2nunit.ProcessID).MainWindowHandle, &H100, Keys.Alt Or Keys.R, IntPtr.Zero) 

    Catch ex As System.Exception 

     MsgBox(ex.Message + Environment.NewLine + ex.StackTrace) 

    End Try 

End Sub 
End Module 

같은 편집 대답과 부착 및 디버깅을위한 기반 스크립트를 조정하고있다 nunit gui를 실행하십시오. 최신 버전의 nunit에 대해서는 nunit gui에 첨부 할 수 있습니다.

위의 스크립트는 Visual Studio IDE와 nunit 바이너리만으로 nunit 디버깅을 활성화합니다. nunit을 외부 도구 (현재 프로젝트를 매개 변수로 사용)로 설정하고, 사용자 정의 도구 모음을 만들고, 위 스크립트를 사용하는 단추를 해당 도구 모음에 추가하기 만하면됩니다. 이것은 nunit을 시작하고, 그것에 접속하고, 테스트 실행을 시작하고, 중단 점에서 중단합니다.

한 가지 더 : nunit gui에서 도구 -> 설정 -> 트리 디스플레이의 "각 프로젝트의 시각적 상태 저장"을 비활성화하거나 nunit gui가 마지막 실행 테스트를 기억합니다. 당신은 디버그를 원했습니다.

가능한 개선 사항 : nunit을 시작하기 전에 빌드하십시오.

+0

단원 테스트를 디버그하려는 경우 TestDriven.NET 또는 ReSharper와 같은 것을 얻는 것이 좋습니다. 둘 다 Visual Studio 내에서 테스트를 쉽게 디버깅 할 수 있습니다. –

+0

필자는 이러한 도구에 익숙하지만 프리웨어가 아니며 VisualNUnit과 같은 프리웨어 도구가 충분히 신뢰할 수 없습니다. 게다가, 나는 거의 다 왔어. 지금 내가 필요로하는 것은 버튼 핸들이다. 그리고 나는 현재 프로젝트를 위해 NUnit을 시작하고, 붙이고, 테스트를 실행하고, 브레이크 포인트를 중단하는 버튼이있는 자신의 커스텀 툴바를 가지고있다. – mtijn

+0

Visual NUnit은 프리웨어와 달리 오픈 소스입니다. 너는 항상 그것을 고칠 수 ... ...? –

답변

4

이 시도 :

<DllImport("user32.dll", SetLastError:=True, CharSet:=CharSet.Auto)> 
Private Shared Function SendMessage(ByVal hWnd As IntPtr, ByVal Msg As UInteger, ByVal wParam As IntPtr, ByVal lParam As IntPtr) As IntPtr 
End Function 
<DllImport("user32.dll", SetLastError:=True, CharSet:=CharSet.Auto)> 
Private Shared Function FindWindowEx(ByVal parentHandle As IntPtr, ByVal childAfter As IntPtr, ByVal lclassName As String, ByVal windowTitle As String) As IntPtr 
End Function 

Dim ButtonHandle As IntPtr = FindWindowEx(YOURPROCESS.HANDLE, 0, "Button", "&Run") 
SendMessage(ButtonHandle, &HF5, 0, 0) 

편집는 : NUint 당신이 버튼을 쉽게 처리 할 얻을 수없는 의미 .NET 응용 프로그램 인 것 같다. 당신은 Spy ++의 도움으로 당신 스스로를 볼 수 있습니다.

나는 ALT + R의 키보드 단축키를 가지고 Run 버튼이 너무 대신이 코드를 사용할 수있는 것으로 나타났습니다 :

<DllImport("user32.dll", SetLastError:=True, CharSet:=CharSet.Auto)> 
Private Shared Function PostMessage(ByVal hWnd As IntPtr, ByVal Msg As UInteger, ByVal wParam As IntPtr, ByVal lParam As IntPtr) As Boolean 
End Function 
PostMessage(MAIN_WINDOW_HANDLE, &H100, Keys.Alt Or Keys.R, IntPtr.Zero) 

나는이 테스트를하고 그것을 잘 작동합니다.

+0

정말 끝내 주셔서 감사합니다! (http://chat.stackoverflow.com/rooms/6788/discussion-between-mtijn-and-roger-lipscombe)! 하지만 이제 어떻게하면 nunit.exe에 대한 프로세스 핸들을 얻을 수 있습니까? 이미 EnvDTE80.Process2 객체가 있지만 사용하지 않는 것 같습니다. – mtijn

+0

nunit.exe는 NUnit GUI 프로세스입니다. 내 질문을보고, 나는 최신 결과로 그것을 업데이 트했습니다. – mtijn

+0

정확히 내가 필요한 것을 고마워, 내가 질문에 최종 결과를 게시했습니다. – mtijn

관련 문제