-
-
Notifications
You must be signed in to change notification settings - Fork 173
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
Can't use logback for Android JUnit in Android Studio? #151
Comments
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
Still unsolved |
I can not see any output in my JUnit-Tests also. I got the following exception:
Adding Any advice how to setup a correct JUnit-Test-Setup? |
@cleemansen could you provide your build.gradle and config? I'm having |
@almozavr snippet of my
My logback config is very specific. This setup "works" as described in my last comment w/ a simple |
I tried dependency substitution but gradle + android doesn't work that way 😖
|
@cleemansen I'm afraid, your solution is unreliable -> slf4j takes first "random" binding if there are multiple, it comes from their documentation, and actually I encountered it today.. |
I'm also not happy w/ that workaround. I had the same idea substituting the libraries, too. Never tried it and I don't know if this approach is worthwhile. |
@cleemansen dep. substitution works great with vanilla gradle (executed from terminal), but it seems like Android Studio uses diff classpath rules, so it simple skips configuration rules for inbound test runs 😢 |
Local unit tests that use
If you cannot use Robolectric in your project for some reason, those tests must be moved to instrumented unit tests, which run on an emulator or device. See Android docs on testing for more information. Setup:
dependencies {
testImplementation 'org.robolectric:robolectric:3.8'
}
import org.junit.runner.RunWith;
import org.robolectric.RobolectricTestRunner;
@RunWith(RobolectricTestRunner.class)
public class ExampleUnitTest { ... }
<configuration debug="true">
<appender name="console" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>%msg</pattern>
</encoder>
</appender>
<root level="DEBUG">
<appender-ref ref="console" />
</root>
</configuration>
import org.robolectric.annotation.Config;
@Config(manifest = Config.NONE)
public class ExampleUnitTest { ... } See changes in tony19-sandbox/logback-test-app@4682f5a |
@tony19 thanks for the so much detailed example! I believe it would be great to mention this sample app repo at readme or include in the main repo. Also, I consider |
That repo is currently for CI only, but I might clean it up as a general sample app.
Robolectric is supplemental to unit test frameworks, such as |
@tony19 I'm afraid, it's not that straightforward in the world of junit 4 and 5 and their runners, e.g.: Anyway, I doubt one would stick with Robolectric to run vanilla unit tests just because of the logger tool.. |
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
I had put "logback.xml" in
src\test\assets\logback.xml
src\main\assets\logback.xml
src\androidTest\assets\logback.xml
but seems it still not working
logback file below:
after some trying
add
testCompile 'ch.qos.logback:logback-classic:1.2.3'
it works but got
Class path contains multiple SLF4J bindings.
warning..The text was updated successfully, but these errors were encountered: