Package org.nuxeo.runtime.test.runner
Class FeaturesRunner
- java.lang.Object
-
- org.junit.runner.Runner
-
- org.junit.runners.ParentRunner<org.junit.runners.model.FrameworkMethod>
-
- org.junit.runners.BlockJUnit4ClassRunner
-
- org.nuxeo.runtime.test.runner.FeaturesRunner
-
- All Implemented Interfaces:
org.junit.runner.Describable
,org.junit.runner.manipulation.Filterable
,org.junit.runner.manipulation.Orderable
,org.junit.runner.manipulation.Sortable
- Direct Known Subclasses:
FeaturesRunnerWithParms
public class FeaturesRunner extends org.junit.runners.BlockJUnit4ClassRunner
A Test Case runner that can be extended through features and provide injection though Guice.- Author:
- Bogdan Stefanescu
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected class
FeaturesRunner.AfterClassStatement
protected class
FeaturesRunner.AfterMethodRunStatement
protected class
FeaturesRunner.AfterTeardownStatement
protected class
FeaturesRunner.BeforeClassStatement
protected class
FeaturesRunner.BeforeMethodRunStatement
protected class
FeaturesRunner.BeforeSetupStatement
protected static class
FeaturesRunner.Direction
protected static class
FeaturesRunner.MethodStatement
protected class
FeaturesRunner.RulesFactory<A extends Annotation,R>
-
Field Summary
Fields Modifier and Type Field Description protected static String
CUSTOM_ENVIRONMENT_SYSTEM_PROPERTY
protected static String
DEFAULT_BUILD_DIRECTORY
protected com.google.inject.Injector
injector
Guice injector.protected org.nuxeo.runtime.test.runner.FeaturesLoader
loader
protected TargetResourceLocator
locator
protected static AnnotationScanner
scanner
protected Object
underTest
-
Constructor Summary
Constructors Constructor Description FeaturesRunner(Class<?> classToRun)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description protected void
afterMethodRun(org.junit.runners.model.FrameworkMethod method, Object test)
protected void
afterRun()
protected void
afterTeardown(org.junit.runners.model.FrameworkMethod method, Object test)
protected void
apply(String id, Collection<org.nuxeo.runtime.test.runner.FeaturesLoader.Holder> holders, ThrowableConsumer<org.nuxeo.runtime.test.runner.FeaturesLoader.Holder,Exception> consumer)
protected void
apply(String id, FeaturesRunner.Direction direction, ThrowableConsumer<org.nuxeo.runtime.test.runner.FeaturesLoader.Holder,Exception> consumer)
protected void
beforeMethodRun(org.junit.runners.model.FrameworkMethod method, Object test)
protected void
beforeRun()
protected void
beforeSetup(org.junit.runners.model.FrameworkMethod method, Object test)
protected org.junit.runners.model.Statement
classBlock(org.junit.runner.notification.RunNotifier aNotifier)
protected List<org.junit.rules.TestRule>
classRules()
protected List<org.junit.runners.model.FrameworkMethod>
computeTestMethods()
Object
createTest()
void
evaluateRunnable(ThrowableRunnable<Throwable> runnable, ThrowableRunnable<Throwable> finisher)
protected String
formatFeatures(Collection<org.nuxeo.runtime.test.runner.FeaturesLoader.Holder> holders)
<T extends Annotation>
List<T>getAnnotations(Class<T> type)
Returns the list of annotations present on the test class, then on the interfaces implemented by the test class, then on its super class, then on the different features.<T extends Annotation>
List<T>getAnnotations(Class<T> type, org.junit.runners.model.FrameworkMethod method)
Returns the list of annotations for the given method.static String
getBuildDirectory()
Returns the Maven build directory, depending on the "custom.environment" system property.<T extends Annotation>
TgetConfig(Class<T> type)
<T extends Annotation>
TgetConfig(org.junit.runners.model.FrameworkMethod method, Class<T> type)
Get the annotation on the test method, if no annotation has been found, get the annotation from the test class (SeegetConfig(Class)
)<T extends RunnerFeature>
TgetFeature(Class<T> aType)
Iterable<RunnerFeature>
getFeatures()
com.google.inject.Injector
getInjector()
<T extends Annotation>
List<T>getMethodAnnotationsWithClassFallback(Class<T> type, org.junit.runners.model.FrameworkMethod method)
Returns the list of annotations for the given method, if no annotation has been found, get the annotations for the current test.<T extends Annotation>
List<T>getMethodOrTestAnnotations(Class<T> type, org.junit.runners.model.FrameworkMethod method)
Returns the list of annotations for the given method if the method is given, otherwise return the list of annotations for the current test.static AnnotationScanner
getScanner()
Path
getTargetTestBasepath()
Deprecated.since 11.1, seems unusedClass<?>
getTargetTestClass()
Object
getTargetTestInstance()
May return null if the test class was not yet instantiatedURL
getTargetTestResource(String name)
protected List<org.junit.rules.TestRule>
getTestRules(Object target)
protected void
initialize()
protected com.google.inject.Injector
onInjector(org.junit.runner.notification.RunNotifier aNotifier)
protected List<org.junit.rules.MethodRule>
rules(Object target)
protected void
start()
protected void
stop()
protected void
throwSeriousError(Throwable cause)
String
toString()
protected void
validateZeroArgConstructor(List<Throwable> errors)
protected org.junit.runners.model.Statement
withAfterClasses(org.junit.runners.model.Statement statement)
protected org.junit.runners.model.Statement
withAfters(org.junit.runners.model.FrameworkMethod method, Object target, org.junit.runners.model.Statement statement)
protected org.junit.runners.model.Statement
withBefores(org.junit.runners.model.FrameworkMethod method, Object target, org.junit.runners.model.Statement statement)
-
Methods inherited from class org.junit.runners.BlockJUnit4ClassRunner
collectInitializationErrors, createTest, describeChild, getChildren, isIgnored, methodBlock, methodInvoker, possiblyExpectingExceptions, runChild, testName, validateConstructor, validateFields, validateInstanceMethods, validateNoNonStaticInnerClass, validateOnlyOneConstructor, validateTestMethods, withPotentialTimeout
-
-
-
-
Field Detail
-
scanner
protected static final AnnotationScanner scanner
-
CUSTOM_ENVIRONMENT_SYSTEM_PROPERTY
protected static final String CUSTOM_ENVIRONMENT_SYSTEM_PROPERTY
- Since:
- 11.1
- See Also:
- Constant Field Values
-
DEFAULT_BUILD_DIRECTORY
protected static final String DEFAULT_BUILD_DIRECTORY
- Since:
- 11.1
- See Also:
- Constant Field Values
-
injector
protected com.google.inject.Injector injector
Guice injector.
-
loader
protected final org.nuxeo.runtime.test.runner.FeaturesLoader loader
-
locator
protected final TargetResourceLocator locator
-
underTest
protected Object underTest
-
-
Constructor Detail
-
FeaturesRunner
public FeaturesRunner(Class<?> classToRun) throws org.junit.runners.model.InitializationError
- Throws:
org.junit.runners.model.InitializationError
-
-
Method Detail
-
getScanner
public static AnnotationScanner getScanner()
-
getBuildDirectory
public static String getBuildDirectory()
Returns the Maven build directory, depending on the "custom.environment" system property.- Since:
- 11.1
-
getTargetTestClass
public Class<?> getTargetTestClass()
-
getTargetTestInstance
public Object getTargetTestInstance()
May return null if the test class was not yet instantiated
-
getTargetTestBasepath
@Deprecated(since="11.1") public Path getTargetTestBasepath()
Deprecated.since 11.1, seems unused
-
getTargetTestResource
public URL getTargetTestResource(String name) throws IOException
- Throws:
IOException
-
getFeatures
public Iterable<RunnerFeature> getFeatures()
-
getAnnotations
public <T extends Annotation> List<T> getAnnotations(Class<T> type)
Returns the list of annotations present on the test class, then on the interfaces implemented by the test class, then on its super class, then on the different features.- Returns:
- the list of annotations for the current test
- Since:
- 2021.15
-
getAnnotations
public <T extends Annotation> List<T> getAnnotations(Class<T> type, org.junit.runners.model.FrameworkMethod method)
Returns the list of annotations for the given method.- Returns:
- the list of annotations for the given method
- Since:
- 2021.15
-
getMethodOrTestAnnotations
public <T extends Annotation> List<T> getMethodOrTestAnnotations(Class<T> type, @Nullable org.junit.runners.model.FrameworkMethod method)
Returns the list of annotations for the given method if the method is given, otherwise return the list of annotations for the current test.This is a convenient method for feature that has the same code to execute for before class and before method steps.
- Returns:
- the list of annotations for the given method
- Since:
- 2021.15
-
getMethodAnnotationsWithClassFallback
public <T extends Annotation> List<T> getMethodAnnotationsWithClassFallback(Class<T> type, @Nullable org.junit.runners.model.FrameworkMethod method)
Returns the list of annotations for the given method, if no annotation has been found, get the annotations for the current test.- Returns:
- the list of annotations for the given method, if they exist, otherwise the list of annotations for the current test
- Since:
- 2021.15
-
getConfig
public <T extends Annotation> T getConfig(Class<T> type)
- Since:
- 5.6
-
getConfig
public <T extends Annotation> T getConfig(org.junit.runners.model.FrameworkMethod method, Class<T> type)
Get the annotation on the test method, if no annotation has been found, get the annotation from the test class (SeegetConfig(Class)
)- Since:
- 5.7
-
computeTestMethods
protected List<org.junit.runners.model.FrameworkMethod> computeTestMethods()
- Overrides:
computeTestMethods
in classorg.junit.runners.BlockJUnit4ClassRunner
-
beforeRun
protected void beforeRun()
-
beforeMethodRun
protected void beforeMethodRun(org.junit.runners.model.FrameworkMethod method, Object test)
-
afterMethodRun
protected void afterMethodRun(org.junit.runners.model.FrameworkMethod method, Object test)
-
afterRun
protected void afterRun()
-
start
protected void start()
-
stop
protected void stop()
-
beforeSetup
protected void beforeSetup(org.junit.runners.model.FrameworkMethod method, Object test)
-
afterTeardown
protected void afterTeardown(org.junit.runners.model.FrameworkMethod method, Object test)
-
apply
protected void apply(String id, FeaturesRunner.Direction direction, ThrowableConsumer<org.nuxeo.runtime.test.runner.FeaturesLoader.Holder,Exception> consumer)
- Since:
- 11.1
-
apply
protected void apply(String id, Collection<org.nuxeo.runtime.test.runner.FeaturesLoader.Holder> holders, ThrowableConsumer<org.nuxeo.runtime.test.runner.FeaturesLoader.Holder,Exception> consumer)
- Since:
- 11.1
-
formatFeatures
protected String formatFeatures(Collection<org.nuxeo.runtime.test.runner.FeaturesLoader.Holder> holders)
-
evaluateRunnable
public void evaluateRunnable(ThrowableRunnable<Throwable> runnable, ThrowableRunnable<Throwable> finisher) throws Throwable
- Throws:
Throwable
-
throwSeriousError
protected void throwSeriousError(Throwable cause)
-
getInjector
public com.google.inject.Injector getInjector()
-
onInjector
protected com.google.inject.Injector onInjector(org.junit.runner.notification.RunNotifier aNotifier)
-
withAfterClasses
protected org.junit.runners.model.Statement withAfterClasses(org.junit.runners.model.Statement statement)
- Overrides:
withAfterClasses
in classorg.junit.runners.ParentRunner<org.junit.runners.model.FrameworkMethod>
-
classBlock
protected org.junit.runners.model.Statement classBlock(org.junit.runner.notification.RunNotifier aNotifier)
- Overrides:
classBlock
in classorg.junit.runners.ParentRunner<org.junit.runners.model.FrameworkMethod>
-
classRules
protected List<org.junit.rules.TestRule> classRules()
- Overrides:
classRules
in classorg.junit.runners.ParentRunner<org.junit.runners.model.FrameworkMethod>
-
withBefores
protected org.junit.runners.model.Statement withBefores(org.junit.runners.model.FrameworkMethod method, Object target, org.junit.runners.model.Statement statement)
- Overrides:
withBefores
in classorg.junit.runners.BlockJUnit4ClassRunner
-
withAfters
protected org.junit.runners.model.Statement withAfters(org.junit.runners.model.FrameworkMethod method, Object target, org.junit.runners.model.Statement statement)
- Overrides:
withAfters
in classorg.junit.runners.BlockJUnit4ClassRunner
-
getTestRules
protected List<org.junit.rules.TestRule> getTestRules(Object target)
- Overrides:
getTestRules
in classorg.junit.runners.BlockJUnit4ClassRunner
-
rules
protected List<org.junit.rules.MethodRule> rules(Object target)
- Overrides:
rules
in classorg.junit.runners.BlockJUnit4ClassRunner
-
createTest
public Object createTest() throws Exception
- Overrides:
createTest
in classorg.junit.runners.BlockJUnit4ClassRunner
- Throws:
Exception
-
validateZeroArgConstructor
protected void validateZeroArgConstructor(List<Throwable> errors)
- Overrides:
validateZeroArgConstructor
in classorg.junit.runners.BlockJUnit4ClassRunner
-
getFeature
public <T extends RunnerFeature> T getFeature(Class<T> aType)
-
-