Extends Verify to allow verification of WinForms UIs.
See Milestones for release notes.
Entity Framework Extensions is a major sponsor and is proud to contribute to the development this project.
[ModuleInitializer]
public static void Init() =>
VerifyWinForms.Initialize();A visual element (Form/Control etc) can be verified as follows:
[Test]
public Task FormUsage() =>
Verify(new MyForm());With the state of the element being rendered as a verified file:
TheTests.FormUsage.DotNet.verified.png:
A Form is shown as the top-level window it is, but off screen and without being activated (so it does not take the focus), and messages are pumped once. So it is laid out, scaled and drawn as it appears on screen, and its Load and Shown handlers have run. A form that has already been shown is rendered where it is. Either way it is then disposed, without being closed.
Any ToolStripDropDown can be verified: a ContextMenuStrip, the DropDown of a ToolStripMenuItem or ToolStripDropDownButton, or a plain ToolStripDropDown. It is shown as the popup window it is, but off screen, so it is laid out and drawn (renderer, margins, border) as it appears on screen. It is then closed and disposed.
A ContextMenuStrip can be verified as follows:
[Test]
public Task ContextMenuStrip()
{
var menu = new ContextMenuStrip();
var items = menu.Items;
items.Add(new ToolStripMenuItem("About"));
items.Add(new ToolStripMenuItem("Exit"));
return Verify(menu);
}With the state of the element being rendered as a verified file:
TheTests.ContextMenuStrip.DotNet.verified.png:
The menu of a ToolStripDropDownButton (or of a ToolStripMenuItem) can be verified via its DropDown:
[Test]
public Task ToolStripDropDownMenu()
{
var button = new ToolStripDropDownButton("File");
var items = button.DropDownItems;
items.Add(new ToolStripMenuItem("New"));
items.Add(
new ToolStripMenuItem("Word Wrap")
{
Checked = true
});
items.Add(new ToolStripSeparator());
items.Add(new ToolStripMenuItem("Exit"));
return Verify(button.DropDown);
}With the state of the element being rendered as a verified file:
TheTests.ToolStripDropDownMenu.DotNet.verified.png:
Whatever is verified (a Form, a ToolStripDropDown, a UserControl, or any other Control) is disposed once it has been rendered. So there is no need to dispose it in the test, and it cannot be used, or verified, again after the Verify call. A form is disposed without being closed, so its FormClosing and FormClosed events are not raised.
The rendering of Form elements can very slightly between different OS versions. This can make verification on different machines (eg CI) problematic. There are several approaches to mitigate this:
- Using a custom comparer
Gem designed by Adnen Kadri from The Noun Project.




