Open mustafaozhan opened 3 years ago
Hmm, not sure getTestLogWriter
is actually doing, is it logging something when you run the test ?
I end up writing my custom Writer
fun initLogger(
forTest: Boolean = false
) = Logger.setLogWriters(
if (forTest) {
TestWriter()
} else {
CustomWritter()
}
)
class TestWriter : LogWriter() {
override fun log(
severity: Severity,
message: String,
tag: String,
throwable: Throwable?
) {
println("${severity.name}: $tag $message ${throwable ?: ""}")
}
}
CommonWriter
is available. It looks like the test code is using LogcatWriter
in test code, which I'd guess is calling into something that robolectric or similar is providing?
Out of the box, the new version of Kermit uses the convenience function platformLogWriter()
, which will create and instance of LogcatWriter
on Android.
In test setup you should be able to just use CommonWriter
. We could maybe wrap calls in LogcatWriter
in try/catch and assume we're in tests is they throw, although I want to think about that a bit.
I also added TestLogWriter as an alternative. I haven't thought about that at all, but was doing a whole bunch of stuff today, so threw it in there as a start.
getTestLogWriter()
is internal to Kermit's tests, so you can't call that directly.
To try things out, I'm pushing 1.0.0-SNAPSHOT
now, and I would expect actual 1.0.0 soon (next few days).
Hmm. Not closing this yet. Need to dig in more.
TestWriter doesn't print anything, CommonWriter doesn't let you assert anything. We can either document how to init tests to do what you want, or we'd need to discuss code changes for default.
Currently, there is no LogWriter to use in tests In old Kermit I was using the
CommonLogger()
for test without problem, but the new Kermit (Logger) doesn't have it.It causes this issue:
Maybe we need the
getTestLogWriter()
publicly avaliable so tests will not fail due toMethod println in android.util.Log not mocked.
ie: