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.
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 .
| Modifier and Type | Field and Description |
|---|---|
protected org.slf4j.Logger |
logger |
protected SpincastConfig |
spincastConfig |
| Constructor and Description |
|---|
SpincastTestBase() |
| Modifier and Type | Method and Description |
|---|---|
protected void |
addExtraSystemProperties()
Adds System properties as they are provided by the
getExtraSystemProperties() method. |
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 |
beforeClassException(Throwable ex)
This method will be called if an exception occures during
the
BeforeAfterClassMethodsProvider.beforeClass() execution. |
void |
beforeTest() |
protected GuiceTweaker |
createGuiceTweaker() |
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 com.google.inject.Module |
getExtraOverridingModule()
If an overriding Module is to be added using the
Guice tweaker.
|
protected List<SpincastPlugin> |
getExtraPlugins()
Extra plugins to be added by the Guice Tweaker.
|
protected Map<String,String> |
getExtraSystemProperties()
Extra System properties to set before the tests are run.
|
protected GuiceTweaker |
getGuiceTweakerFromThreadLocal() |
protected com.google.inject.Injector |
getInjector() |
protected SpincastConfig |
getSpincastConfig() |
protected Class<? extends SpincastConfig> |
getTestingConfigImplementationClass()
The implementation to use for the
SpincastConfig binding,
when running tests. |
protected File |
getTestingWritableDir() |
protected boolean |
isDisableBindCurrentClass() |
protected void |
resetSystemProperties()
Resets System properties.
|
void |
testFailure(org.junit.runner.notification.Failure failure)
You can override this method to be
informed when a test fails.
|
protected void |
validateCreatedInjector(com.google.inject.Injector guice)
Validates the created Injector, before the
dependencies are injected in the test class.
|
protected final org.slf4j.Logger logger
@Inject protected SpincastConfig spincastConfig
public void beforeClass()
BeforeAfterClassMethodsProviderbeforeClass in interface BeforeAfterClassMethodsProviderprotected void addExtraSystemProperties()
getExtraSystemProperties() method.protected Map<String,String> getExtraSystemProperties()
protected void resetSystemProperties()
protected GuiceTweaker getGuiceTweakerFromThreadLocal()
protected void validateCreatedInjector(com.google.inject.Injector guice)
protected GuiceTweaker createGuiceTweaker()
protected boolean isDisableBindCurrentClass()
protected List<SpincastPlugin> getExtraPlugins()
Most of the time, you want to make sure you keep the plugins already added by base classes. For example :
List<SpincastPlugin> plugins = super.getGuiceTweakerPlugins();
plugins.add(new YourPlugin());
return plugins;
protected com.google.inject.Module getExtraOverridingModule()
protected Class<? extends SpincastConfig> getTestingConfigImplementationClass()
SpincastConfig binding,
when running tests.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 beforeClassException(Throwable ex)
BeforeAfterClassMethodsProviderBeforeAfterClassMethodsProvider.beforeClass() execution.
Be careful!! Here, you are pretty much certain that
the instanciation of the class was not succesful, so you
can't use any of its methods!beforeClassException 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 TestFailureListenerprotected com.google.inject.Injector getInjector()
protected void deleteTempDir()
protected File getTestingWritableDir()
protected SpincastConfig getSpincastConfig()
protected String createTestingFilePath(String relativePath)
protected String createTestingFilePath()
protected abstract com.google.inject.Injector createInjector()
main(...) method) or by
creating a custom Injector.Copyright © 2018. All rights reserved.