AbstractJUnit4SpringContextTests
)@Deprecated public abstract class AbstractDependencyInjectionSpringContextTests extends AbstractSingleSpringContextTests
Convenient superclass for JUnit 3.8 based tests depending on a Spring context. The test instance itself is populated by Dependency Injection.
Really for integration testing, not unit testing. You should not normally use the Spring container for unit tests: simply populate your POJOs in plain JUnit tests!
This supports two modes of populating the test:
populateProtectedVariables
property to true
in
the constructor to switch on Field Injection.
AbstractSingleSpringContextTests.setDirty()
,
AbstractSingleSpringContextTests.contextKey()
,
AbstractSpringContextTests.getContext(java.lang.Object)
,
AbstractSingleSpringContextTests.getConfigLocations()
Modifier and Type | Field and Description |
---|---|
static int |
AUTOWIRE_BY_NAME
Deprecated.
Constant that indicates autowiring bean properties by name.
|
static int |
AUTOWIRE_BY_TYPE
Deprecated.
Constant that indicates autowiring bean properties by type.
|
static int |
AUTOWIRE_NO
Deprecated.
Constant that indicates no autowiring at all.
|
applicationContext
logger
Constructor and Description |
---|
AbstractDependencyInjectionSpringContextTests()
Deprecated.
Default constructor for AbstractDependencyInjectionSpringContextTests.
|
AbstractDependencyInjectionSpringContextTests(String name)
Deprecated.
Constructor for AbstractDependencyInjectionSpringContextTests with a
JUnit name.
|
Modifier and Type | Method and Description |
---|---|
int |
getAutowireMode()
Deprecated.
Return the autowire mode for test properties set by Dependency Injection.
|
protected void |
injectDependencies()
Deprecated.
Inject dependencies into 'this' instance (that is, this test instance).
|
boolean |
isDependencyCheck()
Deprecated.
Return whether or not dependency checking should be performed for test
properties set by Dependency Injection.
|
boolean |
isPopulateProtectedVariables()
Deprecated.
Return whether to populate protected variables of this test case.
|
protected void |
prepareTestInstance()
Deprecated.
Prepare this test instance, injecting dependencies into its protected
fields and its bean properties.
|
void |
setAutowireMode(int autowireMode)
Deprecated.
Set the autowire mode for test properties set by Dependency Injection.
|
void |
setDependencyCheck(boolean dependencyCheck)
Deprecated.
Set whether or not dependency checking should be performed for test
properties set by Dependency Injection.
|
void |
setPopulateProtectedVariables(boolean populateFields)
Deprecated.
Set whether to populate protected variables of this test case.
|
contextKey, createApplicationContext, createBeanDefinitionReader, customizeBeanFactory, getApplicationContext, getConfigLocations, getConfigPath, getConfigPaths, getLoadCount, loadContext, loadContextLocations, onSetUp, onTearDown, prepareApplicationContext, setDirty, setUp, tearDown
addContext, contextKeyString, getContext, hasCachedContext, isContextKeyEmpty, setDirty
getDisabledTestCount, isDisabledInThisEnvironment, recordDisabled, runBare
countTestCases, createResult, getName, run, run, runTest, setName, toString
assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertFalse, assertFalse, assertNotNull, assertNotNull, assertNotSame, assertNotSame, assertNull, assertNull, assertSame, assertSame, assertTrue, assertTrue, fail, fail, failNotEquals, failNotSame, failSame, format
public static final int AUTOWIRE_NO
setAutowireMode(int)
,
Constant Field Valuespublic static final int AUTOWIRE_BY_NAME
setAutowireMode(int)
,
Constant Field Valuespublic static final int AUTOWIRE_BY_TYPE
setAutowireMode(int)
,
Constant Field Valuespublic AbstractDependencyInjectionSpringContextTests()
public AbstractDependencyInjectionSpringContextTests(String name)
name
- the name of this text fixturepublic final void setPopulateProtectedVariables(boolean populateFields)
false
.public final boolean isPopulateProtectedVariables()
public final void setAutowireMode(int autowireMode)
The default is AUTOWIRE_BY_TYPE
. Can be set to
AUTOWIRE_BY_NAME
or AUTOWIRE_NO
instead.
AUTOWIRE_BY_TYPE
,
AUTOWIRE_BY_NAME
,
AUTOWIRE_NO
public final int getAutowireMode()
public final void setDependencyCheck(boolean dependencyCheck)
The default is true
, meaning that tests cannot be run
unless all properties are populated.
public final boolean isDependencyCheck()
protected void prepareTestInstance() throws Exception
Note: if the ApplicationContext
for this test instance has not
been configured (e.g., is null
), dependency injection
will naturally not be performed, but an informational
message will be written to the log.
prepareTestInstance
in class AbstractSingleSpringContextTests
Exception
- in case of preparation failureinjectDependencies()
protected void injectDependencies() throws Exception
The default implementation populates protected variables if the
appropriate flag is set
, else uses
autowiring if autowiring is switched on (which it is by default).
Override this method if you need full control over how dependencies are injected into the test instance.
Exception
- in case of dependency injection failureIllegalStateException
- if the ApplicationContext
for this
test instance has not been configuredpopulateProtectedVariables()