public.javadoc.org.spincast.testing.core.SpincastTestBase.html Maven / Gradle / Ivy
Show all versions of spincast-website Show documentation
SpincastTestBase (org.spincast:spincast-framework 1.0.0 API)
org.spincast.testing.core
Class SpincastTestBase
- java.lang.Object
-
- org.spincast.testing.core.SpincastTestBase
-
- All Implemented Interfaces:
- BeforeAfterClassMethodsProvider, RepeatedClassAfterMethodProvider, TestFailureListener
- Direct Known Subclasses:
- AppBasedTestingBase, NoAppCustomContextTypesTestingBase
public abstract class SpincastTestBase
extends Object
implements BeforeAfterClassMethodsProvider, TestFailureListener, RepeatedClassAfterMethodProvider
Base class for Spincast test classes.
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
Fields
Modifier and Type
Field and Description
protected org.slf4j.Logger
logger
protected SpincastConfig
spincastConfig
-
Constructor Summary
Constructors
Constructor and Description
SpincastTestBase()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods
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()
This method will be called after each test.
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()
This method will be called before each test.
protected GuiceTweaker
createGuiceTweaker()
protected abstract com.google.inject.Injector
createInjector()
The test class must implement this method to create
the Guice injector.
protected File
createTestingDir()
Create a temp directory.
protected String
createTestingFilePath()
Returns a unique path to use to create a temporary test file.
protected String
createTestingFilePath(String relativePath)
Returns the absolute path to use, given the relative one,
to create a temporary test file.
protected void
deleteTestingWritableTempDir()
Deletes the testing writable temp directory.
protected Set<com.google.inject.Key<?>>
getExtraExactBindingsToRemoveBeforePlugins()
Extra exact bindings to remvoe before the
plugins are applied.
protected Map<String,String>
getExtraSystemProperties()
Extra System properties to set before the tests are run.
protected com.google.inject.Module
getGuiceTweakerExtraOverridingModule()
If an overriding Module is to be added using the
Guice tweaker.
protected List<SpincastPlugin>
getGuiceTweakerExtraPlugins()
Extra plugins to be added by the Guice Tweaker.
protected GuiceTweaker
getGuiceTweakerFromThreadLocal()
protected com.google.inject.Injector
getInjector()
Returns the Guice injector.
protected SpincastConfig
getSpincastConfig()
protected Class<? extends SpincastConfig>
getTestingConfigImplementationClass()
The implementation to use for the SpincastConfig
binding,
when running tests.
protected File
getTestingWritableTempDir()
Returns the directory that can be used to create files
and subdirectories during testing.
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
tweakConfigurations(GuiceTweaker guiceTweaker)
protected void
validateCreatedInjector(com.google.inject.Injector guice)
Validates the created Injector, before the
dependencies are injected in the test class.
-
-
Field Detail
-
logger
protected final org.slf4j.Logger logger
-
spincastConfig
@Inject
protected SpincastConfig spincastConfig
-
Method Detail
-
beforeClass
public void beforeClass()
Description copied from interface: BeforeAfterClassMethodsProvider
Called before the tests of the class are ran.
- Specified by:
beforeClass
in interface BeforeAfterClassMethodsProvider
-
addExtraSystemProperties
protected void addExtraSystemProperties()
Adds System properties as they are provided by the
getExtraSystemProperties()
method.
-
getExtraSystemProperties
protected Map<String,String> getExtraSystemProperties()
Extra System properties to set before the tests are run.
Those will be automatically reset once the tests are done.
-
getExtraExactBindingsToRemoveBeforePlugins
protected Set<com.google.inject.Key<?>> getExtraExactBindingsToRemoveBeforePlugins()
Extra exact bindings to remvoe before the
plugins are applied.
-
resetSystemProperties
protected void resetSystemProperties()
Resets System properties.
-
getGuiceTweakerFromThreadLocal
protected 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 GuiceTweaker createGuiceTweaker()
-
tweakConfigurations
protected void tweakConfigurations(GuiceTweaker guiceTweaker)
-
isDisableBindCurrentClass
protected boolean isDisableBindCurrentClass()
-
getGuiceTweakerExtraPlugins
protected List<SpincastPlugin> 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 SpincastConfig> getTestingConfigImplementationClass()
The implementation to use for the SpincastConfig
binding,
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()
Description copied from interface: BeforeAfterClassMethodsProvider
Called after the tests of the class are ran.
This will only be called if the beforeClass()
method completed successfully, so you can be sure that
the instanciation of the class is complete here.
- Specified by:
afterClass
in interface BeforeAfterClassMethodsProvider
-
beforeClassException
public void beforeClassException(Throwable ex)
Description copied from interface: BeforeAfterClassMethodsProvider
This method will be called if an exception occures during
the BeforeAfterClassMethodsProvider.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!
- Specified by:
beforeClassException
in interface BeforeAfterClassMethodsProvider
-
afterClassLoops
public void afterClassLoops()
Description copied from interface: RepeatedClassAfterMethodProvider
Called after all the loops of the class
as specified by the @repeat annotation.
This will only be called if the beforeClass()
method completed successfully, so you can be sure that
the instanciation of the class is complete here.
- Specified by:
afterClassLoops
in interface 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:
testFailure
in interface TestFailureListener
-
getInjector
protected com.google.inject.Injector getInjector()
Returns the Guice injector.
-
deleteTestingWritableTempDir
protected void deleteTestingWritableTempDir()
Deletes the testing writable temp directory.
-
getTestingWritableTempDir
protected File 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 SpincastConfig getSpincastConfig()
-
createTestingFilePath
protected String createTestingFilePath(String relativePath)
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
protected String createTestingFilePath()
Returns a unique path to use to create a temporary test file.
This file will be deleted when the tests are done.
-
createTestingDir
protected File 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 a main(...)
method) or by
creating a custom Injector.
Copyright © 2019. All rights reserved.