https://stackoverflow.com/questions/10441622/write-junit-tests-for-spring-mvc-application-which-internally-relies-upon-contex

@ContextConfiguration(locations = "classpath:module-test-beans.xml")
@WebAppConfiguration
public class SampleTest extends AbstractTestNGSpringContextTests {

    @Autowired
    private WebApplicationContext wac;

    @BeforeClass
    public void setUp() throws ServletException {
        MockServletContext sc = new MockServletContext("");
        ServletContextListener listener = new ContextLoaderListener(wac);
        ServletContextEvent event = new ServletContextEvent(sc);
        listener.contextInitialized(event);
    }

    @Test
    public void testMe() {
        Assert.assertFalse(ContextLoader.getCurrentWebApplicationContext() == null);
    }
}

 

'spring-test' 카테고리의 다른 글

spring-boot-test - 두번째  (0) 2022.06.02
JUnit5 Test  (0) 2020.03.14
spring-boot-test  (0) 2018.07.19
Posted by 張's blog
,