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 ?
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With