Class SpincastTestBase
- All Implemented Interfaces:
org.spincast.testing.junitrunner.BeforeAfterClassMethodsProvider,org.spincast.testing.junitrunner.CanBeDisabled,org.spincast.testing.junitrunner.RepeatedClassAfterMethodProvider,org.spincast.testing.junitrunner.TestFailureListener
- Direct Known Subclasses:
AppBasedTestingBase
Uses a custom Junit runner,
SpincastJUnitRunner.
This runner create a single instance of the test class for all of its tests,
instead of a new instance for each test. It also calls a beforeClass()
method before the tests are run and an afterClass() method after
they are run.
A class extending this will be part of a Guice context
(created using the createInjector method) and
the required dependencies will be injected into it.
A GuiceTweaker instance is used to
be able to tweak a Guice context automagically. This for example
allows you to start your actual application, using its main() method.
Note that the Guice tweaker only works when the Guice context is created
using the standard Spincast Bootstrapper .
Note that you can annotate a test class with:
@FixMethodOrder(MethodSorters.NAME_ASCENDING)if you need its tests to be ran in order (using the alphabetical order of the test methods' names).
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected static final org.slf4j.Loggerprotected org.spincast.core.config.SpincastConfig -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected voidAdds System properties as they are provided by thegetExtraSystemProperties()method.voidvoidvoidThis method will be called after each test.voidvoidvoidThis method will be called before each test.protected org.spincast.core.guice.GuiceTweakerprotected abstract com.google.inject.InjectorThe test class must implement this method to create the Guice injector.protected FileCreate a temp directory.protected StringReturns a unique path to use to create a temporary test file.protected StringcreateTestingFilePath(String relativePath) Returns the absolute path to use, given the relative one, to create a temporary test file.protected voidDeletes the testing writable temp directory.protected Set<com.google.inject.Key<?>>Extra exact bindings to remvoe before the plugins are applied.Extra System properties to set before the tests are run.protected com.google.inject.ModuleIf an overriding Module is to be added using the Guice tweaker.protected List<org.spincast.core.guice.SpincastPlugin>Extra plugins to be added by the Guice Tweaker.protected org.spincast.core.guice.GuiceTweakerIds of plugins to disable.protected com.google.inject.InjectorReturns the Guice injector.protected org.spincast.core.config.SpincastConfigprotected Class<? extends org.spincast.core.config.SpincastConfig>The implementation to use for theSpincastConfigbinding, when running tests.protected FileReturns the directory that can be used to create files and subdirectories during testing.protected booleanbooleanbooleanisTestClassDisabledPreBeforeClass(Collection<org.junit.runners.model.FrameworkMethod> filteredTests) protected voidResets System properties.voidtestFailure(org.junit.runner.notification.Failure failure) You can override this method to be informed when a test fails.protected voidtweakConfigurations(org.spincast.core.guice.GuiceTweaker guiceTweaker) protected voidvalidateCreatedInjector(com.google.inject.Injector guice) Validates the created Injector, before the dependencies are injected in the test class.
-
Field Details
-
logger
protected static final org.slf4j.Logger logger -
spincastConfig
@Inject protected org.spincast.core.config.SpincastConfig spincastConfig
-
-
Constructor Details
-
SpincastTestBase
public SpincastTestBase()
-
-
Method Details
-
isTestClassDisabledPreBeforeClass
public boolean isTestClassDisabledPreBeforeClass(Collection<org.junit.runners.model.FrameworkMethod> filteredTests) - Specified by:
isTestClassDisabledPreBeforeClassin interfaceorg.spincast.testing.junitrunner.CanBeDisabled
-
isTestClassDisabledPostBeforeClass
public boolean isTestClassDisabledPostBeforeClass()- Specified by:
isTestClassDisabledPostBeforeClassin interfaceorg.spincast.testing.junitrunner.CanBeDisabled
-
beforeClass
public void beforeClass()- Specified by:
beforeClassin interfaceorg.spincast.testing.junitrunner.BeforeAfterClassMethodsProvider
-
addExtraSystemProperties
protected void addExtraSystemProperties()Adds System properties as they are provided by thegetExtraSystemProperties()method. -
getExtraSystemProperties
Extra System properties to set before the tests are run. Those will be automatically reset once the tests are done. -
getExtraExactBindingsToRemoveBeforePlugins
Extra exact bindings to remvoe before the plugins are applied. -
resetSystemProperties
protected void resetSystemProperties()Resets System properties. -
getGuiceTweakerFromThreadLocal
protected org.spincast.core.guice.GuiceTweaker getGuiceTweakerFromThreadLocal() -
validateCreatedInjector
protected void validateCreatedInjector(com.google.inject.Injector guice) Validates the created Injector, before the dependencies are injected in the test class. -
createGuiceTweaker
protected org.spincast.core.guice.GuiceTweaker createGuiceTweaker() -
getGuiceTweakerPluginsToDisable
Ids of plugins to disable.Example:
Set
pluginIdsToIgnore = super.getGuiceTweakerPluginsToDisable(); pluginIdsToIgnore.add(XXXXXX); return pluginIdsToIgnore; -
tweakConfigurations
protected void tweakConfigurations(org.spincast.core.guice.GuiceTweaker guiceTweaker) -
isDisableBindCurrentClass
protected boolean isDisableBindCurrentClass() -
getGuiceTweakerExtraPlugins
Extra plugins to be added by the Guice Tweaker. -
getGuiceTweakerExtraOverridingModule
protected com.google.inject.Module getGuiceTweakerExtraOverridingModule()If an overriding Module is to be added using the Guice tweaker.Can be overriden with something like :
return Modules.override(super.getGuiceTweakerExtraOverridingModule()).with(new SpincastGuiceModuleBase() { protected void configure() { // ... } }); -
getTestingConfigImplementationClass
protected Class<? extends org.spincast.core.config.SpincastConfig> getTestingConfigImplementationClass()The implementation to use for theSpincastConfigbinding, when running tests. -
beforeTest
public void beforeTest()This method will be called before each test. -
afterTest
public void afterTest()This method will be called after each test. -
afterClass
public void afterClass()- Specified by:
afterClassin interfaceorg.spincast.testing.junitrunner.BeforeAfterClassMethodsProvider
-
beforeClassException
- Specified by:
beforeClassExceptionin interfaceorg.spincast.testing.junitrunner.BeforeAfterClassMethodsProvider
-
afterClassLoops
public void afterClassLoops()- Specified by:
afterClassLoopsin interfaceorg.spincast.testing.junitrunner.RepeatedClassAfterMethodProvider
-
testFailure
public void testFailure(org.junit.runner.notification.Failure failure) You can override this method to be informed when a test fails.- Specified by:
testFailurein interfaceorg.spincast.testing.junitrunner.TestFailureListener
-
getInjector
protected com.google.inject.Injector getInjector()Returns the Guice injector. -
deleteTestingWritableTempDir
protected void deleteTestingWritableTempDir()Deletes the testing writable temp directory. -
getTestingWritableTempDir
Returns the directory that can be used to create files and subdirectories during testing.This directory will be deleted when the tests are done.
-
getSpincastConfig
protected org.spincast.core.config.SpincastConfig getSpincastConfig() -
createTestingFilePath
Returns the absolute path to use, given the relative one, to create a temporary test file.This file will be deleted when the tests are done.
-
createTestingFilePath
Returns a unique path to use to create a temporary test file.This file will be deleted when the tests are done.
-
createTestingDir
Create a temp directory.This directory will be deleted when the tests are done.
-
createInjector
protected abstract com.google.inject.Injector createInjector()The test class must implement this method to create the Guice injector. It can be done by starting a real application (with amain(...)method) or by creating a custom Injector.
-