Sono sicuro che mi manca qualcosa di semplice. la barra viene abilitata nel test della junit, ma perché non si può abilitare l'auto-rimozione all'interno di foo?Autowire non funziona in junit test
risposta
Foo non è un fagiolo gestito, lo stai istanziando tu stesso. Quindi Spring non ha intenzione di autorizzare nessuna delle sue dipendenze per te.
eh. oh uomo, ho bisogno di dormire. è così ovvio. Grazie! – Upgradingdave
Stai creando una nuova istanza di Foo. Quell'istanza non ha idea del contenitore di iniezione di dipendenza Spring. Devi eseguire l'autowire foo nel tuo test:
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration({"beans.xml"})
public class BarTest {
@Autowired
// By the way, the by type autowire won't work properly here if you have
// more instances of one type. If you named them in your Spring
// configuration use @Resource instead
@Resource(name = "mybarobject")
Object bar;
@Autowired
Foo foo;
@Test
public void testBar() throws Exception {
//this works
assertEquals("expected", bar.someMethod());
//this doesn't work, because the bar object inside foo isn't autowired?
assertEquals("expected", foo.someMethodThatUsesBar());
}
}
ha perfettamente senso, grazie mille! – Upgradingdave
- 1. Autowire un servizio di primavera in test JUnit
- 2. JUnit @Test prevede l'annotazione non funziona
- 3. Spring @Transactional non funziona nel test JUnit?
- 4. non test JUnit usando Primavera
- 5. Framework di test C# che funziona come JUnit in Eclipse?
- 6. JUnit + Maven + Eclipse: Perché @BeforeClass non funziona?
- 7. Autowiring non funziona in Primavera 3.1.2, JUnit 4.10.0
- 8. Log4j in JUnit Test case
- 9. Perché JUnit 4 su Android non funziona?
- 10. Eseguire test JUnit in parallelo
- 11. Java Thread.currentThread(). SetUncaughtExceptionHandler() non funziona con JUNIT?
- 12. Test Wrapping JUnit (in Eclipse)
- 13. JUnit opzionali test/richieste
- 14. Groovy Eclipse non può lanciare test JUnit
- 15. JUnit test si blocca
- 16. Raggruppamento di test JUnit
- 17. Eliminare o commentare test JUnit non funzionanti?
- 18. JUnit descrizione del test
- 19. junit test case generator
- 20. Struts 2.3.14 junit test
- 21. Il debug dei punti di interruzione su JUnit test in Eclipse non funziona
- 22. Provare a eseguire test JUnit Android in Eclipse non riesce?
- 23. come trasformare test parametrizzati junit non paralleli in corsa parallela
- 24. Non può Autowire Servizio in HandlerInterceptorAdapter
- 25. Rimozione test JUnit testuite ridondanti
- 26. Classe di test JUnit generica
- 27. Spring Parameterized/Theories JUnit Test
- 28. JUnit esegue i test case in sequenza?
- 29. Test delle query JDBC in JUnit
- 30. Errore 206 nel test JUnit in Eclipse
Cosa intendi con "bar inside foo"? – skaffman