{"id":18937508,"url":"https://github.com/verifytests/verify.avalonia","last_synced_at":"2025-04-15T18:32:12.892Z","repository":{"id":189260374,"uuid":"680351341","full_name":"VerifyTests/Verify.Avalonia","owner":"VerifyTests","description":"Extends Verify to allow verification of Avalonia UIs","archived":false,"fork":false,"pushed_at":"2025-04-12T12:12:10.000Z","size":1046,"stargazers_count":35,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-04-12T13:26:43.371Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/VerifyTests.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"license.txt","code_of_conduct":"code_of_conduct.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":"VerifyTests"}},"created_at":"2023-08-19T01:16:34.000Z","updated_at":"2025-04-12T12:09:38.000Z","dependencies_parsed_at":"2024-02-17T06:25:11.990Z","dependency_job_id":"83c2c2f1-2adb-4869-a647-f8776b2af216","html_url":"https://github.com/VerifyTests/Verify.Avalonia","commit_stats":null,"previous_names":["verifytests/verify.avalonia"],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/VerifyTests%2FVerify.Avalonia","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/VerifyTests%2FVerify.Avalonia/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/VerifyTests%2FVerify.Avalonia/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/VerifyTests%2FVerify.Avalonia/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/VerifyTests","download_url":"https://codeload.github.com/VerifyTests/Verify.Avalonia/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248573844,"owners_count":21126914,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-08T12:11:31.037Z","updated_at":"2025-04-15T18:32:07.880Z","avatar_url":"https://github.com/VerifyTests.png","language":"C#","funding_links":["https://github.com/sponsors/VerifyTests"],"categories":[],"sub_categories":[],"readme":"# \u003cimg src=\"/src/icon.png\" height=\"30px\"\u003e Verify.Avalonia\n\n[![Discussions](https://img.shields.io/badge/Verify-Discussions-yellow?svg=true\u0026label=)](https://github.com/orgs/VerifyTests/discussions)\n[![Build status](https://ci.appveyor.com/api/projects/status/5ywtfx5oc257d4tr?svg=true)](https://ci.appveyor.com/project/SimonCropp/verify-avalonia)\n[![NuGet Status](https://img.shields.io/nuget/v/Verify.Avalonia.svg)](https://www.nuget.org/packages/Verify.Avalonia/)\n\nExtends [Verify](https://github.com/VerifyTests/Verify) to allow verification of [Avalonia UIs](https://avaloniaui.net/).\n\n## Getting Started\n\nThe test project needs a `ModuleInitializer` and an Avalonia application with a `Style`.\n\n\u003c!-- snippet: src/StandaloneExampleTest.XUnit/VerifyAvaloniaSetupApplication.cs --\u003e\n\u003ca id='snippet-src/StandaloneExampleTest.XUnit/VerifyAvaloniaSetupApplication.cs'\u003e\u003c/a\u003e\n```cs\n[assembly: AvaloniaTestApplication(typeof(VerifyAvaloniaSetupApplication))]\n\npublic class VerifyAvaloniaSetupApplication : Application\n{\n    [ModuleInitializer]\n    public static void Init()\n    {\n        VerifyImageMagick.RegisterComparers(.24);\n        VerifierSettings.InitializePlugins();\n    }\n\n    public static AppBuilder BuildAvaloniaApp() =\u003e\n        AppBuilder\n            .Configure\u003cVerifyAvaloniaSetupApplication\u003e()\n            .UseSkia()\n            .UseHeadless(\n                new()\n                {\n                    UseHeadlessDrawing = false\n                });\n\n    public VerifyAvaloniaSetupApplication() =\u003e\n        Styles.Add(new FluentTheme());\n}\n```\n\u003csup\u003e\u003ca href='/src/StandaloneExampleTest.XUnit/VerifyAvaloniaSetupApplication.cs#L1-L24' title='Snippet source file'\u003esnippet source\u003c/a\u003e | \u003ca href='#snippet-src/StandaloneExampleTest.XUnit/VerifyAvaloniaSetupApplication.cs' title='Start of snippet'\u003eanchor\u003c/a\u003e\u003c/sup\u003e\n\u003c!-- endSnippet --\u003e\n\nAnd add the following NuGet packages:\n\n  - https://nuget.org/packages/Verify.Avalonia/\n  - https://nuget.org/packages/Avalonia.Headless.XUnit/\n  - https://nuget.org/packages/Avalonia.Themes.Fluent/\n  - https://nuget.org/packages/Avalonia.Skia/\n\n\n## More details\n\n**See [Milestones](../../milestones?state=closed) for release notes.**\n\n**Currently only supported in XUnit since [AvaloniaTestAttribute results in incorrect TestContext.Test.MethodName in NUnit](https://github.com/AvaloniaUI/Avalonia/issues/12590)**\n\nLeverages [Avalonia Headless Testing](https://docs.avaloniaui.net/docs/next/concepts/headless).\n\nSee [Headless Testing with XUnit](https://docs.avaloniaui.net/docs/next/concepts/headless/headless-xunit) and [Headless Testing with NUnit](https://docs.avaloniaui.net/docs/next/concepts/headless/headless-nunit) for more information.\n\n\n### ModuleInitializer\n\n\u003c!-- snippet: Enable --\u003e\n\u003ca id='snippet-Enable'\u003e\u003c/a\u003e\n```cs\n[ModuleInitializer]\npublic static void Init()\n{\n    VerifyImageMagick.RegisterComparers(.097);\n    VerifyAvalonia.Initialize();\n}\n```\n\u003csup\u003e\u003ca href='/src/NUnitTests/ModuleInit.cs#L3-L12' title='Snippet source file'\u003esnippet source\u003c/a\u003e | \u003ca href='#snippet-Enable' title='Start of snippet'\u003eanchor\u003c/a\u003e\u003c/sup\u003e\n\u003c!-- endSnippet --\u003e\n\nThis sample uses [Verify.ImageMagick](https://github.com/VerifyTests/Verify.ImageMagick) to ignore small rendering differences that are expected between different operating systems.\n\nOther [comparers](https://github.com/VerifyTests/Verify/blob/main/docs/comparer.md) options: \n\n * https://github.com/VerifyTests/Verify.ImageHash\n * https://github.com/VerifyTests/Verify.ImageMagick\n * https://github.com/VerifyTests/Verify.Phash\n * https://github.com/VerifyTests/Verify.ImageSharp.Compare\n\n\n### Verify.CommunityToolkit.Mvvm\n\nMany Avalonia projects use [CommunityToolkit.Mvvm](https://learn.microsoft.com/en-us/dotnet/communitytoolkit/mvvm/). To ensure proper serialization of MVVM commands, use [Verify.CommunityToolkit.Mvvm](https://github.com/VerifyTests/Verify.CommunityToolkit.Mvvm).\n\n\n### InternalsVisibleTo\n\nEnsure tests projects have InternalsVisibleTo configured in the target app so tests can use generated controls by name.\n\n\u003c!-- snippet: InternalsVisibleTo --\u003e\n\u003ca id='snippet-InternalsVisibleTo'\u003e\u003c/a\u003e\n```csproj\n\u003cItemGroup\u003e\n  \u003cInternalsVisibleTo Include=\"NUnitTests\" /\u003e\n  \u003cInternalsVisibleTo Include=\"XUnitTests\" /\u003e\n\u003c/ItemGroup\u003e\n```\n\u003csup\u003e\u003ca href='/src/TestableApp/TestableApp.csproj#L19-L24' title='Snippet source file'\u003esnippet source\u003c/a\u003e | \u003ca href='#snippet-InternalsVisibleTo' title='Start of snippet'\u003eanchor\u003c/a\u003e\u003c/sup\u003e\n\u003c!-- endSnippet --\u003e\n\n\n### Initialize AvaloniaTestApplication\n\nThe `[AvaloniaTestApplication]` attribute wires the tests in the current project with the specific application. It needs to be defined once per project in any file. Verify.Avalonia requires that `UseHeadlessDrawing` is disabled and `.UseSkia()` is set.\n\n\u003c!-- snippet: src/XUnitTests/TestAppBuilder.cs --\u003e\n\u003ca id='snippet-src/XUnitTests/TestAppBuilder.cs'\u003e\u003c/a\u003e\n```cs\n[assembly: AvaloniaTestApplication(typeof(TestAppBuilder))]\n\npublic static class TestAppBuilder\n{\n    public static AppBuilder BuildAvaloniaApp() =\u003e\n        AppBuilder.Configure\u003cApp\u003e()\n            .UseSkia()\n            .UseHeadless(\n                new()\n                {\n                    UseHeadlessDrawing = false\n                });\n}\n```\n\u003csup\u003e\u003ca href='/src/XUnitTests/TestAppBuilder.cs#L1-L13' title='Snippet source file'\u003esnippet source\u003c/a\u003e | \u003ca href='#snippet-src/XUnitTests/TestAppBuilder.cs' title='Start of snippet'\u003eanchor\u003c/a\u003e\u003c/sup\u003e\n\u003c!-- endSnippet --\u003e\n\n\n### Test\n\n\u003c!-- snippet: XunitTests/CalculatorTests.cs --\u003e\n\u003ca id='snippet-XunitTests/CalculatorTests.cs'\u003e\u003c/a\u003e\n```cs\n[SuppressMessage(\"Performance\", \"CA1822:Mark members as static\")]\npublic class CalculatorTests\n{\n    [AvaloniaFact]\n    public Task Should_Add_Numbers()\n    {\n        var window = new MainWindow\n        {\n            DataContext = new MainWindowViewModel()\n        };\n\n        window.Show();\n\n        // Set values to the input boxes\n        window.FirstOperandInput.Text = \"10\";\n        window.SecondOperandInput.Text = \"20\";\n\n        // Raise click event on the button:\n        window.AddButton.Focus();\n        window.KeyPressQwerty(PhysicalKey.Enter, RawInputModifiers.None);\n\n        Assert.Equal(\"30\", window.ResultBox.Text);\n        return Verify(window);\n    }\n}\n```\n\u003csup\u003e\u003ca href='/src/XUnitTests/CalculatorTests.cs#L1-L25' title='Snippet source file'\u003esnippet source\u003c/a\u003e | \u003ca href='#snippet-XunitTests/CalculatorTests.cs' title='Start of snippet'\u003eanchor\u003c/a\u003e\u003c/sup\u003e\n\u003c!-- endSnippet --\u003e\n\n\n### Result in the following snapshots\n\n\n#### Image\n\n[Should_Add_Numbers.verified.verified.png](/src/XUnitTests/CalculatorTests.Should_Add_Numbers.verified.png):\n\n\u003cimg src=\"/src/XUnitTests/CalculatorTests.Should_Add_Numbers.verified.png\" width=\"250px\"\u003e\n\n\n#### Text\n\n\u003c!-- snippet: XUnitTests/CalculatorTests.Should_Add_Numbers.verified.txt --\u003e\n\u003ca id='snippet-XUnitTests/CalculatorTests.Should_Add_Numbers.verified.txt'\u003e\u003c/a\u003e\n```txt\n{\n  Type: MainWindow,\n  SizeToContent: WidthAndHeight,\n  Title: Simple Calculator,\n  CanResize: false,\n  Content: {\n    Type: StackPanel,\n    Spacing: 10.0,\n    Width: 280.0,\n    Height: 175.0,\n    Margin: 10,\n    HorizontalAlignment: Left,\n    Children: [\n      {\n        Type: TextBox,\n        Text: 10,\n        Watermark: Operand 1,\n        Name: FirstOperandInput\n      },\n      {\n        Type: TextBox,\n        Text: 20,\n        Watermark: Operand 2,\n        Name: SecondOperandInput\n      },\n      {\n        Type: UniformGrid,\n        Columns: 4,\n        Children: [\n          {\n            Type: Button,\n            Command: MainWindowViewModel.Add(),\n            Content: +,\n            Name: AddButton\n          },\n          {\n            Type: Button,\n            Command: MainWindowViewModel.Subtract(),\n            Content: -,\n            Name: SubtractButton\n          },\n          {\n            Type: Button,\n            Command: MainWindowViewModel.Multiply(),\n            Content: *,\n            Name: MultiplyButton\n          },\n          {\n            Type: Button,\n            Command: MainWindowViewModel.Divide(),\n            Content: /,\n            Name: DivideButton\n          }\n        ]\n      },\n      {\n        Type: StackPanel,\n        Spacing: 10.0,\n        Orientation: Horizontal,\n        Children: [\n          {\n            Type: TextBlock,\n            Text: Result:\n          },\n          {\n            Type: TextBlock,\n            Text: 30,\n            Name: ResultBox\n          }\n        ]\n      }\n    ]\n  },\n  Background: LightGray,\n  Width: 300.0,\n  Height: 195.0,\n  IsVisible: true,\n  DataContext: {\n    FirstOperand: 10.0,\n    SecondOperand: 20.0,\n    Result: 30,\n    AddCommand: MainWindowViewModel.Add(),\n    SubtractCommand: MainWindowViewModel.Subtract(),\n    MultiplyCommand: MainWindowViewModel.Multiply(),\n    DivideCommand: MainWindowViewModel.Divide()\n  }\n}\n```\n\u003csup\u003e\u003ca href='/src/XUnitTests/CalculatorTests.Should_Add_Numbers.verified.txt#L1-L87' title='Snippet source file'\u003esnippet source\u003c/a\u003e | \u003ca href='#snippet-XUnitTests/CalculatorTests.Should_Add_Numbers.verified.txt' title='Start of snippet'\u003eanchor\u003c/a\u003e\u003c/sup\u003e\n\u003c!-- endSnippet --\u003e\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fverifytests%2Fverify.avalonia","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fverifytests%2Fverify.avalonia","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fverifytests%2Fverify.avalonia/lists"}