Package io.cucumber.spring
Class SpringFactory
java.lang.Object
io.cucumber.spring.SpringFactory
- All Implemented Interfaces:
Container,Lookup,ObjectFactory
Spring based implementation of ObjectFactory.
Application beans are accessible from the step definitions using autowiring (with annotations).
The spring context can be configured by annotating one glue class with
a @CucumberContextConfiguration and any one of the
following @ContextConfiguration, @ContextHierarchy
or @BootstrapWith. This glue class can also be annotated
with @WebAppConfiguration or @DirtiesContext annotation.
Notes:
- SpringFactory uses Springs TestContextManager framework to manage the
spring context. The class annotated with
CucumberContextConfigurationwill be use to instantiate theTestContextManager. - If not exactly one glue class is annotated with
CucumberContextConfigurationan exception will be thrown. - Step definitions should not be annotated with @
Componentor other annotations that mark it as eligible for detection by classpath scanning. When a step definition class is annotated by @Component or an annotation that has the @Component stereotype an exception will be thrown
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final Collection<Class<?>> private @Nullable TestContextAdaptorprivate @Nullable Class<?> -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbooleanAdd a glue class to the test context.private static voidcheckNoComponentAnnotations(Class<?> type) private voidcheckOnlyOneClassHasCucumberContextConfiguration(Class<?> stepClass) <T> TgetInstance(Class<T> type) Provides an instance of a glue class.(package private) static booleanhasCucumberContextConfiguration(Class<?> stepClass) voidstart()Start the object factory.voidstop()Stops the object factory.
-
Field Details
-
stepClasses
-
withCucumberContextConfiguration
-
testContextAdaptor
-
-
Constructor Details
-
SpringFactory
public SpringFactory()
-
-
Method Details
-
addClass
Description copied from interface:ContainerAdd a glue class to the test context.Invoked after creation but before
ObjectFactory.start(). -
checkNoComponentAnnotations
-
hasCucumberContextConfiguration
-
checkOnlyOneClassHasCucumberContextConfiguration
-
start
public void start()Description copied from interface:ObjectFactoryStart the object factory. Invoked once per scenario.While started
Lookup.getInstance(Class)may be invoked.- Specified by:
startin interfaceObjectFactory
-
stop
public void stop()Description copied from interface:ObjectFactoryStops the object factory. Called once per scenario.When stopped the object factory should dispose of all glue instances.
- Specified by:
stopin interfaceObjectFactory
-
getInstance
Description copied from interface:LookupProvides an instance of a glue class.- Specified by:
getInstancein interfaceLookup- Type Parameters:
T- type of Glue class- Parameters:
type- type of instance to be created.- Returns:
- new instance of type T
-