When testing an application that interacts with other external systems or that access a database you need some handling for this to make this work correctly.
Either you need some test versions of the systems and setup the database similar as the production database which is cubersome and lot of work to make each test work. A slight change in the object model would require that the tests also are changed.
A better method is to use some mocking framework to simulate that certain calls are being made and check that this really happens in the test. There exists several such mocking frameworks that have different advantages and disadvantages.
In the projects I'm currently working with we use a mocking framework developed by Mikael Waltersson which is called Simple Mock. This mock framework is as the name specifies very simple to use but don't be fooled the easy of use doesn't imply that the mock framework lacks functionallity, instead it has the functionallity that is required for a mock framework.
Try it, the time you spend learning how to setup the framework for your project will be earn quick enough once you start writing more and more tests.
Link to the development page on codeproject: http://www.codeproject.com/tips/45376/Simple-Mocking-new-mocking-framework-for-NET-3-5.aspx
Showing posts with label mock. Show all posts
Showing posts with label mock. Show all posts
11 August 2010
14 May 2010
Initializations during test cases
In any larger project a complex test suite should be built, a test suite that when run through should cover most of the code that handles buisness logic, aggregations and such. Presentations aren't always that important even if it is good to include those parts in the tests too,When the tests starts to increase they will take longer and longer to complete which will impact on the performance of the developers since these have to wait for tests to complete during verficiations of changes.
There are several methods for dealing with this one is the use of a common initializations class that setup the basic structure and adds basic data needed for the tests. The problem with this approach is that if you need to add some new data or change data in the setup you will have a huge impact on the tests and maybe changing a few that should have given indications on a problem that has been introduced. Its often better to separate the tests and let each test setup the data required for just that test and clean up afterwards. If using a database the setup and teardown of the database could be a common setup that is run first in the testclass and teardown occured at the end after all tests. In such an instance you need a way to clean out the database without tearing it down compleatly.
Of course these are just my thoughts and there a several methods in dealing with this. One that we often use is the use of mocking of objects since you then don't need a real database just the apperance of one. from the systems point of view. This makes that test much much more efficient and faster but has the drawback that you aren't really testing the database which also needs to be done.
I any circumstance test ARE important and you should never feel that a test is useless and remove them if you aren't compleatly and absolutly sure since there is often a very good reason for that the test was created in the first place.
Happy testing!
Labels:
database,
initialization,
mock,
performance,
test cases,
testing
Subscribe to:
Posts (Atom)