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

Shouldn't this be in the test source tree? #1

Open
MikeWallaceDev opened this issue Sep 1, 2016 · 1 comment
Open

Shouldn't this be in the test source tree? #1

MikeWallaceDev opened this issue Sep 1, 2016 · 1 comment

Comments

@MikeWallaceDev
Copy link

Hi,
I'm trying to use your mock (thank you for that) but
a) I can't get it to work :D
b) I'm wondering if this class should be located in /src/test/java/android/util instead of /src/main/java/android/util? The reason being I believe that currently it would be included in the APK and not just in the test. Thoughts?

-MIke

@programingjd
Copy link
Owner

Here is the main reason that I can see for using this mock of the android Log.

You have some code that could be used on the jvm and not just on android, so you want to remove all the android dependencies.

This is useful if you want to use the library with a jvm project, but also if you want to have simple junit tests that do not run within an android environment and therefore run much faster.

Here's how I am structuring my code for this (using gradle).

  1. Move all the non-android specific code to a regular java library (module), and add the mock as a provided dependency of that library, and also as a testCompile dependency of the library.
  2. For an android app that is going to use the code, I use the library as is, there's no need to include any other dependency. The mock code will not end up in the apk.
  3. For regular jvm code (it could be a jvm app, another non-android specific java library or junit tests), I use the library and I also add the dependency on the mock with the compile scope (or testCompile for unit tests).

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