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

Open
StylianosGakis opened this issue Aug 4, 2023 · 1 comment
Open

Logcat usage in classes being tested #20

StylianosGakis opened this issue Aug 4, 2023 · 1 comment

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.

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

1 participant