Feature Proposal: Allow Extensions to force required setup's into the UnitTests

Motivation

Both DBIStore and integrated Kino and MongoDB (and others) need to be able to force certain settings in the standard Unit tests to allow us to test them.

both Crawford and I have been hard coding it for now, so we can get some progress, but this issue has been lurking for a while.

Description and Documentation

What I'm proposing, is to add a lib/Unit/Extensions dir, into which Extensions can add extra classes which would be loaded and evaluated.

Examples

package Unit::Extension::MongoDB;

use Unit::Extension;

our @ISA = ('Unit::Extension');

#can be used to detect if an Extension can't be tested, or to turn it on/off
sub applies {
  return 0 if (MongoDB is not available);
  return 1;
}

#do stuff before or after the test's fixture_groups method
sub pre_fixture_groups {
}
sub post_fixture_groups {
}

#do stuff before or after the test's loadExtraConfig method
sub pre_loadExtraConfig {
    #turn on the MongoDBPlugin so that the saved data goes into mongoDB
    #This is temoprary until Crawford and I cna find a way to push dependencies into unit tests
    if (($Foswiki::cfg{Store}{SearchAlgorithm} =~ /MongDB/) or 
        ($Foswiki::cfg{Store}{QueryAlgorithm} =~ /MongDB/)) {
        $Foswiki::cfg{Plugins}{MongoDBPlugin}{Module} = 'Foswiki::Plugins::MongoDBPlugin'; 
        $Foswiki::cfg{Plugins}{MongoDBPlugin}{Enabled} = 1; 
        $Foswiki::cfg{Plugins}{MongoDBPlugin}{EnableOnSaveUpdates} = 1; 
    }
}
sub post_loadExtraConfig {
    if (($Foswiki::cfg{Store}{SearchAlgorithm} =~ /MongDB/) or 
        ($Foswiki::cfg{Store}{QueryAlgorithm} =~ /MongDB/)) {
        require Foswiki::Plugins::MongoDBPlugin;
        Foswiki::Plugins::MongoDBPlugin::getMongoDB()->remove('current', {'_web' => $this->{test_web}});
    }
}



#do stuff before or after the test's set_up method
sub pre_set_up {
}
sub post_set_up {
}


Impact

%WHATDOESITAFFECT%
edit

Implementation

-- Contributors: SvenDowideit - 19 Oct 2010

Discussion

Topic revision: r3 - 19 Nov 2015, GeorgeClark
The copyright of the content on this website is held by the contributing authors, except where stated elsewhere. See Copyright Statement. Creative Commons License    Legal Imprint    Privacy Policy