Common Errors in SpringUnit Tests

Incorrect Name of XML Configuration File


A SpringUnit test fails because the XML configuration file has an incorrect file name.


        IOException parsing XML document from class path resource [IncorrectXmlFilenameTest.xml];
        nested exception is
        class path resource [IncorrectXmlFilenameTest.xml] cannot be opened because it does not exist class path resource [IncorrectXmlFilenameTest.xml]
        cannot be opened because it does not exist


This error occurs when an XML configuration file has been created and is on the classpath, but the name of the file does not conform to the SpringUnit convention.


Ensure the name of the file is Classname.xml where Classname is equivalent to the simple name of the Java test class. For example, if your test class is, then the name of your XML file should be FooTest.xml.


Java Source Code:
package org.springunit.examples.errors;

import org.springunit.framework.SpringUnitContext;
import org.springunit.framework.SpringUnitTest;

public class IncorrectXmlFilenameTest extends SpringUnitTest {
    public void testWillFail() throws Exception {
    public SpringUnitContext getIncorrectXmlFilenameTest() {
        return incorrectXmlFilenameTest;

    public void setIncorrectXmlFilenameTest(
            SpringUnitContext incorrectXmlFilenameTest) {
        this.incorrectXmlFilenameTest = incorrectXmlFilenameTest;

    private SpringUnitContext incorrectXmlFilenameTest;

XML Configuration File:
!! -- File name is IncorrectXXmlFilenameTest.xml -- !!
Previous Next