Ted Velkoff
Ted Velkoff

Reputation: 21

Reading method-level properties using JUnit + spring-test

What is the best way to use spring-test with JUnit to read property files specific to a test method? The following bean illustrates the intent to search method-level, then class-level, then package-level, then root-level property files:


<bean name="properties" class="org.springframework.context.support.PropertySourcesPlaceholderConfigurer"    >
    <property name="locations">
        <list>
            <value>classpath:properties.xml</value>
            <value>classpath:*/properties.xml</value>
            <value>classpath:*/*/properties.xml</value>
            <value>classpath:*/*/*.properties.xml</value>
        </list>
    </property>
</bean>

I've considered using/subclassing PropertySourcesPlaceholderConfigurer or SpringMethodRule, but so far, neither a viable nor elegant solution has occurred to me. spring-test offers a variety of promising class-level annotations, but the stumbling block is that I want to be able to find a method-specific file, e.g.:

classpath:myPackage/myClass/myMethod.properties.xml

Upvotes: 1

Views: 263

Answers (1)

Sam Brannen
Sam Brannen

Reputation: 31197

If you are just looking for an algorithm that helps you to look up classpath resources based on the current method, you can take inspiration from the ServletTestExecutionListener in the Spring TestContext Framework, specifically the detectDefaultScript() method.

Regards,

Sam (author of the Spring TestContext Framework)

Upvotes: 0

Related Questions