VerifyTests / Verify.Avalonia

Extends Verify to allow verification of Avalonia UIs
MIT License
33 stars 1 forks source link

Can we detect common setup mistakes? #216

Closed JayBazuzi closed 1 month ago

JayBazuzi commented 1 month ago

The setup process for using Verify.Avalonia isn't obvious, and when the user gets it wrong it's hard to diagnose. Can Verify.Avalonia provide better help messages?

AvaloniaFact

If I write [Fact] instead of [AvaloniaFact], my test fails with this error:

  Error Message:
   System.InvalidOperationException : Unable to locate 'Avalonia.Platform.IWindowingPlatform'.
  Stack Trace:
     at Avalonia.LocatorExtensions.GetRequiredService[T](IAvaloniaDependencyResolver resolver)
   at Avalonia.Controls.Platform.PlatformManager.CreateWindow()
   at Avalonia.Controls.Window..ctor()
   at TestableApp.RecursiveWindow..ctor() in /Users/jaybazuzi/source/Verify.Avalonia/src/TestableApp/RecursiveWindow.axaml.cs:line 7
   at Tests.Recursive() in /Users/jaybazuzi/source/Verify.Avalonia/src/XUnitTests/Tests.cs:line 6
   at System.RuntimeMethodHandle.InvokeMethod(Object target, Void** arguments, Signature sig, Boolean isConstructor)
   at System.Reflection.MethodBaseInvoker.InvokeWithNoArgs(Object obj, BindingFlags invokeAttr)

Styles

If I forget Styles.Add(new FluentTheme()) my test fails with this error:

  Error Message:
   System.Exception : No RenderedFrame
  Stack Trace:
     at Extensions.ToImage(TopLevel topLevel) in /Users/jaybazuzi/source/Verify.Avalonia/src/Verify.Avalonia/Extensions.cs:line 9
   at VerifyTests.VerifyAvalonia.WindowToImage(Window window, IReadOnlyDictionary`2 context) in /Users/jaybazuzi/source/Verify.Avalonia/src/Verify.Avalonia/VerifyAvalonia.cs:line 25
   at VerifyTests.VerifierSettings.<>c__DisplayClass165_0`1.<RegisterFileConverter>b__0(T o, IReadOnlyDictionary`2 context) in /_/src/Verify/Splitters/Settings_Typed.cs:line 29
   at VerifyTests.VerifierSettings.<>c__DisplayClass166_0`1.<RegisterFileConverter>b__0(Object o, IReadOnlyDictionary`2 context) in /_/src/Verify/Splitters/Settings_Typed.cs:line 38
   at VerifyTests.InnerVerifier.Verify(Object target) in /_/src/Verify/Verifier/InnerVerifier_Object.cs:line 67
   at VerifyXunit.Verifier.<>c__DisplayClass9_0.<<Verify>b__0>d.MoveNext() in /_/src/Verify.Xunit/Verifier.cs:line 76
SimonCropp commented 1 month ago

I think both of these should be considered part of Avalonia. so u could get the same errors even if u were not using Verify. so i agree it should give a better error, but that should be a change in the Avalonia code base

SimonCropp commented 1 month ago

let me expand on that a bit. the point of Avalonia.Headless.NUnit and Avalonia.Headless.XUnit is to enabling rendering for the purposes of tests. if people are using the wrong setup in such a way that is it not possible to render, then Avalonia should, if possible, communicate what is wrong with that setup

JayBazuzi commented 1 month ago

Ok, that makes sense.