-
Notifications
You must be signed in to change notification settings - Fork 300
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
bootstrapping in XCTestCase #77
Comments
Sounds good to me, would you have a moment PR such section into the README.md perhaps? |
But what if I want to test different LogHandlers with the LoggingSystem? Seems to be impossible for now 😢 |
So I found a workaround in Btw you can find beta of my LoggingKit here 🙂 |
@maximkrouk you can construct a logger with a backend explicitly: let logger = Logger(label: "foo") { label in
MyAwesomeBackend(label)
} see docs. |
Does this solution apply when using SwiftLog in an iOS app and its test cases? I'm finding the host app bootstraps the logging system fine, but then when loading tests I get the second bootstrapping error. I have attempted to use the lazy global variable approach above, but and finding its not protecting the bootstrapping from attempting again. |
@leisurehound could you send us the code you use with the lazy global? That should work. |
sorry, I had an unrelated config issue that was causing this, once I fixed that the tests now run without double bootstrapping the logger. Sorry for the noise. |
Thanks for looping back, closing the ticket then 👍 |
Actually, the original ticket stands as to documenting the pattern, so opening. |
LoggingSystem.bootstrap
must only be called once per process. One might assume to bootstrap the logger inXCTestCase.setUp
, but this can be called multiple times and will result in an assertion.To get around this, a global lazy variable can be used that is asserted in each
setUp
method. It will only be run once, the first time it is accessed, allowing for logging to be configured in XCTests:Declare the global variable like so:
Then, in your
XCTestCase
s, use like so:We should consider documenting this or providing some sort of helper.
The text was updated successfully, but these errors were encountered: