Incorrect Name of SpringUnitContext Property in XML Configuration File
Description
A SpringUnit test fails because the name
of the SpringUnitContext property of the test is incorrect
in the XML configuration file.
Symptoms
org.springframework.beans.factory.UnsatisfiedDependencyException:
Error creating bean with name 'org.springunit.examples.errors.IncorrectPropertyNameInXmlTest':
Unsatisfied dependency expressed through bean property 'incorrectPropertyNameInXml':
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 XML configuration file 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:
<bean id="fooTest" class="org.springunit.framework.SpringUnitContext">
Example
Java Source Code:
package org.springunit.examples.errors;
import org.springunit.framework.SpringUnitContext;
import org.springunit.framework.SpringUnitTest;
public class IncorrectPropertyNameInXmlTest extends SpringUnitTest {
public void testWillFail() throws Exception {
}
public SpringUnitContext getIncorrectPropertyNameInXml() {
return incorrectPropertyNameInXml;
}
public void setIncorrectPropertyNameInXml(
SpringUnitContext incorrectPropertyNameInXml) {
this.incorrectPropertyNameInXml = incorrectPropertyNameInXml;
}
private SpringUnitContext incorrectPropertyNameInXml;
}
XML Configuration File:
<beans>
<bean id="incorectPropertyNameInJavaTest" class="org.springunit.framework.SpringUnitContext">
<property name="data">
<map>
<! -- Test data goes here -->
</map>
</property>
</bean>
</beans>