Link to home
Start Free TrialLog in
Avatar of Jaison Peter
Jaison Peter

asked on

Unit test newbie questions

I am writing unit test case for my asp.net application . I am newbie in unit testing. I have following doubts. Could you please clarify the below doubts:

1. I have written unit test for all methods in my application which include privite, protected, public , function returns void,int,list so on.. is that necessary?
2. I felt some of the functions like page_load and button_click , does this need to write unit test cases?  
3. How i will write unit test for void methods? do i just need to check the function will not throw an exception.
4. Suppose a function is returns SQL queries as string, how i should i write test case , i just need to check the function will not throw an exception?
5. Suppose , if we are writting unit test for all function in application it wil effect the code coverage right?
ASKER CERTIFIED SOLUTION
Avatar of Chris Stanyon
Chris Stanyon
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
To add to what Chris was saying; you would mock up your DBContext (this is an example of using Entity Framework).
This will allow you to mock up data as the model and when you pass the mocked DBContext it will contain your mock up data (so you would not have to use a live database connection and you've consistent test data).

Here's an example for EF 6.0+:

Entity Framework Testing with a Mocking Framework (EF6 onwards)

Less than EF 6.0+:

Testing With a Fake DbContext