- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我已经为我录制了这个附加到进程 (nunit.exe) 的宏。现在我想在我附加到的进程的窗口上按下一个按钮(名为“运行”),但是如何呢?我录制了这个宏:
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
但是(通过 Tools.ExternalCommand6)启动的 nunit 用户界面上的“运行”按钮仍然没有被按下。这是有道理的,因为按钮句柄似乎总是 0.. 为什么?有没有人有解决方案?
更新:我已经根据这样编辑过的答案调整了脚本
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 2.5.7,为了连接和调试工作,您需要连接到 nunit 代理并在 nunit gui 上按运行,对于更新版本的 nunit,您可以连接到 nunit gui。
以上脚本仅使用 Visual Studio 和 nunit 二进制文件即可从 Visual Studio IDE 进行 nunit 调试。您需要做的就是将 nunit 设置为外部工具(将当前项目作为参数),创建自定义工具栏,并向使用上述脚本的工具栏添加一个按钮。这将启动 nunit,附加到它,开始运行测试,并在您的断点处中断。
还有一件事:在 nunit gui 中,在工具 -> 设置 -> 树显示中禁用“保存每个项目的视觉状态”,否则 nunit gui 会记住上次运行的测试,如果那不是你的测试,那会很痛苦想调试。
可能的改进:在启动 nunit 之前构建。
最佳答案
试试这个:
<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++ 的帮助下亲眼看到这一点。
我注意到按钮 Run
有一个键盘快捷键 ALT + R
所以你可以使用这个代码:
<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)
我测试了这个,它工作正常。
关于c# - 如何在不同的进程上按下按钮 (nunit.exe),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8853801/
使用捆绑的 NUnit 工具配置了 NUnit 步骤,如下所示: 执行步骤后,我在日志开头出现以下消息时遇到困难: The TeamCity NUnit runner requires the fol
是否可以定义自定义过滤器,以便 NUnit 仅运行特定测试?我的许多 Nunit 测试都标有自定义属性“BugId”。是否可以编写一个过滤器,以便我可以传入一个数字并仅使用该属性和数字运行测试?如果是
已结束。此问题正在寻求书籍、工具、软件库等的推荐。它不满足Stack Overflow guidelines 。目前不接受答案。 我们不允许提出寻求书籍、工具、软件库等推荐的问题。您可以编辑问题,以便
我想使用 NUnit 来运行 GUI/集成测试。我想做的是在所有测试之前初始化一些自定义报告(来 self 们使用的 GUI 测试框架),并在整个套件运行后运行报告导出。 是否有一些“ super ”
我需要从不同的单元调用测试以在我当前的单元中使用(我指的单元是类)。 NUnit 是否有基础设施可以做到这一点,还是我应该继续做我正在做的事情?实例化类并调用方法? 谢谢! 最佳答案 如果我没理解错的
我将 NUnit 与 CruiseControl.NET 一起使用。我有很多测试项目和程序集。当我运行测试时,在 NUnit 详细信息页面上,它只显示一个程序集,但包含来自所有程序集的所有测试。在日志
我有 13 个独立但相关的架构程序集,以及 13 个独立的 NUnit 测试程序集,每个测试程序集都包含与其匹配的架构程序集的所有测试装置。我正在使用 NUnit 2.5.2(当前最新版本)。 我可以
我可以强制每个 nunit 测试方法在单独的进程上运行吗?我需要这样做,因为调用一些被测方法可能会产生副作用。因此,我需要确保每个单元测试都与其他单元测试完全隔离运行。 最佳答案 您可以使用“/pro
我想在它们运行之前报告它们,并且可以选择通过 shell 脚本运行单个测试而无需管理类别。我们有一些非托管代码可能会使进程处于不良状态,有时很乐意在每次 nunit-console 运行时单独运行每个
我有一些初始化代码来使用我的 API。初始化可能会失败,我想在 NUnit 测试中对其进行测试。 初始化之后,可以使用 API。我也在测试 API,但我所有的测试方法都将使用相同的通用初始化代码。 我
就目前而言,这个问题不适合我们的问答形式。我们希望答案得到事实、引用资料或专业知识的支持,但这个问题可能会引发辩论、争论、投票或扩展讨论。如果您觉得这个问题可以改进并可能重新打开,visit the
我已将我的测试配置为在发生故障时最多重试 x 次,以确保故障是合法的,而不是运行期间的侥幸。我没有在初始失败时记录错误消息。 但是,我注意到如果我正在运行测试,第一个测试会失败,然后第二个测试会通过,
由于不清楚的原因,我的 Nunit 测试装置不能在一次运行中执行,所以我被迫在单独的运行中执行一些测试。然而,这意味着测试结果被拆分到多个输出文件中。 是否有可以将 NUnit 结果 XML 文件合并
我创建了一个 NUnit 理论来帮助我测试一些代码。被测试的实际代码对于这个问题并不像我用来测试它的数据那么重要。即,24 小时制中的小时和分钟。 我以这种方式编写我的装置是为了利用这些特性并符合 N
如果我有以下代码: [TestFixture] public class MyBaseTest { protected ISessionManager _sessionManager;
我有一组单元测试,我需要从一个命令行调用中运行它们。其中一个程序集使用与其余程序集不同的配置文件。有没有办法在一个 nunit 项目文件中指定多个应用程序配置文件? 最佳答案 不在项目文件中,但您可以
我已经成功地为 TeamCity 服务器上的每个构建运行了 MSTest。 我有几个使用 NUnit 的项目,所以希望让 TeamCity 运行 NUnit 测试就像运行 MSTests 一样简单:
当我的夜间构建完成时,我会自动运行一些 NUnit 测试。我有一个控制台应用程序检测新构建,然后将构建的 MSI 复制到本地文件夹,并将我的所有组件部署到测试服务器。之后,我在 NUnit dll 中
有没有办法从 TeamCity 的“测试”选项卡中生成 NUnit 测试的可视化结果,目前我的 NAnt 脚本使用以下任务输出结果的 .xml 文件: TIA 最佳答案 可以使用 Te
我们使用 NUnit 来执行集成测试。这些测试非常耗时。通常,检测故障的唯一方法是超时。 我希望一旦检测到单个故障就停止执行测试。 有没有办法做到这一点? 最佳答案 使用 nunit-console,
我是一名优秀的程序员,十分优秀!