Hello Developers
I have a Spring Web app working with multi-modules (it comes from other project based in one-module)
I can export the app into a .war
file and deploy it with Tomcat and all works fine.
My problem is about testing.
Just playing with:
@WebAppConfiguration
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes={RootApplicationContextConfig.class, ServletApplicationContextConfig.class})
public class PersonaRetrieveControllerTest {
@Autowired
private WebApplicationContext webApplicationContext;
private MockMvc mockMvc;
private static Persona persona;
@BeforeClass
public static void beforeClass(){
persona = PersonaFactory.crearPersonaMix();
}
@Before
public void setUp(){
mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).build();
}
@Test
public void abc(){
}
}
I always get the following:
Caused by: java.io.FileNotFoundException: ServletContext resource [/WEB-INF/tiles/definition/tiles-definitions.xml] cannot be resolved to URL because it does not exist
Remember: the app runs fine in tomcat
The module being testing is
project(':web-27-controller') {
description 'Web - Controller & Rest'
dependencies {
compile project(':web-27-service-api')
compile project(':web-27-support')
//Testing
testCompile project(':web-27-context')
testRuntime project(':web-27-web')
}
}
And it depends in someway to :web-27-web'
(here no testing)
project(':web-27-web') {
description 'Web (JSP, JS, CSS)'
apply plugin: 'war'
dependencies {
exportedProjects.each{
if("$it"!=":web-27-web")
compile project("$it")
}
//Apache Tiles
['tiles-jsp',
'tiles-servlet'
].each {
testRuntime "org.apache.tiles:$it:$tilesVersion"
runtime "org.apache.tiles:$it:$tilesVersion"
}
//JSTL
compile "javax.servlet:jstl:$jstlVersion"
testRuntime "javax.servlet:jstl:$jstlVersion"
//Servlet API
providedCompile "javax.servlet:javax.servlet-api:$javaxServletApiVersion"
testRuntime "javax.servlet:javax.servlet-api:$javaxServletApiVersion"
}
war {
version=''
baseName = warBaseName
}
}
In this :web-27-web
module I can see the path to the /WEB-INF/tiles/definition/tiles-definitions.xml
file. Furthermore in this module exists all about web files such as: html, js, css, images, and tiles (xml) and again, the app runs fine in tomcat
My current configuration about Gradle would be verbose or perhaps illogic since I’ve tried many combinations.
The obvious question is: why works in production and not in testing.
I am working with testRuntime
and nothing.
I already have read:
What is missing about testing configuration?
Thank you