Common Errors in SpringUnit Tests

Incorrect Name of SpringUnitContext Property in Java

Description

A SpringUnit test fails because the name of the SpringUnitContext property of the test is incorrect in the Java source code.

Symptoms

org.springframework.beans.factory.UnsatisfiedDependencyException:
        Error creating bean with name 'org.springunit.examples.errors.IncorrectPropertyNameInJavaTest':
        Unsatisfied dependency expressed through bean property 'incorectPropertyNameInJavaTest':
        Set this property value or disable dependency checking for this bean.
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.
	    checkDependencies(AbstractAutowireCapableBeanFactory.java:995)
    ...

Cause

This error occurs when the name of the SpringUnitContext property in the Java source code does not conform to the SpringUnit convention.

Remedy

Ensure the name of the property is classname where classname is equivalent to the simple name of the Java test class. For example, if your test class is com.my.company.FooTest, then the property should be declared this way: private SpringUnitContext fooTest;

Example

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

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

public class IncorrectPropertyNameInJavaTest extends SpringUnitTest {
    
    public void testWillFail() throws Exception {
    }
    
    public SpringUnitContext getIncorectPropertyNameInJavaTest() {
        return incorectPropertyNameInJavaTest;
    }

    public void setIncorectPropertyNameInJavaTest(
            SpringUnitContext incorectPropertyNameInJavaTest) {
        this.incorectPropertyNameInJavaTest = incorectPropertyNameInJavaTest;
    }

    private SpringUnitContext incorectPropertyNameInJavaTest;

}
XML Configuration File:
<beans>

    <bean id="incorrectPropertyNameInJavaTest" class="org.springunit.framework.SpringUnitContext">
        <property name="data">
            <map>
            	<! -- Test data goes here -->
            </map>
        </property>
    </bean>
    
</beans>
Previous Next