java.lang.Object | ||
↳ | BlockJUnit4ClassRunner | |
↳ | org.springframework.test.context.junit4.SpringJUnit4ClassRunner |
SpringJUnit4ClassRunner
is a custom extension of
BlockJUnit4ClassRunner which provides functionality of the
Spring TestContext Framework to standard JUnit 4.5+ tests by means
of the TestContextManager
and associated support classes and
annotations.
The following list constitutes all annotations currently supported directly
by SpringJUnit4ClassRunner
.
(Note that additional annotations may be supported by various
TestExecutionListeners
)
@ExpectedException
@Timed
@Repeat
@ProfileValueSourceConfiguration
@IfProfileValue
NOTE: As of Spring 3.0, SpringJUnit4ClassRunner
requires
JUnit 4.5+.
Public Constructors | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Constructs a new
SpringJUnit4ClassRunner and initializes a
TestContextManager to provide Spring testing functionality to
standard JUnit tests. |
Public Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Returns a description suitable for an ignored test class if the test is
disabled via
@IfProfileValue at the class-level, and
otherwise delegates to the parent implementation. | |||||||||||
Check whether the test is enabled in the first place.
|
Protected Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Delegates to the parent implementation for creating the test instance and
then allows the
TestContextManager to
prepare the test instance before returning it. | |||||||||||
Creates a new
TestContextManager for the supplied test class and
the configured default ContextLoader class name. | |||||||||||
Get the name of the default
ContextLoader class to use for
the supplied test class. | |||||||||||
Get the
exception that the supplied FrameworkMethod
test method is expected to throw. | |||||||||||
Retrieves the configured JUnit
timeout from the Test
@Test annotation on the supplied FrameworkMethod test
method. | |||||||||||
Retrieves the configured Spring-specific
timeout from the
@Timed annotation on the supplied
FrameworkMethod test method. | |||||||||||
Get the
TestContextManager associated with this runner. | |||||||||||
Returns
true if Ignore @Ignore is present for
the supplied FrameworkMethod test method or if the test method is
disabled via @IfProfileValue . | |||||||||||
Augments the default JUnit behavior
with
potential repeats of the entire execution chain. | |||||||||||
Performs the same logic as
BlockJUnit4ClassRunner#possiblyExpectingExceptions(FrameworkMethod, Object, Statement)
except that the expected exception is retrieved using
getExpectedException(FrameworkMethod) . | |||||||||||
Performs the same logic as
BlockJUnit4ClassRunner#runChild(FrameworkMethod, RunNotifier),
except that tests are determined to be ignored by
isTestMethodIgnored(FrameworkMethod) . | |||||||||||
Wraps the Statement returned by the parent implementation with a
RunAfterTestClassCallbacks statement, thus preserving the default
functionality but adding support for the Spring TestContext Framework. | |||||||||||
Wraps the Statement returned by the parent implementation with a
RunAfterTestMethodCallbacks statement, thus preserving the
default functionality but adding support for the Spring TestContext
Framework. | |||||||||||
Wraps the Statement returned by the parent implementation with a
RunBeforeTestClassCallbacks statement, thus preserving the
default functionality but adding support for the Spring TestContext
Framework. | |||||||||||
Wraps the Statement returned by the parent implementation with a
RunBeforeTestMethodCallbacks statement, thus preserving the
default functionality but adding support for the Spring TestContext
Framework. | |||||||||||
Supports Spring's
@Repeat annotation by returning a
SpringRepeat statement initialized with the configured repeat
count or 1 if no repeat count is configured. | |||||||||||
Supports both Spring's
@Timed and JUnit's
Test#timeout() @Test(timeout=...) annotations, but not both
simultaneously. |
[Expand]
Inherited Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
From class
java.lang.Object
|
Constructs a new SpringJUnit4ClassRunner
and initializes a
TestContextManager
to provide Spring testing functionality to
standard JUnit tests.
clazz | the test class to be run |
---|
InitializationError |
---|
Returns a description suitable for an ignored test class if the test is
disabled via @IfProfileValue
at the class-level, and
otherwise delegates to the parent implementation.
Check whether the test is enabled in the first place. This prevents
classes with a non-matching @IfProfileValue
annotation
from running altogether, even skipping the execution of
prepareTestInstance()
TestExecutionListener
methods.
Delegates to the parent implementation for creating the test instance and
then allows the TestContextManager
to
prepare the test instance before returning it.
Exception |
---|
Creates a new TestContextManager
for the supplied test class and
the configured default ContextLoader
class name.
Can be overridden by subclasses.
clazz | the test class to be managed |
---|
Get the name of the default ContextLoader
class to use for
the supplied test class. The named class will be used if the test class
does not explicitly declare a ContextLoader
class via the
@ContextConfiguration
annotation.
The default implementation returns null
, thus implying use
of the standard default ContextLoader
class name.
Can be overridden by subclasses.
clazz | the test class |
---|
null
Get the exception
that the supplied FrameworkMethod
test method is expected to throw.
Supports both Spring's @ExpectedException(...)
and JUnit's Test#expected() @Test(expected=...) annotations, but
not both simultaneously.
null
if none was
specified
Retrieves the configured JUnit timeout
from the Test
@Test annotation on the supplied FrameworkMethod test
method.
0
if none was specified.
Retrieves the configured Spring-specific timeout
from the
@Timed
annotation on the supplied
FrameworkMethod test method.
0
if none was specified.
Get the TestContextManager
associated with this runner.
Returns true
if Ignore @Ignore is present for
the supplied FrameworkMethod test method or if the test method is
disabled via @IfProfileValue
.
Augments the default JUnit behavior
with
potential repeats
of the entire execution chain.
Furthermore, support for timeouts has been moved down the execution chain
in order to include execution of org.junit.Before @Before
and org.junit.After @After methods within the timed
execution. Note that this differs from the default JUnit behavior of
executing @Before
and @After
methods
in the main thread while executing the actual test method in a separate
thread. Thus, the end effect is that @Before
and
@After
methods will be executed in the same thread as
the test method. As a consequence, JUnit-specified timeouts will work
fine in combination with Spring transactions. Note that JUnit-specific
timeouts still differ from Spring-specific timeouts in that the former
execute in a separate thread while the latter simply execute in the main
thread (like regular tests).
Performs the same logic as
BlockJUnit4ClassRunner#possiblyExpectingExceptions(FrameworkMethod, Object, Statement)
except that the expected exception is retrieved using
getExpectedException(FrameworkMethod)
.
Performs the same logic as
BlockJUnit4ClassRunner#runChild(FrameworkMethod, RunNotifier),
except that tests are determined to be ignored by
isTestMethodIgnored(FrameworkMethod)
.
Wraps the Statement returned by the parent implementation with a
RunAfterTestClassCallbacks
statement, thus preserving the default
functionality but adding support for the Spring TestContext Framework.
Wraps the Statement returned by the parent implementation with a
RunAfterTestMethodCallbacks
statement, thus preserving the
default functionality but adding support for the Spring TestContext
Framework.
Wraps the Statement returned by the parent implementation with a
RunBeforeTestClassCallbacks
statement, thus preserving the
default functionality but adding support for the Spring TestContext
Framework.
Wraps the Statement returned by the parent implementation with a
RunBeforeTestMethodCallbacks
statement, thus preserving the
default functionality but adding support for the Spring TestContext
Framework.
Supports Spring's @Repeat
annotation by returning a
SpringRepeat
statement initialized with the configured repeat
count or 1
if no repeat count is configured.
Supports both Spring's @Timed
and JUnit's
Test#timeout() @Test(timeout=...) annotations, but not both
simultaneously. Returns either a SpringFailOnTimeout
, a
FailOnTimeout, or the unmodified, supplied Statement as
appropriate.