Search code examples
javamavenspring-mvcjunit4applicationcontext

JUnit Error: "Failed to load ApplicationContext"


Nothing seems to work

I'm trying to run simple test:

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = {"/applicationContext.xml"})
@Transactional
public class EmailServiceTest {

I've also tried:

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = {"src/main/webapp/WEB-INF/applicationContext.xml"})
@Transactional
public class EmailServiceTest {

Along with a few different things in place of "location," such as "classpath" and "file."

The "ApplicationContext" is located:

src
    main
        webapp
            WEB-INF
                applicationContext.xml

But JUnit test still says: Failed to load ApplicationContext


Solution

  • The issue was solved after we realized our build file was missing information pertaining to testing. Information such as the "app.properties" and " applicationContext" were not being copied into the testing resources. So technically, none of these were on the classpath.