android10 / frodo

Android Library for Logging RxJava Observables and Subscribers.
1.48k stars 101 forks source link

Prevent DebugLog logs messages when running code under JUnit. #30

Open VictorAlbertos opened 8 years ago

VictorAlbertos commented 8 years ago

Hi.

I've been getting the next exception when running a JUnit test which calls methods annotated with @RxLogObservable

java.lang.RuntimeException: Method d in android.util.Log not mocked. See http://g.co/androidstudio/not-mocked for details.

    at android.util.Log.d(Log.java)
    at com.fernandocejas.frodo.internal.DebugLog.log(DebugLog.java:21)
    at com.fernandocejas.frodo.internal.MessageManager.printMessage(MessageManager.java:20)
    at com.fernandocejas.frodo.internal.MessageManager.printObservableInfo(MessageManager.java:25)
    at com.fernandocejas.frodo.internal.observable.FrodoObservable.getObservable(FrodoObservable.java:28)
    at com.fernandocejas.frodo.aspect.LogObservable.weaveAroundJoinPoint(LogObservable.java:39)
    at app.data.sections.chat.ChatRepository.getChats(ChatRepository.java:30)
    at app.data.sections.chat.ChatRepositoryTest.When_Remove_Chat_Then_Remove_Chat(ChatRepositoryTest.java:29)
....

I've been able to fix the error by adding the next configuration test to gradle:

android {
    testOptions {
        unitTests.returnDefaultValues = true
    }
}

This pull request tries to fix that. I've been able to compile the project and run successfully the unit tests of "frodo-runtime" module. But it seems that DebugLog class isn't covered by any of them (probably not need for that until now).

Also, I don't know how can I test this new functionality from the android sample app. I couldn't connect the "frodo-plugin" gradle locally with the sample app. Indeed, I don't even know if that's possible (I have a very limited knowledge about gradle plugins).