MapView extent is null in unit test?

471
1
01-18-2023 10:30 AM
succip
by
New Contributor III

Hello,

I'm trying to automate testing of a series of tools in my ArcGIS Pro Add In. Several of them rely on an active MapView and it doesn't seem to initialize properly in the context of a unit test. For example, I'd like to confirm the MapView coordinates change when a combobox item is changed, zooming to a different map tile in a dataset. Following the regression example in the community samples, my test currently looks like this:

 

public async Task ZoomToMapTile_ChangesMapViewLocation()
{
    await _map.OpenViewAsync();
    MapView mapView = MapView.Active;
    double originXCoordinate = MapView.Active.Extent.Center.X;
    Mapping.ZoomToMapTile("004");
    double destinationXCoordinate = MapView.Active.Extent.Center.X;

    Assert.AreNotEqual(originXCoordinate, destinationXCoordinate);
}

 

Running with breakpoints, I see the MapView populates the correct map properly, but many of the properties are null, and the IsReady property is false. Should I avoid this pattern for unit testing user controls? Is there any other way for me to automate testing?

Any suggestions or guidance is greatly appreciated.

1 Reply
CharlesMacleod
Esri Regular Contributor

When running headless, Pro does not have a fully activated view so u cant rely on it for unit tests. To test functionality that requires a ("proper") active view u will need something like CUIT, coded UI test.