Sto provando a scrivere un test JUnit per un progetto Spring Roo. Se il mio test richiede l'uso delle classi di entità, ottengo la seguente eccezione:Come utilizzare i test JUnit con Spring Roo? (Problemi con EntityManager)
java.lang.IllegalStateException: Entity manager has not been injected
(is the Spring Aspects JAR configured as an AJC/AJDT aspects library?)
aspetti primavera JAR sembra essere configurato correttamente. In particolare, ho il seguente nel file pom.xml
:
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-aspects</artifactId>
<version>${spring.version}</version>
</dependency>
e
<plugin>
<configuration>
<outxml>true</outxml>
<aspectLibraries>
<aspectLibrary>
<groupId>org.springframework</groupId>
<artifactId>spring-aspects</artifactId>
</aspectLibrary>
</aspectLibraries>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
e le classi che utilizzano le classi di entità funzionare bene, quando non è chiamato da un test JUnit. Qualche idea su come posso impostare le cose in modo che il gestore Entity venga iniettato da un test JUnit?
Qui è la mia classe di test (più o meno):
public class ServiceExampleTest {
@Test
public void testFoo() {
FooService fs = new FooServiceImpl();
Set<Foo> foos = fs.getFoos();
}
}
Questo è sufficiente per generare l'eccezione. La classe FooServiceImpl restituisce un set di Foo, dove Foo è una classe di entità. Il metodo getFoos()
funziona quando l'applicazione viene eseguita nel solito modo. Il problema viene solo nel contesto dei test unitari.
Potrebbe pubblicare il tuo classe di test come bene? Non ho mai usato Spring Roo, ma con i normali test di Spring di solito devi estendere AbstractSpringJUnit4Test (o qualcosa del genere) o usare un runner Spring personalizzato tramite annotazione per i test. – ponzao