Spring @ContextConfiguration

前端 未结 3 2174
甜味超标
甜味超标 2021-02-20 04:56

I am running the next test:

import static org.junit.Assert.assertEquals;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.bean         


        
3条回答
  •  借酒劲吻你
    2021-02-20 05:30

    The idea of @Configuration given above works nice. But for that you have to annotate your classes with @Configuration. This is not a nice idea when it comes to testing offline i.e when in your organisation test cases are not executed at built time. In that case going by @ContextConfiguration(locations = { "classpath:/META-INF/spring/applicationContext.xml" }) will be a nice idea.

    For using this method, take care of the following:

    1. Check your classpath in .classpath file of your project.

    2. If you cannot write the path of applicationContext relative to classpath.

    You can have one more file as applicationContextTest folder kept in your test case folder and then one can use @ContextConfiguration(locations = { "classpath:applicationContextTest.xml"})

提交回复
热议问题