-
-
Notifications
You must be signed in to change notification settings - Fork 12
Unit Testing
Tom Laird-McConnell edited this page Dec 19, 2024
·
2 revisions
The Consolonia.NUnit
package provides scaffolding for writing unit tests against your UI. It does this by giving you the ability to load the application into a dummy console, send keystrokes to it and then validate that the output matches your expectations.
To do this you derive your test class from UnitTestConsole
and then write unit tests using the .KeyInput()
and .AssertHasText()
methods.
The KeyInput() method allows you to send one or more simulated key strokes to the application.
The AssertHasText() method gives you the ability to send 1..N regular expressions which will be evaluated against the text of a snapshot of the simulated console screen.
[TestFixture]
public class MyTests: UnitTestConsole
{
[Test]
public async Task Test1()
{
await UITest.KeyInput(Key.Tab);
await UITest.AssertHasText("Arch", "Leaf");
await UITest.KeyInput(Key.Right);
await UITest.AssertHasText("Arch", "Leaf", "This is the second page");
}
}