Package 

Class Detox

  • All Implemented Interfaces:

    
    public final class Detox
    
                        

    Static class.

    To start Detox tests, call runTests() from a JUnit test. This test must use AndroidJUnitRunner or a subclass of it, as Detox uses Espresso internally. All non-standard async code must be wrapped in an Espresso IdlingResource.

    Example usage
    
    @runWith(AndroidJUnit4.class)
    @LargeTest
    public class DetoxTest {
     @Rule
      //The Activity that controls React Native.
      public ActivityTestRule<MainActivity> mActivityRule = new ActivityTestRule(MainActivity.class);
    
     @Before
      public void setUpCustomEspressoIdlingResources() {
        // set up your own custom Espresso resources here
      }
    
     @Test
      public void runDetoxTests() {
        Detox.runTests();
      }
    }

    Two required parameters are detoxServer and detoxSessionId. These must be provided either by Gradle.

    
    android {
      defaultConfig {
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
        testInstrumentationRunnerArguments = [
          'detoxServer': 'ws://10.0.2.2:8001',
          'detoxSessionId': '1'
        ]
      }
    }
    Or through command line, e.g
    adb shell am instrument -w -e detoxServer ws://localhost:8001 -e detoxSessionId
    1 com.example/android.support.test.runner.AndroidJUnitRunner

    These are automatically set using,

    detox test

    If not set, then Detox tests are no ops. So it's safe to mix it with other tests.

    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
    • Field Summary

      Fields 
      Modifier and Type Field Description
    • Constructor Summary

      Constructors 
      Constructor Description
    • Enum Constant Summary

      Enum Constants 
      Enum Constant Description
    • Constructor Detail

    • Method Detail

      • runTests

         static void runTests(ActivityTestRule activityTestRule)

        Call this method from a JUnit test to invoke detox tests.

        In case you have a non-standard React Native application, consider using runTests}.

        Parameters:
        activityTestRule - the activityTestRule
      • runTests

         static void runTests(ActivityTestRule activityTestRule, DetoxConfig detoxConfig)

        Same as the default runTests method, but allows for the explicit specification of various configurations. Note: review DetoxConfig for defaults.

        Parameters:
        detoxConfig - The configurations to apply.
      • runTests

         static void runTests(ActivityTestRule activityTestRule, @NonNull() Context context)

        Use this method only if you have a React Native application and it doesn't implement ReactApplication; Otherwise use runTests.

        The only requirement is that the passed in object must have a method with the signature

        ReactNativeHost getReactNativeHost();
        Parameters:
        activityTestRule - the activityTestRule
        context - an object that has a getReactNativeHost() method