Skip to content
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

Logcat usage in classes being tested #20

Closed
StylianosGakis opened this issue Aug 4, 2023 · 3 comments
Closed

Logcat usage in classes being tested #20

StylianosGakis opened this issue Aug 4, 2023 · 3 comments

Comments

@StylianosGakis
Copy link

If a logger is not installed, it defaults to NoLog which crashes on any log command.
When inside unit tests, if the class being tested also needs to log something and does so using logcat, it means it will by default crash.
What do you usually do in such scenarios? Having to install a logger on each test (even if done by a rule) sounds quite cumbersome to me and I am not familiar with any better alternatives.

@StylianosGakis
Copy link
Author

What I have done so far is implement a TestLogcatLogger which simply prints out to System.out and created a test rule like this for my tests.

class TestLogcatLoggingRule(
  private val testLogcatLogger: LogcatLogger = TestLogcatLogger(),
) : ExternalResource(){
  override fun before() {
    LogcatLogger.install(testLogcatLogger)
  }

  override fun after() {
    LogcatLogger.uninstall()
  }
}

I suppose that's the expected thing to do here.

@spectrl
Copy link

spectrl commented Aug 28, 2024

You can also just use PrintLogger for this

@StylianosGakis
Copy link
Author

Heh I did not know this existed. This bad boy has served me well for this past year 😅
But you are right that PrintLogger is what I was looking for here, thanks! Closing this now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants