Is it possible to provide custom/wrapped method runner? #2588
-
| In Avalonia, to run headless (=lookless, console) tests we pass test body into a callback, which is executed on the dedicated thread with all the UI properties set-up. using var session = HeadlessUnitTestSession.StartNew(typeof(App)); await session.Dispatch(() => { var window = new Window(); // arrange window.Show(); // act if (!window.IsActive) throw new Exception(); // assert })This approach works well with XUnit and NUnit unit tests frameworks, allowing as to customize configuration per each test if necessary. [AvaloniaFact] public void Should_Open_Window() { var window = new Window(); // arrange window.Show(); // act Assert.True(window.IsActive); // assert }
My question is, is it possible to achieve similar in BenchmarkDotNet? It's important, that benchmarking code excludes any headless session setup time, and only measures what's inside of the callback. Meaning, we can't just put |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
| I don't think this is possible currently. Perhaps when #2589 is implemented you could start the benchmarks inside your dispatch callback. |
Beta Was this translation helpful? Give feedback.
-
| Since #2958 was merged, you can implement your own engine to wrap the default engine. public class AvaloniaEngineFactory : IEngineFactory { public IEngine Create(EngineParameters engineParameters) => new AvaloniaEngine(engineParameters); } public class AvaloniaEngine(EngineParameters engineParameters) : IEngine { public async ValueTask<RunResults> RunAsync() { using var session = HeadlessUnitTestSession.StartNew(typeof(App)); return await session.Dispatch( async () => await new EngineFactory().Create(engineParameters).RunAsync(), engineParameters.Host.CancellationToken ) } }Then pass the factory to the config job |
Beta Was this translation helpful? Give feedback.
Since #2958 was merged, you can implement your own engine to wrap the default engine.
Then pass the factory to the config job
Job.Defaul…