简体   繁体   中英

How to get spring configurations via junit test in spring maven

I need to run junit test case.In my controller, i have autowired classes which will be configured during runtime. I need that configurations to be done while running the junit test itself.. Can anyone provide solution for this..

you can use the below code snippet

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration({ "classpath:spring-context.xml"})
public class TestClass {
    @Autowired
    private SomeServiceClass service;

    @Test
    public void testMethod() {
        //  your code goes here
    }
}

for spring test dependency you can use

<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-test</artifactId>
    <version>${spring.version}</version>
    <scope>test</scope>
</dependency>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM