private static int BuildAndRunAndroidTests(List <string> commandArgs, bool reinstall, string resultPath) { if (commandArgs.Count == 0) { throw new OptionException("One APK should be provided", "apk"); } // get build number int buildNumber; if (!Int32.TryParse(Environment.GetEnvironmentVariable("XENKO_BUILD_NUMBER"), out buildNumber)) { buildNumber = -1; } // get branch name var branchName = Environment.GetEnvironmentVariable("XENKO_BRANCH_NAME"); var exitCode = 0; foreach (var packageFile in commandArgs) { if (!packageFile.EndsWith("-Signed.apk")) { throw new OptionException("APK should end up with \"-Signed.apk\"", "apk"); } // Remove -Signed.apk suffix var packageName = Path.GetFileName(packageFile); packageName = packageName.Replace("-Signed.apk", string.Empty); var androidDevices = AndroidDeviceEnumerator.ListAndroidDevices(); if (androidDevices.Length == 0) { throw new InvalidOperationException("Could not find any Android device connected."); } foreach (var device in androidDevices) { var testServerHost = new TestServerHost(buildNumber, branchName); Directory.CreateDirectory(resultPath); var deviceResultFile = Path.Combine(resultPath, "TestResult_" + packageName + "_Android_" + device.Name + "_" + device.Serial + ".xml"); var currentExitCode = testServerHost.RunAndroidTest( new TestServerHost.ConnectedDevice { Name = device.Name, Serial = device.Serial, Platform = TestPlatform.Android, }, reinstall, packageName, packageFile, deviceResultFile); if (currentExitCode != 0) { exitCode = currentExitCode; } } } return(exitCode); }
private static int BuildAndRunAndroidTests(List<string> commandArgs, bool reinstall, string resultPath) { if (commandArgs.Count == 0) throw new OptionException("One APK should be provided", "apk"); // get build number int buildNumber; if (!Int32.TryParse(Environment.GetEnvironmentVariable("XENKO_BUILD_NUMBER"), out buildNumber)) buildNumber = -1; // get branch name var branchName = Environment.GetEnvironmentVariable("XENKO_BRANCH_NAME"); var exitCode = 0; foreach (var packageFile in commandArgs) { if (!packageFile.EndsWith("-Signed.apk")) throw new OptionException("APK should end up with \"-Signed.apk\"", "apk"); // Remove -Signed.apk suffix var packageName = Path.GetFileName(packageFile); packageName = packageName.Replace("-Signed.apk", string.Empty); var androidDevices = AndroidDeviceEnumerator.ListAndroidDevices(); if (androidDevices.Length == 0) throw new InvalidOperationException("Could not find any Android device connected."); foreach (var device in androidDevices) { var testServerHost = new TestServerHost(buildNumber, branchName); Directory.CreateDirectory(resultPath); var deviceResultFile = Path.Combine(resultPath, "TestResult_" + packageName + "_Android_" + device.Name + "_" + device.Serial + ".xml"); var currentExitCode = testServerHost.RunAndroidTest( new TestServerHost.ConnectedDevice { Name = device.Name, Serial = device.Serial, Platform = TestPlatform.Android, }, reinstall, packageName, packageFile, deviceResultFile); if (currentExitCode != 0) exitCode = currentExitCode; } } return exitCode; }