Skip to content

Development and Testing

Bartłomiej Dach edited this page Aug 7, 2023 · 8 revisions

All initial development of (and further improvements applied) to components in a project should be developed in the VisualTests environment. There are several advantages to doing this.

Hot Reload

Test scenes are integrated with the .NET Hot Reload mechanism. Here is an example of how this looks in practice:

hotreload.mp4

Keep in mind that the Hot Reload facility is subject to some limitations and some changes will require a full application restart. For more information, see Supported Edits in Edit & Continue (EnC).

Steps and automated testing

You can use the AddStep function to add automatic steps which should be performed. Asserts can also be added as steps. These steps can be run in an interactive environment by the user, but also run in a headless execution, allowing for CI process testing.

The types of steps available to be added are as follows:

  • AddStep() creates a step that runs a method. Completes successfully if no exceptions are caught.
  • AddRepeatStep() creates a step that runs a method a specified amount of times. Completes successfully if no exceptions are caught.
  • AddToggleStep() toggles a flag.
  • AddWaitStep() adds a step that waits a specified amount of time before continuing to the next step.
  • AddSliderStep() adds a step that creates a slider-bar that adjusts a set value.
  • AddAssert() creates a step that fails if the specified value does not return true.
  • AddUntilStep() adds a step that attempts to run until a condition becomes true, or fails when it times out.

Both AddAssert() and AddUntilStep() support the NUnit assertion constraint model, i.e.:

AddAssert("no text is selected", () => textBox.SelectedText, () => Is.Empty);

Using this style is highly recommended as the NUnit matchers provide vastly improved debugging output in case of failure compared to just plain true/false assertions.

Caveats

  • Hot reload has no effect if the application is started with a debugger attached. Attempting to attach debugger after launching and applying changes via hot reload will fail with error 0x80131c69 (CORDBG_E_ASSEMBLY_UPDATES_APPLIED).
  • If the debugger is attached, UntilSteps will never time out. This is a convenience feature to improve debugging of the failing condition in the until step.
Clone this wiki locally