Hi,
I have the following Spring component with an autowired field.
I wrote the followowing unit test, using ReflectionTestUtils to inject the parametresStore autowired field :Code:@Service @Transactional(propagation=Propagation.REQUIRED, rollbackFor=Throwable.class) public class PlageCalculServiceImpl implements PlageCalculService { @Autowired private ParametresStore parametresStore; @Override public PlageHoraire getPlagePreparation(Date lundi) {...} }
When I run unit tests, I have the following stack trace :Code:@RunWith(SpringJUnit4ClassRunner.class) @Transactional @ContextConfiguration(locations = { "classpath:spring-test.xml", "classpath:spring-datasource-test.xml", "classpath:spring-hibernate-test.xml"}) public class PlageCalculServiceTest { @Autowired private PlageCalculService plageCalculService; @Test public void testGetPlagePreparationDimanche() { ... ParametresStore mock = new ParametresStoreMock(); ReflectionTestUtils.setField(this.plageCalculService, "parametresStore", mock, ParametresStore.class); Calendar lundi = new GregorianCalendar(2010, Calendar.NOVEMBER, 8, 5, 0); PlageHoraire plagePreparation = this.plageCalculService.getPlagePreparation(lundi.getTime()); ... } }
If I remove @Transactional annotation from my Spring component, everything works fine.Code:java.lang.IllegalArgumentException: Could not find field [parametresStore] on target [xxx.PlageCalculServiceImpl@19478c7] at org.springframework.test.util.ReflectionTestUtils.setField(ReflectionTestUtils.java:106)
I use Spring 3.0.4.
Any idea how I could solve this problem ?
Thanks in advance,
Olivier


Reply With Quote