Spring Framework
  1. Spring Framework
  2. SPR-6567

Annotation configuration based TestContext

    Details

    • Type: New Feature New Feature
    • Status: Resolved
    • Priority: Major Major
    • Resolution: Duplicate
    • Affects Version/s: 3.0 RC3
    • Fix Version/s: None
    • Component/s: Test
    • Labels:
      None
    • Last commented by a User:
      false

      Description

      Why don't you add AnnotationContextLoader that supports annotation configuration based TestContext.

      for example. If there is an annotation configuration like this

      @Configuration
      public class SpringAnnotationConfigTestAppConfig {

      @Bean
      public String name()

      { return "keesun"; }

      }

      and, at the same package, I can make test like this.

      @RunWith(SpringJUnit4ClassRunner.class)
      @ContextConfiguration(loader = AnnotationContextLoader.class, locations =

      {"."})
      public class SpringAnnotationConfigTest {

      @Autowired ApplicationContext ac;
      @Autowired String name;

      @Test
      public void di(){ assertNotNull(ac); assertThat(name, is("keesun")); }

      }

      then, conventionally SpringJUnit4ClassRunner finds SpringAnnotationConfigTest + "AppConfig.java" for an annotation configuration.

      Of course, It makes sence that we sould use 'locations' attribute of @ContextConfigruation like these.

      @ContextConfiguration(loader = AnnotationContextLoader.class, locations = {"/sandbox/springtest/sample/SpringAnnotationConfigTestAppConfig.java"})
      @ContextConfiguration(loader = AnnotationContextLoader.class, locations = {"/sandbox/springtest/sample/"})
      @ContextConfiguration(loader = AnnotationContextLoader.class, locations = {"/sandbox/springtest/sample"})
      @ContextConfiguration(loader = AnnotationContextLoader.class, locations = {"./SpringAnnotationConfigTestAppConfig.java"})
      @ContextConfiguration(loader = AnnotationContextLoader.class, locations = {"./"})
      @ContextConfiguration(loader = AnnotationContextLoader.class, locations = {"."}

      )

      with '.Java' locations can be used to AnnotationConfigurationApplicationContext.regist(), and without '.java' locations will be used to AnnotationConfigurationApplicationContext.scan().

      What do you think about this?

      1. AnnotationContextLoader.java
        6 kB
        Keesun Baik
      2. AnnotationContextLoaderTest.java
        2 kB
        Keesun Baik
      3. SpringAnnotationConfigTest.java
        2 kB
        Keesun Baik
      4. SpringAnnotationConfigTestAppConfig.java
        0.5 kB
        Keesun Baik

        Issue Links

          Activity

          Hide
          Keesun Baik added a comment -

          These are implementation and test.

          Show
          Keesun Baik added a comment - These are implementation and test.
          Hide
          Keesun Baik added a comment -

          These are sample test and configuration.

          Show
          Keesun Baik added a comment - These are sample test and configuration.
          Hide
          Chris Beams added a comment -

          Duplicates SPR-6184

          Show
          Chris Beams added a comment - Duplicates SPR-6184

            People

            • Assignee:
              Unassigned
              Reporter:
              Keesun Baik
              Last updater:
              Trevor Marshall
            • Votes:
              3 Vote for this issue
              Watchers:
              5 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:
                Days since last comment:
                3 years, 35 weeks, 1 day ago