Question

I want to check the behaviour of a method by testing a protected variable of an assigned object. Therefore, I want to inject a mock object for this assigned object. My problem is that this object is created during this method and is not given trough a parameter.

bool MappingConfigurationBuilder::buildMappingConfiguration(MappingConfiguration*& mappingConfiguration)
{
  ...
  ConfigurationForColor configurationForColor;
  buildConfigurationForColor(configurationForColor);
  mappingConfiguration = new MappingConfiguration(configurationForHeight, configurationForColor);
  ...
  return true;
}

This method should create a ConfigurationForColor, change a protected variable on it in the protected method buildConfigurationForColor(...) and assign the object to a MappingConfiguration. I want to check the protected variable on configurationForColor.

Can I use Google Mock to change the type of configurationForColor to a mock object? Or is their another possibility to test the protected variable?

Was it helpful?

Solution

It sounds like you need some kind of inversion of control.

For that, it would be good to create a factory, which returns MappingConfiguration type objects (either mocks or real objects).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top