Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can we unit test global.asax in asp.net?

I am doing unit testing. I have no idea that how to unit test global.asax in asp.net. Is global.asax in asp.net come under unit test coverage ? Also there is application installer class which contain system varibles. Should i test them ?

like image 712
Ninad More Avatar asked Jan 09 '13 07:01

Ninad More


2 Answers

You can. But you shouldn't. A unit test, as the name suggests, tests units. The code in global.asax or in your system configuration is not a unit. The tests for these things would be really tightly coupled with the code and would always give you false fails when you change an irrelevant thing so it doesn't worth it. There are other levels in application testing where it become relevant: integration testing, automation etc. You shouldn't put everything into 'unit test', only well defined, single parts. E.g. you don't unit test your web.config or DI container config too, but you test them on another level.

like image 56
Peter Porfy Avatar answered Sep 19 '22 12:09

Peter Porfy


My stance on this is that you shouldn't have to unit-test code in your global.asax.

Main reason is that there should not be more in there than declarations and wiring code. As Peter Porfy already said, that code should be tested in integration tests.

If you find any logic worth unit-testing in your global.asax you probably should factor it out and test those classes separately.

like image 36
Marnix van Valen Avatar answered Sep 19 '22 12:09

Marnix van Valen