public abstract class SpincastTestBase extends Object implements BeforeAfterClassMethodsProvider, TestFailureListener, RepeatedClassAfterMethodProvider
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.
The NAME_ASCENDING option is used to sort the tests. This means you can force the order in which tests are run by prefixeing them with something like : "t01_firstTest", "t02_secondTest", etc.
A GuiceTweaker instance is used to
be able to tweak a Guice context automagaically. This for example
allows you to start your actual application, using its main() method,
but still be able to mock some components for testing purposes. A
Guice tweaker is enabled by default if your test class extend this
base class. If SpincastConfig is bound, its method will be automatically
intercepted and testing values are going to be used instead (by default using the
SpincastConfigTestingDefault class).
Note that the Guice tweaker only works when the Guice context is created
using the Spincast class or the SpincastBootstrapper
classes from the spincast-default artifact.
| Constructor and Description |
|---|
SpincastTestBase() |
| Modifier and Type | Method and Description |
|---|---|
void |
afterClass()
Called after the tests of the class are ran.
|
void |
afterClassLoops()
Called after all the loops of the class
as specified by the @repeat annotation.
|
void |
afterTest() |
void |
beforeClass()
Called before the tests of the class are ran.
|
void |
beforeTest() |
protected GuiceTweaker |
createGuiceTweaker()
Create the Guice Tweaker.
|
protected abstract com.google.inject.Injector |
createInjector()
The test class must implement this method to create
the Guice injector.
|
protected String |
createTestingFilePath()
Create a temporary test file.
|
protected String |
createTestingFilePath(String relativePath)
Create a temporary test file, using the given relative path.
|
protected void |
deleteTempDir() |
protected List<SpincastPlugin> |
getGuiceTweakerExtraPlugins()
The extra plugins added by the Guice Tweaker.
|
protected com.google.inject.Injector |
getInjector() |
protected SpincastConfig |
getSpincastConfig() |
protected Class<? extends SpincastConfigTesting> |
getSpincastConfigTestingImplementation()
The testing configuration class implementation to use.
|
protected GuiceTweaker |
getSpincastPluginFromThreadLocal() |
protected File |
getTestingWritableDir() |
protected boolean |
isEnableGuiceTweaker()
Should a GuiceTweaker ThreadLocal be
created?
|
protected boolean |
isEnableGuiceTweakerExtraPlugins()
Should we add the plugings n general required during
testing?
|
protected boolean |
isEnableGuiceTweakerTestingConfigMecanism()
If
true, a AOP interceptor will be
bound so a call to any of any of SpincastConfig's
method will be intercepted and will use the
methods from the testing config instead,
as returned by getSpincastConfigTestingImplementation(). |
protected void |
setSpincastConfig(SpincastConfig spincastConfig) |
protected void |
setupSpincastConfigTesting(GuiceTweaker guiceTweaker)
Adds an OAP interceptor so calls to methods of the original
SpincastConfig onject will be redirected to the
testing version (as returned by getSpincastConfigTestingImplementation()). |
void |
testFailure(org.junit.runner.notification.Failure failure)
You can override this method to be
informed when a test fails.
|
protected boolean isEnableGuiceTweaker()
Is true by default.
protected boolean isEnableGuiceTweakerTestingConfigMecanism()
true, a AOP interceptor will be
bound so a call to any of any of SpincastConfig's
method will be intercepted and will use the
methods from the testing config instead,
as returned by getSpincastConfigTestingImplementation().
Is true by default.
protected boolean isEnableGuiceTweakerExtraPlugins()
Is true by default.
public void beforeClass()
BeforeAfterClassMethodsProviderbeforeClass in interface BeforeAfterClassMethodsProviderprotected GuiceTweaker createGuiceTweaker()
This is only useful when the Guice Injector is created
starting with Spincast.configure(...). If
you create the Guice Injector by yourself, using
Guice.createInjector(...), this won't
have any effect.
protected List<SpincastPlugin> getGuiceTweakerExtraPlugins()
protected Class<? extends SpincastConfigTesting> getSpincastConfigTestingImplementation()
isEnableGuiceTweakerTestingConfigMecanism() if you
want to disable this class from being used.protected void setupSpincastConfigTesting(GuiceTweaker guiceTweaker)
SpincastConfig onject will be redirected to the
testing version (as returned by getSpincastConfigTestingImplementation()).protected GuiceTweaker getSpincastPluginFromThreadLocal()
public void beforeTest()
public void afterTest()
public void afterClass()
BeforeAfterClassMethodsProviderThis will only be called if the beforeClass() method completed successfully, so you can be sure that the instanciation of the class is complete here.
afterClass in interface BeforeAfterClassMethodsProviderpublic void afterClassLoops()
RepeatedClassAfterMethodProviderThis will only be called if the beforeClass() method completed successfully, so you can be sure that the instanciation of the class is complete here.
afterClassLoops in interface RepeatedClassAfterMethodProviderpublic void testFailure(org.junit.runner.notification.Failure failure)
testFailure in interface TestFailureListener@Inject protected void setSpincastConfig(SpincastConfig spincastConfig)
protected SpincastConfig getSpincastConfig()
protected com.google.inject.Injector getInjector()
protected void deleteTempDir()
protected File getTestingWritableDir()
protected String createTestingFilePath(String relativePath)
protected String createTestingFilePath()
protected abstract com.google.inject.Injector createInjector()
main(...) method) or by
creating a custom Injector.Copyright © 2017. All rights reserved.