BitmapAssetValueConverter - unit testing #5690
Replies: 1 comment
-
Use Avalonia.Headless platform. There is an example of integration with xUnit - https://github.com/kekekeks/Avalonia-unit-testing-with-headless-platform
Not sure how exactly you initialize Avalonia for tests, this one line it not enough to start main loop.
I doubt that it's possible to run Avalonia app on multiple UI threads (for parallel tests). Avalonia internal code expects to have only one UI thread, at least there is single static Dispatcher.UIThread. |
Beta Was this translation helpful? Give feedback.
-
Hello!
In my code, I use BitmapAssetValueConverter to set the image source dynamically, during the application runtime.
The code looks like the following (I'm leaving out exception handling for brevity):
In my .NET Core 3.1 project, I use Avalonia.Desktop and Avalonia.ReactiveUI packages.
I've got a few unit tests going through this code. But I'm not sure they are correct.
In one of the tests I put in a valid path to a PNG file and verify that the returned object is a bitmap with expected attributes.
Without any Avalonia initialization, the Bitmap constructor throws a NullReferenceException.
If I add the following code, my tests (multiple tests executing this code, running in parallel, to be precise) often work, but sometimes they fail with InvalidOperationException : Call from invalid thread
AppBuilder.Configure<App>().UsePlatformDetect().UseReactiveUI().SetupWithoutStarting();
My questions are:
Many thanks, all suggestions and ideas appreciated.
Beta Was this translation helpful? Give feedback.
All reactions