-
- All Implemented Interfaces:
public final class DetoxStatic 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.
Or through command line, e.gandroid { defaultConfig { testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" testInstrumentationRunnerArguments = [ 'detoxServer': 'ws://10.0.2.2:8001', 'detoxSessionId': '1' ] } }adb shell am instrument -w -e detoxServer ws://localhost:8001 -e detoxSessionId 1 com.example/android.support.test.runner.AndroidJUnitRunnerThese are automatically set using,
detox testIf not set, then Detox tests are no ops. So it's safe to mix it with other tests.
-
-
Method Summary
Modifier and Type Method Description static voidrunTests(ActivityTestRule activityTestRule)Call this method from a JUnit test to invoke detox tests. static voidrunTests(ActivityTestRule activityTestRule, DetoxConfig detoxConfig)Same as the default runTests method, but allows for the explicit specification of various configurations. static voidrunTests(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. static voidrunTests(ActivityTestRule activityTestRule, @NonNull() Context context, DetoxConfig detoxConfig)Same as runTests, but allows for the explicit specification of various configurations. static voidlaunchMainActivity()static voidstartActivityFromUrl(String url)static voidstartActivityFromNotification(String dataFilePath)-
-
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 activityTestRulecontext- an object that has agetReactNativeHost()method
-
runTests
static void runTests(ActivityTestRule activityTestRule, @NonNull() Context context, DetoxConfig detoxConfig)
Same as runTests, but allows for the explicit specification of various configurations. Note: review DetoxConfig for defaults.
- Parameters:
detoxConfig- The configurations to apply.
-
launchMainActivity
static void launchMainActivity()
-
startActivityFromUrl
static void startActivityFromUrl(String url)
-
startActivityFromNotification
static void startActivityFromNotification(String dataFilePath)
-
-
-
-