-
-
Notifications
You must be signed in to change notification settings - Fork 3
Configuration
You can customize some behaviours from the Xamarin.Forms.TestingLibrary, most of it is accessed by the static TestingLibraryOptions
. So in order to customize you simply set its values. These are the available options at the moment.
In order to correctly show the debugging information, a tree is built with all the elements relevant properties and its children. You can customize how the tree is formatted.
You may provide a ITreeFormatter implementation. Accessible through TestingLibraryOptions.DebugOptions.TreeFormatter
.
The default formatter uses Spectre.Console's project to print the tree. You can see its implementation here.
You can specify where the debug text is printed to. By default it will be printed to the Console.Out
, so the test runner show should it in the test panel if you are running the tests in any IDE, and of course, in the console if you are running through the command line.
You may provide a TextWriter implementation. Accessible through TestingLibraryOptions.DebugOptions.OutputTextWriter
.
To decrease the number of "visual noise" in the debug tree, you can filter some properties from the printed text.
By default, Xamarin.Forms.TestingLibrary only shows these properties to provide a debug tree with the most relevant properties that you might want to see:
- Properties that have the
BindableContextAttribute.IsManuallySet
- Properties that have the
BindableContextAttribute.IsSetFromStyle
- Properties that have the
BindableContextAttribute.None
(some important properties that are initialized by the framework have this flag) - Properties that are not named
Renderer
orNavigation
.
You may provide your own filter by setting the TestingLibraryOptions.DebugOptions.DefaultPrintablePropertyFilter
. You can see the default option here.
Xamarin.Forms.TestingLibrary formats some properties to make it more readable, instead of printing the properties ToString()
, which could lead indistinguishable properties, we provide some default formatters:
- ThicknessValueFormatter
- ColorValueFormatter
- LayoutOptionsValueFormatter
- StringValueFormatter
- EnumerableValueFormatter
- DefaultValueFormatter
The formatter looks for the first formatter able to format the given property, so the order matters. That's why the DefaultValueFormatter
is registered last, it simply calls ToString
when no other formatter was able to respond.
If you want to provide extra formatters, you can just add new formatters to the start of the list. If for some reason you need to add formatter in a specific order, you can also replace the provided formatters altogether, so you can build your own list. This can be achieved by setting the TestingLibraryOptions.DebugOptions.DefaultValueFormatter
property.
The formatter architecture was based on FluentAssertions' Formatters.