Build System Integration

Starting with Robolectric 3.3, the test runner will look for a file named /com/android/tools/test_config.properties on the classpath. If it is found, it will be used to provide the default manifest, resource, and asset locations for tests, without the need to specify @Config(constants=BuildConfig.class) or @Config(manifest="...", res="...", assetDir="...") in your tests.

This gives build system implementors the ability to perform manifest, asset and resource preprocessing and merging for tests using the same strategy it would when building the APK, rather than leaving it up to Robolectric.

This supersedes Robolectric’s support for merging multiple libraries specified via @Config(libraries = {"lib1", "lib2"}) and project.properties support from legacy Eclipse ADT projects.

Keys in the file:

  • android_merged_manifest: Full path to the project’s merged AndroidManifest.xml file.
  • android_merged_resources: Full path to the project’s merged resources.
  • android_merged_assets: Full path to the project’s merged assets.
  • android_custom_package: Java packagename for the applications R class.
  • android_resource_apk: Path to a resources.ap_ file that contains binary resources and XML files produced by aapt tool, as well as merged assets.

Note that Robolectric expects that build systems will have performed final R.class generation by the time unit tests are run.

For merged Raw resource support:

android_merged_assets=/some/path/MyApp/app/build/intermediates/assets/debug
android_merged_resources=/some/path/MyApp/app/build/intermediates/res/merged/debug
android_merged_manifest=/some/path/MyApp/app/build/intermediates/manifests/full/debug/AndroidManifest.xml
android_custom_package=com.example.app

For Binary resource support:

android_resource_apk=/some/path/to/app/resources.ap_
Robolectric
  • Home
  • Setup
    • Getting Started
    • Writing Your First Test
  • User Guide
    • AndroidX Test
    • Configuring Robolectric
    • Device Configuration
    • Using Qualified Resources
    • Using Add-On Modules
    • Best Practices
  • Customizing
    • Build System Integration
    • Customizing the Test Runner
  • Contributing
    • Building Robolectric
    • Contributor Guidelines
    • Shadows
  • Resources
    • GitHub
    • Release Notes
    • Migration Guide
    • Javadoc: 3.8 | 4.0 | 4.1 | 4.2 | 4.3 | 4.4 | 4.5 | 4.6 | 4.7 | 4.8 | 4.9
    • Issues

Recent Posts

GSoC 2022 - ConscryptMode

Sep 6, 2022

My name is Umesh Singh and I was an...

sharedTest pattern: sharing tests and speeding up development

Oct 6, 2021

After Robolectric’s 4.0 release, Robolectric supports...

A memorial tribute for Jonathan Gerrish

Sep 13, 2021

In late August, 2021, we were incredibly saddened to learn...

  • More…

Chrome Extension

See Robolectric documentation inline with Android Developer Documentation.

Contact

  • GitHub Project
  • robolectric@googlegroups.com
  • @Robolectric

©2010-2017. All rights reserved.
Design: HTML5 UP.