Interface Configurer<T>

Type Parameters:
T - the configuration object's type
All Known Implementing Classes:
ConfigConfigurer, ConscryptModeConfigurer, GetInstallerPackageNameModeConfigurer, GraphicsModeConfigurer, LazyApplicationConfigurer, LooperModeConfigurer, SQLiteModeConfigurer, TextLayoutModeConfigurer

public interface Configurer<T>
Provides configuration data for tests.

The test author can apply configuration data at a package, class, or method level, or any combination of those.

The implementation of the configurer determines how config information is collected and merged for each test.

For the test:

   class com.foo.MyTest extends com.foo.BaseTest {
     @Test void testMethod() {}
   }
 

the configuration is applied in the following order:

  • the defaultConfig()
  • as specified in /robolectric.properties
  • as specified in /com/robolectric.properties
  • as specified in /com/foo/robolectric.properties
  • as specified in BaseTest
  • as specified in MyTest
  • as specified in MyTest.testMethod

Configuration objects can be accessed by shadows or tests via ConfigurationRegistry.get(Class).

See Also:
  • Method Summary

    Modifier and Type
    Method
    Description
    Returns the default configuration for tests that do not specify a configuration of this type.
    Retrieve the class type for this Configurer
    getConfigFor(Class<?> testClass)
    Returns the configuration for the given class.
    Returns the configuration for the given method.
    getConfigFor(String packageName)
    Returns the configuration for a given package.
    merge(T parentConfig, T childConfig)
    Merges two configurations.
  • Method Details

    • getConfigClass

      Class<T> getConfigClass()
      Retrieve the class type for this Configurer
    • defaultConfig

      @Nonnull T defaultConfig()
      Returns the default configuration for tests that do not specify a configuration of this type.
    • getConfigFor

      T getConfigFor(@Nonnull String packageName)
      Returns the configuration for a given package.

      This method will be called once for package in the hierarchy leading to the test class being configured. For example, for com.example.FooTest, this method will be called three times with "com.example", "@com", and "" (representing the top level package).

      Parameters:
      packageName - the name of the package, or the empty string representing the top level unnamed package
      Returns:
      a configuration object, or null if the given properties has no relevant data for this configuration
    • getConfigFor

      T getConfigFor(@Nonnull Class<?> testClass)
      Returns the configuration for the given class.

      This method will be called for each class in the test's class inheritance hierarchy.

      Returns:
      a configuration object, or null if the given class has no relevant data for this configuration
    • getConfigFor

      T getConfigFor(@Nonnull Method method)
      Returns the configuration for the given method.
      Returns:
      a configuration object, or null if the given method has no relevant data for this configuration
    • merge

      @Nonnull T merge(@Nonnull T parentConfig, @Nonnull T childConfig)
      Merges two configurations. This method will called whenever getConfigFor(java.lang.String) returns a non-null configuration object.
      Parameters:
      parentConfig - a less specific configuration object
      childConfig - a more specific configuration object
      Returns:
      the new configuration with merged parent and child data.