Hello,
I have been trying to unit test my ArcGIS Pro add-in in an automated fashion on a build server.
I followed the steps in this guide to get unit testing working on my local machine (which works great): https://github.com/esri/arcgis-pro-sdk/wiki/ProGuide-Regression-Testing
However, I'm finding that because the user on the build server is not logged into an ArcGIS Portal, that this method in the above guide is failing:
/// <summary>
/// Starts an instance of ArcGIS Pro Application
/// </summary>
public static async void StartApplication()
{
var evt = new System.Threading.ManualResetEvent(false);
System.Threading.Tasks.Task ready = null;
var uiThread = new System.Threading.Thread(() =>
{
try
{
Application = new ProApp();
ready = Application.TestModeInitializeAsync();
evt.Set();
}
catch (XamlParseException)
{
throw new FatalArcGISException("Pro is not licensed");
}
catch (Exception ex)
{
throw ex;
}
finally
{
evt.Set();
}
System.Windows.Threading.Dispatcher.Run();
});
uiThread.TrySetApartmentState(System.Threading.ApartmentState.STA);
uiThread.Name = "Test UI Thread";
uiThread.IsBackground = true;
uiThread.Start();
evt.WaitOne(); // Task ready to wait on.
if (ready != null)
{
try
{
await ready;
}
catch (Exception ex)
{
throw ex;
}
}
}
The error message I see in the console from the test run says: The active test run was aborted. Reason: Test host process crashed
Is there a way to programmatically provide Portal credentials to the ArcGIS Pro application before it is initialized for unit testing?
Solved! Go to Solution.
So I finally was able to get this working... it turns out that I was using the wrong Windows user on the build machine to license ArcGIS Pro. I needed to log into the machine with the automated build user's Windows credentials, instead of my own admin ones.
Additionally, for licensing ArcGIS Pro, I ended up using a Single Use License instead of a Named User License. Apparently a Named User License configuration does work for automated unit tests, but it requires being authorized to work offline, which renders it unavailable for usage anywhere else (until it is taken back online). Using a Single User License seems more straightforward and less problematic.
What type of license configuration do you have?
I'm using a Named User License from my ArcGIS Online account.
It should stay logged in if you are are authenticating with your named user license.
Also maybe check out this thread:
https://github.com/microsoft/vstest/issues/2261
Right, I did find it stays logged in on my local machine. Unfortunately though, I'm not able to log in as the build user on the build server, so I have no way to manually enter my credentials in the first place.
Thanks for the link, I will check that thread out.
Have you checked your user permissions to the server? If you are unable to log in sounds like a permissions issue.
It's not a permissions issue. The problem is our automated build on the server recreates a clean environment each time it runs tests, which will break the ArcGIS Pro licensing. And since it is automated, I'm not able to manually enter my named user credentials each time it runs.
It's seeming like this setup might not be compatible with a named user license configuration... Would a different license configuration be more ideal for this scenario?
So I finally was able to get this working... it turns out that I was using the wrong Windows user on the build machine to license ArcGIS Pro. I needed to log into the machine with the automated build user's Windows credentials, instead of my own admin ones.
Additionally, for licensing ArcGIS Pro, I ended up using a Single Use License instead of a Named User License. Apparently a Named User License configuration does work for automated unit tests, but it requires being authorized to work offline, which renders it unavailable for usage anywhere else (until it is taken back online). Using a Single User License seems more straightforward and less problematic.