Detox
Detox copied to clipboard
Fix misleading filepaths for DetoxTest.java in project-setup.mdx
Description
In this pull request, I have fixed misleading filepaths in the documentation for Project Setup in Step 4: Additional Android configuration.
The issue with the misleading documentation lines are that they referenced the test code will reside at android/app/src/androidTest/java/com/<you.package>/DetoxTest.java
however this is incorrect as it should instead reside at android/app/src/androidTest/java/DetoxTest.java
.
I spent 2 hours debugging an issue where Detox would build and attempt to run the test however it would not launch the app and would fail at await device.launchApp()
:
Detox can't seem to connect to the test app(s)!
HINT: The test app might have crashed prematurely, or has had trouble setting up the connection.
- I had properly setup the XML config for clear text traffic for Metro to connect
- I had used trace and record logs all options and read the Detox logs which indicated the clear text traffic was working:
11-21 17:08:25.517 20209 20209 D NetworkSecurityConfig: Using Network Security Config from resource network_security_config debugBuild: true
- In the Detox logs I noticed the
adb ... shell am instrument
command returningOK (0 tests)
:
INSTRUMENTATION_RESULT: stream=
Time: 0
OK (0 tests)
INSTRUMENTATION_CODE: -1
- This was clearly an indication that Detox was attempting to start the app but the instrument command could not find the "dummy test"
DetoxTest.java
- I tried many combinations of the filepath for
DetoxTest.java
in my source sets until I found thatandroidTest/java/DetoxTest.java
was the working path- The official Android SDK docs directly support this idea (see Table 1.): https://developer.android.com/studio/test/advanced-test-setup
Since I have fixed this issue after 2 hours of debugging I think it warrants the docs to be updated since two simple line changes would have saved me 2 hours.
Note: This solution is working for me with the following combinations:
-
"react-native": "0.70.5",
-
"detox": "^20.13.5",
-
targetSdkVersion = 32
-
kotlinVersion = '1.7.0'
- 3 custom
productFlavors
- 2 standard
buildTypes
:debug
andrelease
For features/enhancements:
- [x] I have added/updated the relevant references in the documentation files.
For API changes:
- [ ] I have made the necessary changes in the types index file.
Actually, this is curious, @kalyncoose. In our example project, I can see that we don't use java
, yet it works (we have regular CI builds on every commit, so it's not something inactive).
I might be okay with adding java
as an alternative suggestion, but still, it's not clear what's the difference between the example project and yours... is it a newer Gradle plugin or Android SDK? Is it your build scripts, or is it something else?
In which package did you put your DetoxTest.java, by the way? I mean, like package com.example;
in the beginning.
Hi @noomorph, thanks for collaborating on this PR. The project in question is private for my company so I cannot write the exact package name but it is like this: package org.domain.projectName
and so I tried a large variety of folder structures for the DetoxTest.java
and these were the outcomes:
- ❌
./androidTest/java/com/org/domain/projectName/DetoxTest.java
- ❌
./androidTest/java/org/domain/projectName/DetoxTest.java
- ❌
./androidTest/java/com/domain/projectName/DetoxTest.java
- ❌
./androidTest/java/com/DetoxTest.java
- ❌
./androidTest/java/projectName/DetoxTest.java
- ❌
./androidTest/java/com/projectName/DetoxTest.java
- ❌
./androidTest/org/domain/projectName/DetoxTest.java
- ❌
./androidTest/projectName/DetoxTest.java
- ❌
./androidTest/com/DetoxTest.java
- ✅
./androidTest/java/DetoxTest.java
As for the Gradle version here is what my RN project outputted with ./gradlew --version
:
------------------------------------------------------------
Gradle 7.5.1
------------------------------------------------------------
Build time: 2022-08-05 21:17:56 UTC
Revision: d1daa0cbf1a0103000b71484e1dbfe096e095918
Kotlin: 1.6.21
Groovy: 3.0.10
Ant: Apache Ant(TM) version 1.10.11 compiled on July 10 2021
JVM: 11.0.17 (Azul Systems, Inc. 11.0.17+8-LTS)
OS: Mac OS X 13.4 x86_64
As far as the build scripts go, I have correctly updated my .detoxrc.js
file to accommodate for my project's "dev" productFlavor
with the debug
and release
variants where are both building successfully:
...
'android.debug': {
type: 'android.apk',
binaryPath: 'android/app/build/outputs/apk/dev/debug/app-dev-debug.apk',
build: 'cd android && ./gradlew assembleDevDebug assembleAndroidTest -DtestBuildType=debug',
reversePorts: [8081],
},
'android.release': {
type: 'android.apk',
binaryPath: 'android/app/build/outputs/apk/dev/release/app-dev-release.apk',
build: 'cd android && ./gradlew assembleDevRelease assembleAndroidTest -DtestBuildType=release',
},
...
I then successfully execute the build scripts with mobile/package.json
scripts like these:
"detox:att:debug": "detox build --configuration android.att.debug && detox test --configuration android.att.debug --record-logs all",
"detox:att:release": "detox build --configuration android.att.release && detox test --configuration android.att.release --record-logs all",
Possible issue: does the assembleAndroidTest
need to be reworded for productFlavors
?
This pull request has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. For more information on bots in this repository, read this discussion.
This pull request has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. For more information on bots in this repository, read this discussion.