@ContextConfiguration: Difference between revisions

From NovaOrdis Knowledge Base
Jump to navigation Jump to search
(Created page with "=External= * https://docs.spring.io/spring-framework/docs/current/javadoc-api/org/springframework/test/context/ContextConfiguration.html =Internal= * Spring_Framework_Tes...")
 
 
(3 intermediate revisions by the same user not shown)
Line 6: Line 6:


* [[Spring_Framework_Testing_Concepts#.40ContextConfiguration|Spring Framework Testing Concepts]]
* [[Spring_Framework_Testing_Concepts#.40ContextConfiguration|Spring Framework Testing Concepts]]
=Overview=
@ContextConfiguration is a class-level annotation that can be used to configure the [[Spring_Framework_Testing_Concepts#TestContext|test context]] for Spring integration tests. @ContextConfiguration can be used to declare either path-based resource locations, via the locations() or value() attribute, or annotated classes, via the classes() attribute. Note, however, that most implementations of [https://docs.spring.io/spring/docs/current/javadoc-api/org/springframework/test/context/SmartContextLoader.html SmartContextLoader] only support a single resource type.
If more than one component (produced by @Configuration, stereotype-annotated class, etc.) is required for the test to complete successfully, all those classes must be listed in the "classes" attribute of the annotation:
<syntaxhighlight lang='java'>
@ContextConfiguration(classes = {
        AComponent.class,
        BComponent.class})
</syntaxhighlight>

Latest revision as of 19:38, 23 November 2018

External

Internal

Overview

@ContextConfiguration is a class-level annotation that can be used to configure the test context for Spring integration tests. @ContextConfiguration can be used to declare either path-based resource locations, via the locations() or value() attribute, or annotated classes, via the classes() attribute. Note, however, that most implementations of SmartContextLoader only support a single resource type.

If more than one component (produced by @Configuration, stereotype-annotated class, etc.) is required for the test to complete successfully, all those classes must be listed in the "classes" attribute of the annotation:

@ContextConfiguration(classes = {
        AComponent.class,
        BComponent.class})