mapbox-directions-swift icon indicating copy to clipboard operation
mapbox-directions-swift copied to clipboard

Create a mock for "Route" entity for Unit Testing

Open nastasiupta opened this issue 5 years ago • 3 comments

'MapboxDirections.swift', '0.27.3'

I'm writing unit tests for a class that uses a dependency that should return at least one "Route" entity.

For the dependency class, I created a new class by subclassing, and on completion block I want to return a mock object for "Route", but during build time for unit tests I get those issues:

:-1: Undefined symbol: type metadata accessor for MapboxDirections.Route :-1: Undefined symbol: MapboxDirections.Waypoint.__allocating_init(coordinate: __C.CLLocationCoordinate2D, coordinateAccuracy: Swift.Double, name: Swift.String?) -> MapboxDirections.Waypoint :-1: Undefined symbol: type metadata accessor for MapboxCoreNavigation.NavigationMatchOptions :-1: Undefined symbol: MapboxCoreNavigation.NavigationMatchOptions.__allocating_init(waypoints: [MapboxDirections.Waypoint], profileIdentifier: __C.MBDirectionsProfileIdentifier?) -> MapboxCoreNavigation.NavigationMatchOptions :-1: Undefined symbol: type metadata accessor for MapboxDirections.Waypoint :-1: Undefined symbol: _MBDirectionsProfileIdentifierAutomobile :-1: Undefined symbol: MapboxDirections.Directions.shared.unsafeMutableAddressor : MapboxDirections.Directions

nastasiupta avatar Jul 25 '19 12:07 nastasiupta

For the dependency class, I created a new class by subclassing, and on completion block I want to return a mock object for "Route"

What does the subclass look like? Is this the completion block in an override of an existing method, or a completion block of a new method?

The warnings seem to be about every MapboxDirections symbol you’re using in your test bundle. Could there be a naming collision?

1ec5 avatar Jul 26 '19 09:07 1ec5

@1ec5 here is what I try to do: let options = RouteOptions(waypoints: []) let route = Route(json: [:], waypoints: [], options: options) let response = MapBoxRouteEntityConvertorWorker.MapBoxRouteResponse(route: route, wayType: .fastest)

And those are the errors: :-1: Undefined symbol: type metadata accessor for MapboxDirections.RouteOptions :-1: Undefined symbol: type metadata accessor for MapboxDirections.Waypoint :-1: Undefined symbol: MapboxDirections.RouteOptions.__allocating_init(waypoints: [MapboxDirections.Waypoint], profileIdentifier: __C.MBDirectionsProfileIdentifier?) -> MapboxDirections.RouteOptions :-1: Undefined symbol: type metadata accessor for MapboxDirections.Route :-1: Undefined symbol: MapboxDirections.Route.__allocating_init(json: [Swift.String : Any], waypoints: [MapboxDirections.Waypoint], options: MapboxDirections.RouteOptions) -> MapboxDirections.Route

And i imported: import MapboxDirections

nastasiupta avatar Aug 07 '19 08:08 nastasiupta

Does this issue still persist? We’ve since rewritten the library to use pure Swift instead of bridging to Objective-C. I realize your test is written in Swift, but I wonder if the build errors were related to symbols that were bridging anyways.

1ec5 avatar Jan 07 '20 19:01 1ec5