Come si esegue il test dell'unità su HttpModule
in asp.net dato che HttpApplication
e HttpContext
non implementano un'interfaccia?Unit test IHttpModule
risposta
In passato prima di passare a ASP.NET MVC, ho utilizzato this library Phil Haack creato per Test unità tutto ciò che utilizzava HttpApplication e HttpContext. A sua volta usato uno Duck Typing library.
Purtroppo, questo era il modo migliore per farlo. ASP.NET non è stato creato per essere facilmente testabile. Quando hanno lavorato su ASP.NET MVC, uno degli obiettivi è quello di sbarazzarsi di questi mal di testa rendendo il framework più testabile.
In sostanza è necessario per rimuovere la dipendenza del modulo Http su HttpApplication e HttpContext, la loro sostituzione con un'interfaccia. Si potrebbe creare il proprio IHttpApplication e IHttpContext (insieme a IHttpResonse, IHttpRequest, ecc) o utilizzare quelli menzionati da @Dale Ragan o utilizzare quelli lucidi nuovi in System.Web.Abstractions che sono in bundle con le anteprime MVC ASP.NET.
È possibile utilizzare un quadro di isolamento (beffardo). Conosco due strumenti che consentono di simulare/simulare qualsiasi oggetto .NET - Typemock Isolator e Telerik JustMock Penso che sia possibile utilizzare anche Moles.
Tutti i precedenti consentiranno di falsificare qualsiasi evento oggetto .NET se non implementa un'interfaccia o ha anche un lettore pubblico.
- 1. unit test in C++
- 2. unit test smell
- 3. Unit test Scala
- 4. Unit test codice matematico
- 5. Unit test localized stringhe
- 6. ZF2 autenticazione unit test
- 7. Messagebox e Unit test
- 8. Esecuzione Qt unit test
- 9. Unit test a HttpApplication
- 10. Unit test the Viewmodel
- 11. unit test system.timers.timer
- 12. Unit test Winforms UI
- 13. unit test modular javascript
- 14. Unit test chiamata Activity.startService()?
- 15. Unit test Direttive AngularJS
- 16. EntityFunctions.TruncateTime e unit test
- 17. Test Unit multithreading
- 18. Unit test event javascript
- 19. Unit test e nibernate?
- 20. Unit test icefaces
- 21. unit test direttiva angularjs
- 22. Unit Test & Log4net
- 23. IHttpHandler vs IHttpModule
- 24. unit test e test funzionali in CodeIgniter
- 25. Python - Twisted e Unit Test
- 26. AFNetworking 2.0 e Unit Test
- 27. Unit test di un compilatore
- 28. Unit Test non in esecuzione
- 29. Eccezione catch in unit test
- 30. Unit test a Model Mixin
Potete indicarmi l'articolo di @Dale Ragan. PS: Non ho accesso a Twitter – chugh97
In realtà mi riferisco alla risposta direttamente sotto questo :) – Mike