在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称(OpenSource Name):benwilcock/android-alltest-gradle-sample开源软件地址(OpenSource Url):https://github.com/benwilcock/android-alltest-gradle-sample开源编程语言(OpenSource Language):Java 100.0%开源软件介绍(OpenSource Introduction):#Android All-test Gradle Sample This project provides a Gradle project template for an Android project which integrates and configures testing using Robolectric, Robotium, Java JUnit Tests and Android Instrumentation tests together in one project. BackgroundI develop the TripComputer Android App but I find testing it using the standard Instrumentation framework is really slow because it demands either a connected device or an emulator to be running upon which it runs the tests. Slow testing cycles are a disincentive to TDD, so most tutorials bestow the virtues of switching to the Robolectric framework when unit testing Android apps because it 'simulates' the android SDK in a standard Java VM. This allows your Android tests to be executed outside of the emulator/device. It also allows the use of JUnit v4 syntax rather than the older JUnit v3 required by the built in Android Instrumentation testing framework. However, there's a problem - it's tricky to get this stuff to work in Android Studio. I've been an Android Studio user ever since it first went public nearly 2 years ago. It's an awesome IDE but one consequence of it's use is that it promotes the Gradle build system to be the default choice for Android projects. This is good news for Android developers but unfortunately, getting Android Studio, Gradle, Robolectric and JUnit to all work happily together is a real pain in the rear. Over the past year or so it's been a slowly improving picture, but now Android Studio has gone to a 1.0 release, I (and many others) have figured the time was right to try and bring these tools together. The android-alltest-gradle-sample project on GitHub is my attempt to create a template project that can be used as a starting point for anyone who wishes to use these best of breed Android Testing tools together with Gradle and Android Studio in one project. To use the sample, simply clone the repository (or download a ZIP), import into Android Studio, test it and then start running code. Check out the Acknowledgements section in the readme for further help, tips and advice (including how to execute your Robolectric tests from within Android Studio as well as from the cmdline). Project StructureProject is broken down into 3 modules
Dependencies & FrameworksThis project template integrates and depends on the following popular Java and Android frameworks:
Running TestsTests can be run using one of the following (or combinations thereof):
Known IssuesRobolectric isn't fully suporting AppCompat v21 yet, and strange random failures can affect the smooth running of the build if you choose to 'clean' it. There is more information on Stackoverflow here. The suggested workaround is to separate the gradle commands as follows...
CautionsThis stuff is brittle! It's a very volatile set of tools we're using.
I'm not sure anyone other than Google can improve the situation regarding Android testing if I'm brutally honest. It's a bit of a 'dogs dinner'. On the plus side, I haven't used any additional gradle plugins. I've seen and tried lots but they can go out of date quite quickly. AcknowledgementsThe original inspiration for this template project came from Jason Atwood's blog at Big Nerd Ranch: http://www.bignerdranch.com/blog/all-in-together-android-studio-gradle-and-robolectric/ This template project is based on the following blog post and code samples (but I further further adapted it soa as to include instrumentation and a java core module) http://blog.blundell-apps.com/android-gradle-app-with-robolectric-junit-tests/ The tests for Robolectric can also be configured to run from within Android Studio 1.0.x if you follow this post: http://blog.blundell-apps.com/how-to-run-robolectric-junit-tests-in-android-studio/ I had lots of issues with AppCompat which took a while to fix, but @sjorsgeelen and @loeschg had the right answer here: About the AuthorBen Wilcock is the developer of TripComputer , the only distance tracking app for Android with a battery-saving LOW POWER mode. It’s perfect for cyclists, runners, walkers, hand-gliders, pilots and drivers. It’s free! Download it from the Google Play Store now:- Get Trip Computer on Google Play You can follow Ben on his Blog, Website, Twitter or LinkedIn |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论