android { ... testBuildType "deviceTest" buildTypes { debug { // Using 10.0.2.2 (the desktop 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 { ... } } }
Just like google doc implies here . However, this leads to the fact that test dependencies (for example, JUnit) are not available for unit tests, so the test cannot be performed.
source share