I have a CAML query in a class and I'm using unit test to cover my code with some proper test. For the SharePoint classes and stuff, I use TypeMock to mock the SharePoint objects.

I would like to test the CAML query because I think there is some logic there that need to be test. How can I to that? Is the CAML query engine can run on dummy object?

I'm using SharePoint 2010 with C#.


With unit testing, you would just return some dummy data from your mocked sharepoint object.

I think testing the CAML queries would be a part of integration testing because you need to validate the system is returning the results you expect. You don't want to mock it up because you want to see how the system actually behaves.

  • You have a good point here. Yes it should definitely be in the integration tests. But my question here was about the query itself. Ok, let's say I have 2 elements in my list with a language metadata. My query resquest for english items only. With 2 dummy items, one french, one english, does my query works? It's like if I want to test a foreach with an if within. Does it do what it should do ? or did I make a mistake in the type attribute of the CAML query. – Philippe Lavoie Mar 5 '12 at 20:39
  • Wouldn't you just code your mock object to return the english or french item to test your other code? I guess my point was.. if you want to test the CAML query itself then it would be an integration test. If you want to test how to handle data that is returned from the query, just hard code that into your mocked object. – Kit Menke Mar 5 '12 at 21:11
  • So basicly, are you telling me there is no way to execute a CAML outside/offline of SharePoint system environment (i.e. in a testing context)? – Philippe Lavoie Mar 5 '12 at 22:18
  • 2
    Correct. Maybe this would be a good open source project? – Kit Menke Mar 5 '12 at 23:03
  • Actually, I wish 2 things : The CAML engine would be exposed offline. And, CAML would be replaced by LINQ-to-SharePoint – Philippe Lavoie Mar 6 '12 at 15:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.