Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix misleading filepaths for DetoxTest.java in project-setup.mdx #4287

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

kalyncoose
Copy link

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 returning OK (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 that androidTest/java/DetoxTest.java was the working path

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 and release

For features/enhancements:

  • 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.

@noomorph
Copy link
Collaborator

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).

image

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?

@noomorph
Copy link
Collaborator

noomorph commented Nov 23, 2023

In which package did you put your DetoxTest.java, by the way? I mean, like package com.example; in the beginning.

@kalyncoose
Copy link
Author

kalyncoose commented Nov 28, 2023

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?

Copy link

stale bot commented Mar 13, 2024

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.

Copy link

stale bot commented Apr 22, 2024

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.

@stale stale bot added the 🏚 stale label Apr 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants