Extend documentation and samples
Based on #156, the documentation could be expanded (and the samples extended) to show usage of the logger with a test fixture, rather than just in a standalone test.
Also consider an example that supports parallel execution of tests without bleeding the logger between them.
to show usage of the logger with a test fixture
I'd be super interested in this.
Usually, I set up a collection fixture where the service collection / test server is created once, then all test classes use that same instance to run tests.
My understanding is that ITestOutputHelper is only injectable in test classes constructors, and I don't think we can "inject" loggers after the service provider is built.
Am I missing something?
That's correct, but it's possible to still use it with a shared fixture with the use of the ITestOutputHelperAccessor interface and a bit of boilerplate in a base class. This just isn't explicitly spelled out in the docs here yet 😃.
From an example in one of my own projects.
- The shared fixture implements
ITestOutputHelperand provides a mechanism to set and clear theITestOutputHelper. - A base class for the tests sets and clears the output helper.
- Individual test classes pass through the output helper to the base class.
xunit then does the rest of the heavy lifting for you. The only downside (which is inherent to how xunit works) is that you can't have multiple tests running in parallel with the same fixture, as they'll otherwise be fighting over the current output helper. Maybe you could wrap it and have multiple helpers and cycle them based on the current thread/fixture or something and delegate it via a reference to overcome that, but it's not something I've tried.
Very clean implementation, I like it a lot.
I usually have base classes as well to reset the database between each test.
Thanks heaps!
Is there a way to set the log level? Looks like it is set to information by default and I’m missing the debug and trace output.
Thank you, Martin
All levels except None are logged by default unless you provide a custom Filter method:
https://github.com/martincostello/xunit-logging/blob/f01740ba004a37ffe1a9c94341c6383ff57689a3/src/Logging.XUnit/XUnitLogger.cs#L103-L111
My guess would be your application is configured to not log whatever you're looking for at Debug or Trace.