I'm having a bit of an issue injecting values into TestNG tests. I'm running Spring 5.3.X, and using Spring context XML files (not autowired).
I've tried to boil it down to being as simple as possible, but even the code below doesn't work. I've messed around with a bunch of things I found on this site, but nothing has seemed to work.
Below is my test:
import org.springframework.test.context.testng.AbstractTestNGSpringContextTests;
@ContextConfiguration(locations = {"classpath:test-spring-context.xml"})
public class Test extends AbstractTestNGSpringContextTests {
private String foo;
@org.testng.annotations.Test
public void foo() {
System.out.println(foo);
}
public void setFoo(final String foo) {
this.foo = foo;
}
}
Below is my Spring context file:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd"
default-lazy-init="true">
<bean id="test" class="org.acme.persistence.dao.Test">
<property name="foo" value="bar"/>
</bean>
</beans>
I am expecting the output of the System.out.println("foo") line to be "bar", however it always comes as null.
Am I missing something?
Thanks in advance for any help.