Unit testing 春天+;Tiles 2,如何对控制器进行单元测试?

Unit testing 春天+;Tiles 2,如何对控制器进行单元测试?,unit-testing,spring-mvc,tiles2,Unit Testing,Spring Mvc,Tiles2,当我尝试使用以下代码时: import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.test.context.ActiveProfiles; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4Clas

当我尝试使用以下代码时:

import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.web.WebAppConfiguration;

@RunWith(SpringJUnit4ClassRunner.class)
@WebAppConfiguration
@ContextConfiguration({ "classpath:applicationContext.xml",
        "file:WebContent/WEB-INF/spring/appServlet/servlet-context.xml" })
@ActiveProfiles("unittest")
public class PlaygroundControllerTest {

    @Test
    public void test() {

    }

}
我遇到了以下异常:

Caused by: java.io.FileNotFoundException: ServletContext resource [/WEB-INF/tiles/tiles.xml] cannot be resolved to URL because it does not exist
    at org.springframework.web.context.support.ServletContextResource.getURL(ServletContextResource.java:154)
    at org.springframework.web.servlet.view.tiles2.SpringTilesApplicationContextFactory$SpringWildcardServletTilesApplicationContext.getResources(SpringTilesApplicationContextFactory.java:105)
    at org.springframework.web.servlet.view.tiles2.TilesConfigurer$SpringTilesContainerFactory.getSourceURLs(TilesConfigurer.java:423)
    ... 49 more
这是servlet-context.xml中的相关tiles配置

<bean id="viewResolver"
    class="org.springframework.web.servlet.view.UrlBasedViewResolver">
    <property name="viewClass"
        value="org.springframework.web.servlet.view.tiles2.TilesView" />
</bean>
<bean id="tilesConfigurer" class="org.springframework.web.servlet.view.tiles2.TilesConfigurer">
    <property name="definitions">
        <list>
            <value>/WEB-INF/tiles/tiles.xml</value>
        </list>
    </property>
</bean>

/WEB-INF/tiles/tiles.xml

如何让单元测试找到tiles的配置文件(/WEB-INF/tiles/tiles.xml)?

我遇到了同样的问题

默认情况下,Spring使用“src/main/webapp”路径。您可以在“You_uApplication/src/main/webapp”上更改路径

比如说,

@WebAppConfiguration("webapp/src/main/webapp")