Class BackgroundTestRule

java.lang.Object
org.robolectric.junit.rules.BackgroundTestRule
All Implemented Interfaces:
org.junit.rules.TestRule

@Deprecated public final class BackgroundTestRule extends Object implements org.junit.rules.TestRule
Deprecated.
use LooperMode.Mode.INSTRUMENTATION_TEST instead
Let tests to run on background thread, if it has annotation BackgroundTestRule.BackgroundTest.

This is useful for testing logic that explicitly forbids being called on the main thread.

Example usage:

 @Rule public final BackgroundTestRule backgroundTestRule = new BackgroundTestRule();

 @Test
 @BackgroundTest
 public void testInBackground() {
   assertThat(Looper.myLooper()).isNotEqualTo(Looper.getMainLooper());
 }

 @Test
 public void testInForeground() throws Exception {
   assertThat(Looper.myLooper()).isEqualTo(Looper.getMainLooper());
 }
 
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static @interface 
    Deprecated.
    Annotation for test methods that need to be executed in a background thread.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Deprecated.
     
  • Method Summary

    Modifier and Type
    Method
    Description
    org.junit.runners.model.Statement
    apply(org.junit.runners.model.Statement base, org.junit.runner.Description description)
    Deprecated.
     

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • BackgroundTestRule

      public BackgroundTestRule()
      Deprecated.
  • Method Details

    • apply

      public org.junit.runners.model.Statement apply(org.junit.runners.model.Statement base, org.junit.runner.Description description)
      Deprecated.
      Specified by:
      apply in interface org.junit.rules.TestRule