I have a class thats sole purpose is to run a method on other classes from an Interface.
Testing the interface of the classes is no problem, but the runner doesn’t actually DO anything and (as it stands) the only parameter passed into the constructor is kept private.
In my case, the classes are importing text files into a database.
internal DataImporter
{
private List<IFileImporter> _importers;
public DataImporter(List<IFileImporter> importers){
_importers = importers;
public bool RunImporters()
{
//foreach importer, call its "Run" method - each one then does whatever it needs to do
//however, this need not call a specific "Run" method on IFileImporter
//I have another app that uses IFileImporter to check for presence of a file first
//then allow user to choose to import or not.
}
It seems to me there is nothing to test here? I can’t test the value of _importers, and I don’t want to make it public JUST for the sake of testing. DataImporter is specific to this instance, so creating an interface seems to add no benefit.
I’ve re-used IFileImporters elsewhere, but this is the only “bulk” importer, others are called manually from a winforms app, still others are not in this project at all.
So, do I need to test this…what CAN I test about this?
In a nutshell, yes. I can think of a number of tests right off the top of my head.
Your test ensures that all importers are called by mocking out IFileImporters you pass in the constructor. At a minimum it asserts that what you pass in the constructor are actually used by the method.
A test to ensure that if any importer that raises an exception, your class behaves as you expect.
A test should assert the behaviour if the list is empty. (default to True return?)
A test should also assert the behaviour you expect if one or more importers fail. (Are you and-ing or or-ing your importer results for your RunImporters result?)
Does the method run every importer regardless of if a previous fails, or returns false on the first failure?
There should also be a test on your constructor or Assertion for if its provided a null list.