Context. I have interface IVehicle
, class VehiclesFactory
and private class Vehicle
nested in the VehiclesFactory
. Thus all code except the VehiclesFactory
kwnows nothing about any implementations of the IVehicle
.
Question. How should I unit test the Vehicle
? And should I do it at all?
Assumption 1. I can make the Vehicle
public. However this will allow the all code to write new VehiclesFactory.Vehicle(...)
which I try to avoid.
Assumption 2. I can make a new public method in the VehiclesFactory
, e. g., IVehicle ForUnitTests_Vehicle(...)
which just calls the Vehicle
constructor and passes its arguments to that constructor (allowing a unit test to supply necessary mocks). However this will allow the all code to call this strange method.
Assumption 3. Factories is a plague; use the new
operator everywhere. However this will couple my code more tightly.