È possibile utilizzare java.lang.instrument.Instrumentation nei test JUnit? Sto usando mockrunner per simulare un Servlet e voglio misurare la dimensione degli oggetti memorizzati in una sessioneÈ possibile utilizzare java.lang.instrument.Instrumentation nei test JUnit?
risposta
Ho usato jmockit in test di unità questo potrebbe prendere in giro quasi tutto. Estendendo ciò, anche java.lang.instrument.Instrumentation dovrebbe funzionare.
Sì, questo è possibile, ma non molto semplice.
Il problema con l'utilizzo di java.lang.instrument.Instrumentation è che sarà SEMPRE necessario utilizzare un agente JVM. Una buona introduzione agli agenti JVM è disponibile al numero http://www.javabeat.net/2012/06/introduction-to-java-agents/.
Tuttavia, poiché i test dell'unità vengono eseguiti anche in jvm, è possibile specificare l'agente come argomento JVM.
Un agente JVM che segnala la memoria per ciò che si desidera fare e pronto per il confezionamento, è disponibile allo https://github.com/jbellis/jamm. Puoi costruirlo con Maven o Ant. Per usarlo, si costruisce e poi passare il seguente come argomento JVM quando si avvia il test di unità o unit test privato:
-javaagent:<path to>/jamm.jar
Entro i test di unità, è quindi possibile creare un'istanza della MemoryMeter e l'uso it:
MemoryMeter meter = new MemoryMeter();
meter.measure(object);
meter.measureDeep(object);
meter.countChildren(object);
- 1. È una buona idea catturare AssertionError nei test di JUnit?
- 2. Esegui test jUnit parametrizzati senza utilizzare Annotation
- 3. JUnit confusione: utilizzare 'estende TestCase' o '@Test'?
- 4. È possibile utilizzare i dati del pacchetto R nei test test o run_examples()?
- 5. È possibile eseguire test JUnit incrementale/automatizzato in Eclipse?
- 6. Raggruppamento di test JUnit
- 7. È ancora possibile utilizzare l'unità di prova nei binari 4?
- 8. Errore di violazione della chiave primaria HSQLDB nei test JUnit
- 9. Utilizzare Ant per eseguire solo test JUnit specifici
- 10. JUnit: è possibile "aspettarsi" un'eccezione avvolta?
- 11. JUnit descrizione del test
- 12. validazione spring-data-jpa bean nei test junit
- 13. È possibile utilizzare proiettori da altre app nei test di django?
- 14. Struts 2.3.14 junit test
- 15. È possibile utilizzare le sottocartelle nei drawable in Android?
- 16. Come utilizzare dettagliata-0,9 nei test cabala
- 17. junit test case generator
- 18. JUnit opzionali test/richieste
- 19. JUnit test si blocca
- 20. Spring Parameterized/Theories JUnit Test
- 21. È possibile utilizzare la sintassi BDD ScalaTest in un ambiente JUnit?
- 22. Utilizzare un'asserzione nel metodo @Before di un test JUnit?
- 23. Test Wrapping JUnit (in Eclipse)
- 24. Come utilizzare JUnit con Eclipse
- 25. Come utilizzare VisibleForTesting per i test JUnit puri
- 26. test junit - assertEquals for exception
- 27. SetUp, inizializza il test Junit
- 28. Test unità JUnit e Clojure
- 29. Classe di test JUnit generica
- 30. Eseguire test JUnit in parallelo