Contact Sales: +1-888-365-2779
Community & Support
Skip Navigation LinksHome / Community & Support / Developer Productivity Tools Forums / OpenAccess ORM > General Discussions > Best practices of unit testing with OpenAccess

Not answered Best practices of unit testing with OpenAccess

Feed from this thread
  • Posted on Nov 10, 2008 (permalink)

    Have you got any practices or recommendation of unit testing while using open access? I failed to find any examples how it can be done in documetation.

    Reply

  • Jan Blessenohl Jan Blessenohl admin's avatar

    Posted on Nov 10, 2008 (permalink)

    Hello Alexey,

    There are no mock objects for unit testing at the moment. We just try to clean the database content in the testcase setup method and additional after the tests in the cleanup.

    All the best,
    Jan Blessenohl
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.

    Reply

  • Q1 Webinar Week
  • Posted on Mar 16, 2009 (permalink)

    Hi Alexey,

    Are you talking about unit testing (the functionality contained in) your domain objects? 

    From the top of my head, an option could be to derive an object from IObjectScopeProvider that implements your database happy path (i.e. returns the objects you expect to get from the database when everything works on the OpenAccess end) and then use a mocking framework or some dependency injection to call the functions in your IObjectScopeProvider object whenever a call is made to the original objectScopeProvider object as created by OpenAccess.

    Does this make any sense? Since I am implementing unit testing for one of my projects anyway I'll see if I can get something up to provide an example.

    Regards,
    Erik

    Reply

  • Dimitar Kapitanov Dimitar Kapitanov admin's avatar

    Posted on Mar 16, 2009 (permalink)

    Hello Erik,
    Please check this topic from our documentation and tell us what you think of the content there:
    http://www.telerik.com/help/openaccess-orm/openaccess-tasks-howto-using-openaccess-with-test-frameworks.html.
    Hope this helps.

    All the best,
    Dimitar Kapitanov
    the Telerik team


    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.

    Reply

  • Posted on Mar 17, 2009 (permalink)

    Hi Dimitar,

    The tutorial provided by the link is excellent and I am using that same approach when I am testing my application/objects interface with the database. However, it does not provide a way to test your business objects and business logic independent of OpenAccess.

    For example, I have a persistent Person class. I can use your approach to test whether I can add this class to the database successfully. That's great and very useful indeed.

    However, I also have a PersonService class that encapsulates some business logic involved in adding people to the database. For example, I might want to keep track of a blacklist of people that I do not want to have added to the database. As the PersonService uses it's own instance of the ObjectScope, the automatic rollback provided by your example doesn't work.

    In addition to that, I would like to be able to test just the business logic, not the interface to the database. That is why I suggested mocking to abstract out the database access.

    I am currently working through the example I outlined above to see if mocking would be possible. I will certainly keep you posted on my progress.

    Regards,
    Erik

    Reply

  • Dimitar Kapitanov Dimitar Kapitanov admin's avatar

    Posted on Mar 17, 2009 (permalink)

    Hi Erik,
    Well there are supporters of both approaches. Let me explain why I prefer using test databases against database mocks: by using a test database, you open up the possibility that problems could be caused at the database itself or along the communication path (network, etc) between the DAL and database. Mocking eliminates those possibilities. And in the end mocks hinder the unit tests because you are not taking into account a series of real world problems that usually have impact on your behavior. I think that it would be much more productive to have those things sorted out in the testing phase. From my perspective if you test only BOs using mocks of the DAL and everything is OK, and then in the real case situation you hit a showstopper because of the DAL, this puts you in the same awful situation. Of course that is my opinion, and I do not believe that we can put a statement what best practices are, or are not. Everyone should decide based on the context of the task is my opinion.

    All the best,
    Dimitar Kapitanov
    the Telerik team


    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.

    Reply

  • Posted on Mar 17, 2009 (permalink)

    Hi Dimitar,

    You are absolutely right, everyone should make the best choice for their own particular situation. For myself, I always (try to) test both the actual database access (as you stated, a lot can go wrong there) and use mocking only when I am testing just the business logic. For me personally, that gives me the peace of mind that I am approaching testing from all possible angles.

    Great discussing this with you by the way, it's a sure sign you take these things very seriously :-)

    Regards,
    Erik

    Reply

  • Posted on Mar 17, 2009 (permalink)

    Hi Guys,

    As promised, I did some tinkering about with OpenAccess and mocking. I've written a short article on it on my blog.


    I hope you'll find it useful.

    Regards,
    Erik

    Reply

  • Dimitar Kapitanov Dimitar Kapitanov admin's avatar

    Posted on Mar 18, 2009 (permalink)

    Hello Erik,
    It was a really nice post. I enjoyed reading it.

    Greetings,
    Dimitar Kapitanov
    the Telerik team


    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.

    Reply

  • Q1 Webinar Week

Back to Top

Skip Navigation LinksHome / Community & Support / Developer Productivity Tools Forums / OpenAccess ORM > General Discussions > Best practices of unit testing with OpenAccess
Related resources for "Best practices of unit testing with OpenAccess"

OpenAccess ORM Features  |  Documentation  |  Demos  |  Telerik TV  |  Step-by-step Tutorial   ]