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

Espresso tests - could they be placed outside the app src folder? #2

Closed
RichardGuion opened this issue May 6, 2014 · 13 comments
Closed
Labels

Comments

@RichardGuion
Copy link
Contributor

Impressed by this sample project and how you have all 3 levels of tests working along with Jacoco. I've learned a lot by looking at your code and organization of modules.

One thing I really liked: how you put ComponentTestsRobolectric and UnitTestsRobolectric as folders on the same level as AndroidSample. You did a great job of showing how the build.gradle files in sub folders relate to the master build.gradle file and how Jacoco can point to the directory ../AndroidSample for the code coverage.

However, in AndroidSample you have the src folder with main and test subfolders; test subfolder has espresso/instrumentation tests.

Do you think it is possible to move the Instrumentation tests to a subfolder on the same level as the others? I would prefer to have InstrumentationTests folder alongside Unit/Component.

@nenick
Copy link
Owner

nenick commented May 6, 2014

Thanks for your complimentary words.

Short, yes it is possible and already done https://github.com/stephanenicolas/Quality-Tools-for-Android

I tried it months ago but a co worker implemented the default version earlier. So I found no reason to try it further.

For some additional testing I like also to proof wether it is possible with new build tool versions. We have different stages with different possibilities to setup test data. So for need different kind of tests for live server and server in our dev stages.

@nenick
Copy link
Owner

nenick commented May 7, 2014

I feel i'm close to a solution.

Current i hang on the situation, that AcceptanceTest module will build his own APK. Thats would be ok (ignoring extra compile time) but i didn't find a way to include AndroidSample res into APK current.

A different approach is to reuse the generated APK by AndroidSample (preferred solution), but here i can't find a way to disable APK generation task at AcceptanceTest module. Without it would not override the APK generated by AndroidSample, where all classes and res are included.

i can use: assembleDebug.enabled = false and task will be skipped
but looks like APK is generated by packageDebug. (which works not)

@RichardGuion
Copy link
Contributor Author

Thanks! I will attempt a solution on my own as well.

@nenick nenick added the wish label May 8, 2014
@nenick
Copy link
Owner

nenick commented May 8, 2014

here is my build.gradle after moving espresso to a submodule for the version where it should use the already generated APK from main module. but not working current. https://gist.github.com/nenick/3820d89cd66570f86204

@RichardGuion
Copy link
Contributor Author

Interesting. Thanks for sharing that, will try soon.

@nenick
Copy link
Owner

nenick commented May 9, 2014

version with recompile app sources for module with espresso tests works. it was just a path naming issue where i forgot to rename the module name to AndroidSample. the gist is updated and can be used in a own module.

drawbacks: recompile and in android studio it looks ugly with - ModuleName (resources root)

but it should still be possible to avoid the ugly stuff when we could reuse apk from the main module.

@nenick
Copy link
Owner

nenick commented May 9, 2014

it looks like it wasn't the intention to use espresso in own modules, so you should ask this guys to support it without ugly drawbacks and configurations effort

@RichardGuion
Copy link
Contributor Author

Still trying to get mine to work. Let me summarize what you seemed to do:

You created a new build.gradle file in a sub folder.
The content of the build.gradle was much the same as the one in AndroidSample, and I noted these things:

  • You removed apt
  • You removed buildTypes section
  • I see instrumentTest rather than androidTest but that's just a typo.
  • dependencies for androidTest, such as espresso
  • You kept all the compile dependencies for Android Sample --> so it can compile APK for AndroidSample in addition to instrumented APK?
  • sourceSets directories point back to ../AndroidSample/src/... --> because an instrumented APK needs to refer back to the source I assume?

@nenick
Copy link
Owner

nenick commented May 13, 2014

Yes you are right.

  • Module with given build.gradle
  • move src/test to new module.

Dependencies are added mostly for android studio. He thinks now that AndroidSample/src/main belongs to the other module, because gradle.build say it. That is the real ugly part of this solution.

@RichardGuion
Copy link
Contributor Author

I have mine setup much like yours. But when I do this command:

.gradlew assembleDebugTest

instead of using the new build.gradle file in the sub module, it uses the one in the main Android folder - and produces a nearly empty test apk.

@nenick
Copy link
Owner

nenick commented May 13, 2014

Hehe maybe it didn't find a test class ;)
rename test folder to androidTest and try again

@nenick
Copy link
Owner

nenick commented May 13, 2014

Maybe wrong call (try with :subfolder:assemble... or missing entry in settings.gradle?

@RichardGuion
Copy link
Contributor Author

I finally got it to work. For everyone reading this who wants to know I did the following:

  • Created a folder called "tests" at same level/depth as app.
  • My test source was in src/androidTest/java
  • Copied over build.gradle from app folder into tests
  • Remove build targets not needed from build.gradle
  • Added androidTestCompile dependencies

./gradlew :tests:assembleDebug -> builds APK for app; not necessary exactly but it does it
./gradlew :tests:assembleDebugTest -> builds Test APK with instrumentation

Thank you, Nico, for giving me so many tips on how to accomplish this.

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

No branches or pull requests

2 participants