I have a Xamarin Forms app, with tests using Xamarin.UITest, and I need to detect when it's running in App Center Test.
According to the docs, an environment variable RUNNING_IN_APP_CENTER
should be set to 1
automatically - but Environment.GetEnvironmentVariable("RUNNING_IN_APP_CENTER")
doesn't have a value at runtime.
Indeed, if I loop over all environment variables, it's not there:
KNOX_STORAGE:/data/knox/ext_sdcard
ANDROID_SOCKET_zygote:11
ASEC_MOUNTPOINT:/mnt/asec
MONO_DEBUG:gen-compact-seq-points
TMPDIR:/data/user/0/com.acme.widgets.dev/cache
XA_HTTP_CLIENT_HANDLER_TYPE:Xamarin.Android.Net.AndroidClientHandler
PATH:/sbin:/system/sbin:/system/bin:/system/xbin:/odm/bin:/vendor/bin:/vendor/xbin
MC_AUTH_TOKEN_PATH:/efs
XDG_CONFIG_HOME:/data/user/0/com.acme.widgets.dev/files/.config
DOWNLOAD_CACHE:/data/cache
ANDROID_ASSETS:/system/app
XA_TLS_PROVIDER:btls
ANDROID_ROOT:/system
MONO_GC_PARAMS:major=marksweep
XAMARIN_BUILD_ID:4658cc0f-1a7c-4c97-93a6-f2f09c5edb04
BOOTCLASSPATH:/system/framework/core-oj.jar:/system/framework/core-libart.jar:/system/framework/conscrypt.jar:/system/framework/okhttp.jar:/system/framework/bouncycastle.jar:/system/framework/apache-xml.jar:/system/framework/ext.jar:/system/framework/framework.jar:/system/framework/telephony-common.jar:/system/framework/voip-common.jar:/system/framework/ims-common.jar:/system/framework/sprengine.jar:/system/framework/android.hidl.base-V1.0-java.jar:/system/framework/android.hidl.manager-V1.0-java.jar:/system/framework/knoxsdk.jar:/system/framework/timakeystore.jar:/system/framework/fipstimakeystore.jar:/system/framework/sec_edm.jar:/system/framework/knoxanalyticssdk.jar:/system/framework/smartbondingservice.jar:/system/framework/ucmopensslenginehelper.jar:/system/framework/esecomm.jar:/system/framework/securetimersdk.jar:/system/framework/sec_sdp_sdk.jar:/system/framework/sec_sdp_hidden_sdk.jar:/system/framework/framework-oahl-backward-compatibility.jar:/system/framework/android.test.base.jar:/system/framework/knoxvpnuidtag.jar:/system/framework/SemAudioThumbnail.jar:/system/framework/knoxguard.jar:/system/framework/drutils.jar
ANDROID_DATA:/data
LANG:en-GB
EXTERNAL_STORAGE:/sdcard
ANDROID_BOOTLOGO:1
ENC_EMULATED_STORAGE_TARGET:/storage/enc_emulated
HOME:/data/user/0/com.acme.widgets.dev/files
SYSTEMSERVERCLASSPATH:/system/framework/services.jar:/system/framework/ethernet-service.jar:/system/framework/wifi-service.jar:/system/framework/com.android.location.provider.jar:/system/framework/hqm.jar:/system/framework/hcm.jar
ANDROID_STORAGE:/storage
XDG_DATA_HOME:/data/user/0/com.acme.widgets.dev/files/.local/share
I've also tried altering my App Center CLI command to include extra environment variables, as per the docs:
--test-parameter "app_env=MY_VAR=1"
But just the same, the MY_VAR
is not available in the app.
Is there some other way to read environment variables that I'm missing, or perhaps some other way to detect when running in App Center Test?
Can't you just use the "Test Compiler Directive" to detect that in code:
Look into your AppDelegate and MainActivity where you are enabling the Test configuration.