Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

android testBuildType not working

android {
  ...
  testBuildType "deviceTest"
  buildTypes {
    debug {
      // Using 10.0.2.2 (the desktop's localhost), as the app normally runs on an Emulator
      // in debug mode.
      buildConfigField "String", "BACKEND_URL", '"http://10.0.2.2"'
      buildConfigField "Integer", "PORT", "8080"
      applicationIdSuffix ".debug"
    }
    // Use local host for testing, for MockWebServer
    deviceTest {
      initWith debug
      buildConfigField "String", "BACKEND_URL", '"http://localhost"'
    }
    release {
      ...
    }
  }
}

Exactly like Google doc implies here. However, this causes test dependencies (like JUnit) to be unreachable from unit tests, and so the test cannot run.

like image 352
Ohad Navon Avatar asked Jun 05 '17 11:06

Ohad Navon


1 Answers

I figured out this issue on AS 3.1.3.

The problem is Build Variant and testBuildType doesn't match. So after adding testBuildType to your gradle file, go to 'Build -> Select Build Variant' and select the same variant for your app.

You may also need set signing key or solve proguard issues before running androidTest correctly, but the dependencies should be reachable now.

More detail can be tracked here: https://issuetracker.google.com/issues/36995546

like image 105
Zhicheng Gu Avatar answered Nov 09 '22 01:11

Zhicheng Gu