Common Errors in SpringUnit Tests

Incorrect Name of Test in XML Configuration File


A SpringUnit test fails because the name of a test in the Java source code cannot be found in the XML configuration file.


    at org.springunit.examples.errors.IncorrectNameOfTestInXmlTest.testOne(


This error occurs when the name of a test method in the Java source code cannot be found in the XML configuration file. The getObject method in org.springunit.framework.SpringUnitTest and org.springunit.frameowrk.SpringTransactionalTest returns null if it can find no match in the test context. This can result in downstream NullPointerExceptions.


If the name of the test in the XML configuration is misspelled, then correct it. If it is missing altogether, then add an entry for the test and its data in the XML configuration file.


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

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

public class IncorrectNameOfTestInXmlTest extends SpringUnitTest {
    public void testOne() throws Exception {
        String str = getObject("str");
        String expected = getObject("expected");
    public SpringUnitContext getIncorrectNameOfTestInXmlTest() {
        return incorrectNameOfTestInXmlTest;

    public void setIncorrectNameOfTestInXmlTest(
            SpringUnitContext incorrectNameOfTestInXmlTest) {
        this.incorrectNameOfTestInXmlTest = incorrectNameOfTestInXmlTest;

    private SpringUnitContext incorrectNameOfTestInXmlTest;

XML Configuration File:

    <bean id="incorrectNameOfTestInXmlTest" class="org.springunit.framework.SpringUnitContext">
        <property name="data">
                <entry key="testTwo">
                        <entry key="str"><value>idea</value></entry>
                        <entry key="expected"><value>idea</value></entry>
Previous Next