public class DataDrivenTestRunner
extends org.junit.runners.BlockJUnit4ClassRunner
BlockJUnit4ClassRunner. The algorithm of
constructing and making the runner ready for execution is as follows:SchedulerStrategy can be PARALLEL or SERIAL and is decided
based on Parallel annotationTestConfigProvider
annotation.TestConfigUtil.loadTestBeanConfig(Class)) method.DataLoaderUtil.loadData(java.lang.Class<?>, org.junit.runners.model.FrameworkMethod, org.junit.runners.model.TestClass, java.util.Map<java.lang.String, java.util.List<java.util.Map<java.lang.String, java.lang.Object>>>)) method.Converters annotationProvided or Inject annotation
with the test beans that were loaded in step 1 above.TestProperties
annotation.TestProperties annotation requires a filed of type Properties be defined at the class
level. Look at TestConfigUtil.loadResourceProperties(Class, Object) method for details.Intercept annotation. This helps
in intercepting the method calls to the class under test and perform any initialization/destruction logic
before/after the method execution.| Constructor and Description |
|---|
DataDrivenTestRunner(Class<?> klass)
Look at
DataDrivenTestRunner for details. |
| Modifier and Type | Method and Description |
|---|---|
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.
|
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(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(EasyFrameworkMethod method,
org.junit.runners.model.Statement statement) |
collectInitializationErrors, describeChild, getChildren, getTestRules, possiblyExpectingExceptions, rules, runChild, validateNoNonStaticInnerClass, validateOnlyOneConstructor, validateZeroArgConstructor, withAfters, withBefores, withPotentialTimeoutpublic DataDrivenTestRunner(Class<?> klass) throws org.junit.runners.model.InitializationError
DataDrivenTestRunner for details.klass - org.junit.runners.model.InitializationErrorDataDrivenTestRunnerprotected 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.FrameworkMethodprotected Object getTestInstance() throws InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException
InstantiationExceptionIllegalAccessExceptionIllegalArgumentExceptionInvocationTargetExceptionprotected void loadTestConfigurations(Object testInstance)
protected void loadResourceProperties(Object testInstance)
protected List<org.junit.runners.model.FrameworkMethod> computeTestMethods()
computeTestMethods in class org.junit.runners.BlockJUnit4ClassRunnerFrameworkMethodspublic void filter(org.junit.runner.manipulation.Filter filter)
throws org.junit.runner.manipulation.NoTestsRemainException
ParentRunner so that individual tests can be run using EasyTestfilter in interface org.junit.runner.manipulation.Filterablefilter in class org.junit.runners.ParentRunner<org.junit.runners.model.FrameworkMethod>filter - org.junit.runner.manipulation.NoTestsRemainExceptionprotected void instrumentClass(Class<?> testClass, Object testInstance) throws IllegalArgumentException, IllegalAccessException, InstantiationException
Intercept annotationtestClass - the class under testIllegalArgumentException - if an exception occurredIllegalAccessException - if an exception occurredInstantiationException - if an exception occurredpublic void registerConverter(Converters converter)
converter - the annotation Convertersprotected String testName(org.junit.runners.model.FrameworkMethod method)
testName in class org.junit.runners.BlockJUnit4ClassRunnermethod - the FrameworkMethodprotected 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.junit.runners.BlockJUnit4ClassRunnerprotected org.junit.runners.model.Statement withTestResult(EasyFrameworkMethod method, org.junit.runners.model.Statement statement)
protected Object createTest() throws Exception
createTest in class org.junit.runners.BlockJUnit4ClassRunnerExceptionprotected org.junit.runners.model.Statement methodInvoker(org.junit.runners.model.FrameworkMethod method,
Object testInstance)
Statement that invokes method on testmethodInvoker 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.junit.runners.ParentRunner<org.junit.runners.model.FrameworkMethod>Copyright © 2014. All rights reserved.