|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.junit.runner.Runner
org.junit.runners.ParentRunner<org.junit.runners.model.FrameworkMethod>
org.junit.runners.BlockJUnit4ClassRunner
org.springframework.test.context.junit4.SpringJUnit4ClassRunner
org.easetech.easytest.runner.SpringTestRunner
public class SpringTestRunner
A SpringJUnit4ClassRunner Runner extension that adds support of input parameters as part of the Test
annotation. This SpringJUnit4ClassRunner extension is modified for providing convenient Data Driven Testing
support to its users. This Runner is capable of generating new instances of FrameworkMethod based on the test
data for a given method. For eg. If there is a method "testMethod(String testData)" that has three sets of test data
: [{"testData1"},{"testData2"},{"testData3"}], then this runner will generate three FrameworkMethod instances
with the method names :
testMethod{testData1}
testMethod{testData2}
and
testMethod{testData3}
A user can specify the test data at the class level, using the DataLoader annotation and override it at
the method level. The Runner will take care of executing the test method with the right test data.
This is extremely beneficial in cases, where the user just wants to load the data once and then reuse it for all the
test methods. If the user wants, then he can always override the test data at the method level by specifying the
DataLoader annotation at the method level.
In addition, this runner also introduces a new way for the user to specify the test data using DataLoader
annotation.
There is also a Param annotation to handle boiler plate tasks on behalf of the user as well as supports
additional functionality that eases the life of the user. For eg. it supports Java PropertyEditors to automatically
convert a String to the specified Object. It also supports passing a Map to the test method that contains all the
available test data key / value pairs for easy consumption by the user. It also supports user defined custom Objects
as parameters.
| Field Summary | |
|---|---|
protected static org.slf4j.Logger |
LOG
An instance of logger associated with the test framework. |
| Constructor Summary | |
|---|---|
SpringTestRunner(Class<?> clazz)
Construct a new NewSpringTestRunner |
|
| Method Summary | |
|---|---|
protected List<org.junit.runners.model.FrameworkMethod> |
computeMethodsForTest()
Overridden the compute test method to make it save the method list as class instance, so that the method does not run multiple times. |
protected List<org.junit.runners.model.FrameworkMethod> |
computeTestMethods()
Compute any test methods |
protected Object |
createTest()
Returns a new fixture for running a test. |
protected ClassLoader |
determineClassLoader(Class<?> fieldType,
Class<?> testClass)
Determine the right class loader to use to load the class |
void |
filter(org.junit.runner.manipulation.Filter filter)
Override the filter method from ParentRunner so that individual tests can be run using EasyTest |
protected Object |
getTestInstance()
Get the instance of the class under test |
protected void |
instrumentClass(Class<?> testClass,
Object testInstance)
Instrument the class's field that are marked with Intercept annotation |
protected void |
loadResourceProperties(Object testInstance)
|
protected void |
loadTestConfigurations(Object testInstance)
|
protected org.junit.runners.model.Statement |
methodBlock(org.junit.runners.model.FrameworkMethod method)
|
protected org.junit.runners.model.Statement |
methodInvoker(org.junit.runners.model.FrameworkMethod method,
Object testInstance)
Returns a Statement that invokes method on test |
void |
registerConverter(org.easetech.easytest.annotation.Converters converter)
Method responsible for registering the converters with the EasyTest framework |
protected void |
setSchedulingStrategy()
Set whether the tests should be run in parallel or serial. |
protected String |
testName(org.junit.runners.model.FrameworkMethod method)
Override the name of the test. |
protected void |
validateConstructor(List<Throwable> errors)
Validate that there could ever be only one constructor. |
protected void |
validateInstanceMethods(List<Throwable> errors)
Deprecated. unused API, will go away in future version |
protected void |
validateTestMethods(List<Throwable> errors)
Validate the test methods. |
protected org.junit.runners.model.Statement |
withAfterClasses(org.junit.runners.model.Statement statement)
Returns a Statement: run all non-overridden @AfterClass methods on this class and superclasses
before executing statement; all AfterClass methods are always executed: exceptions thrown by previous
steps are combined, if necessary, with exceptions from AfterClass methods into a MultipleFailureException
. |
protected org.junit.runners.model.Statement |
withTestResult(org.easetech.easytest.runner.EasyFrameworkMethod method,
org.junit.runners.model.Statement statement)
|
| Methods inherited from class org.springframework.test.context.junit4.SpringJUnit4ClassRunner |
|---|
createTestContextManager, getDefaultContextLoaderClassName, getDescription, getExpectedException, getJUnitTimeout, getSpringTimeout, getTestContextManager, isTestMethodIgnored, possiblyExpectingExceptions, run, runChild, withAfters, withBeforeClasses, withBefores, withPotentialRepeat, withPotentialTimeout |
| Methods inherited from class org.junit.runners.BlockJUnit4ClassRunner |
|---|
collectInitializationErrors, describeChild, getChildren, getTestRules, rules, validateNoNonStaticInnerClass, validateOnlyOneConstructor, validateZeroArgConstructor |
| Methods inherited from class org.junit.runners.ParentRunner |
|---|
childrenInvoker, classBlock, classRules, getName, getRunnerAnnotations, getTestClass, runLeaf, setScheduler, sort, validatePublicVoidNoArgMethods |
| Methods inherited from class org.junit.runner.Runner |
|---|
testCount |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
protected static final org.slf4j.Logger LOG
| Constructor Detail |
|---|
public SpringTestRunner(Class<?> clazz)
throws org.junit.runners.model.InitializationError
clazz -
org.junit.runners.model.InitializationError| Method Detail |
|---|
protected void setSchedulingStrategy()
protected List<org.junit.runners.model.FrameworkMethod> computeMethodsForTest()
FrameworkMethod instances
for a given method with multiple test data. So, if a given test method needs to run three times with three set of
input test data, then this method will actually create three instances of FrameworkMethod. In order to
allow the user to override the default name, FrameworkMethod is extended with EasyFrameworkMethod
and EasyFrameworkMethod.setName(String) method introduced.
FrameworkMethod
protected Object getTestInstance()
throws InstantiationException,
IllegalAccessException,
IllegalArgumentException,
InvocationTargetException
InstantiationException
IllegalAccessException
IllegalArgumentException
InvocationTargetExceptionprotected void loadTestConfigurations(Object testInstance)
TestConfigUtil.loadTestConfigurations(Class, Object)protected void loadResourceProperties(Object testInstance)
TestConfigUtil.loadResourceProperties(java.lang.Class>, java.lang.Object)protected List<org.junit.runners.model.FrameworkMethod> computeTestMethods()
computeTestMethods in class org.junit.runners.BlockJUnit4ClassRunnerFrameworkMethods
public void filter(org.junit.runner.manipulation.Filter filter)
throws org.junit.runner.manipulation.NoTestsRemainException
ParentRunner so that individual tests can be run using EasyTest
filter in interface org.junit.runner.manipulation.Filterablefilter in class org.junit.runners.ParentRunner<org.junit.runners.model.FrameworkMethod>filter -
org.junit.runner.manipulation.NoTestsRemainException
protected void instrumentClass(Class<?> testClass,
Object testInstance)
throws IllegalArgumentException,
IllegalAccessException,
org.springframework.aop.framework.AopConfigException,
InstantiationException
Intercept annotation
testClass - the class under test
IllegalArgumentException - if an exception occurred
IllegalAccessException - if an exception occurred
org.springframework.aop.framework.AopConfigException - if an exception occurred
InstantiationException - if an exception occurredpublic void registerConverter(org.easetech.easytest.annotation.Converters converter)
converter - the annotation Convertersprotected String testName(org.junit.runners.model.FrameworkMethod method)
testName in class org.junit.runners.BlockJUnit4ClassRunnermethod - the FrameworkMethod
protected void validateConstructor(List<Throwable> errors)
validateConstructor in class org.junit.runners.BlockJUnit4ClassRunnererrors - list of any errors while validating the Constructor@Deprecated protected void validateInstanceMethods(List<Throwable> errors)
errors for each method annotated with @Test, @Before, or @After that is
not a public, void instance method with no arguments.
validateInstanceMethods in class org.junit.runners.BlockJUnit4ClassRunnerprotected void validateTestMethods(List<Throwable> errors)
validateTestMethods in class org.junit.runners.BlockJUnit4ClassRunnererrors - list of any errors while validating test methodprotected org.junit.runners.model.Statement methodBlock(org.junit.runners.model.FrameworkMethod method)
methodBlock in class org.springframework.test.context.junit4.SpringJUnit4ClassRunner
protected org.junit.runners.model.Statement withTestResult(org.easetech.easytest.runner.EasyFrameworkMethod method,
org.junit.runners.model.Statement statement)
protected Object createTest()
throws Exception
createTest in class org.springframework.test.context.junit4.SpringJUnit4ClassRunnerException
protected org.junit.runners.model.Statement methodInvoker(org.junit.runners.model.FrameworkMethod method,
Object testInstance)
Statement that invokes method on test
methodInvoker in class org.junit.runners.BlockJUnit4ClassRunnerprotected org.junit.runners.model.Statement withAfterClasses(org.junit.runners.model.Statement statement)
Statement: run all non-overridden @AfterClass methods on this class and superclasses
before executing statement; all AfterClass methods are always executed: exceptions thrown by previous
steps are combined, if necessary, with exceptions from AfterClass methods into a MultipleFailureException
.
This method is also responsible for writing the data to the output file in case the user is returning test data
from the test method. This method will make sure that the data is written to the output file once after the
Runner has completed and not for every instance of the test method.
withAfterClasses in class org.springframework.test.context.junit4.SpringJUnit4ClassRunner
protected ClassLoader determineClassLoader(Class<?> fieldType,
Class<?> testClass)
fieldType - testClass -
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||