views:

41

answers:

1

hi there, i'm trying to learn how to properly setup testing for an ASP.Net MVC.

and from what i've been reading here and there thus far, the definition of legacy code kind of piques my interests, where it mentions that legacy codes are any codes without unit tests.

so i did my project in a hurry not having the time to properly setup unit tests for the app and i'm still learning how to properly do TDD and unit testing at the same time. then i came upon selenium IDE/RC and was using it to test on the browser end.

it was during that time too that i came upon the concept of integration testing, so from my understanding it seems that unit testing should be done to define the test and basic assumptions of each function, and if the function is dependent on something else, that something else needs to be mocked so that the tests is always singular and can be run fast.

Questions:

  1. so am i right to say that the project should have started with unit test with proper mocks using something like rhino mocks.

    then anything else which requires 3rd party dll, database data access etc to be done via integration testing using selenium?

  2. because i have a function which calls a third party dll, i'm not sure whether to write a unit test in nunit to just instantiate the object and pass it some dummy data which breaks the mocking part to test it or just cover that part in my selenium integration testing when i submit my forms and call the dll.

  3. and for user acceptance tests, is it safe to say we can just use selenium again?

  4. Am i missing something or is there a better way/framework?

i'm trying to put in more tests for regression testing, and to ensure that nothing breaks when we put in new features. i also like the idea of TDD because it helps to better define the function, sort of like a meta documentation.

thanks!! hope this question isn't too subjective because i need it for my case.

+1  A: 
  1. so am i right to say that the project should have started with unit test with proper mocks using something like rhino mocks.

The project should have started with a good separation of concerns. Once you have a good separation and you work with abstractions instead of concrete classes using a mocking framework and writing unit tests is a piece of cake.

then anything else which requires 3rd party dll, database data access etc to be done via integration testing using selenium?

Yes.

because i have a function which calls a third party dll, i'm not sure whether to write a unit test in nunit to just instantiate the object and pass it some dummy data which breaks the mocking part to test it or just cover that part in my selenium integration testing when i submit my forms and call the dll.

You should not have a function that calls a third party DLL. You should write an abstraction/wrapper around this DLL which you would use and which will be mocked in the unit test where you will verify that your function calls the proper methods without really calling it. You would then use a DI framework in the application to do the plumbing.

and for user acceptance tests, is it safe to say we can just use selenium again?

Selenium or any other Web testing framework would be fine. In the more advanced ($) versions of Visual Studio you could write web tests.

Darin Dimitrov
thanks for clarifying and giving me a clearer overview of how to test and what to test. but unit test should still cover those small functions that does computation right, i.e. if let's say i have a simple function that maps a country and return the id, i should unit test that one?
melaos