1

We want to implement static code analysis (like SPCop / SPCAF / StyleCop) and unit testing (what's the easiest way to mock SharePoint objects? Are there alternatives to Microsoft Fakes?) into our development process. I want to evaluate some tools that could be integrated into our continuous build.

What are your suggestions, known issues, best practices and most appreciated tools?

It would be nice, if it could detect, e.g., access to lists using the display name (problematic on a non us-en system), SPList.Items.Add vs SPList.AddItem, SPWeb.Lists[] vs SPWeb.GetList (depends on number of lists in the web), usages of SPWeb.AllowUnsafeUpdates, etc.

Thanks in advance!

3
  • 1
    I'm not experienced in this, but code analysis tools allow you to create your own rules to check for the things in your last paragraph, if they don't already (getting list through displayname is not something I've seen reported before). johanolivier.blogspot.be/2013/10/… May 18, 2014 at 12:41
  • @CameronVerhelst thanks for your input. I didn't know custom rules are possible, so this might come in handy for the list access issue. This example is a little special, but I had some trouble with that recently, when updating a default list like Shared Documents in a feature event receiver.
    – Markus
    May 18, 2014 at 12:54
  • Nah, I feel your pain, we had trouble with it aswell once. Another good one is url concatenation in SP (managed path's SPSite.ServerRelativeUrl returns a url ending in '/') whereas a non-managed path SPSite.ServerRelativeUrl does not (or the other way around) :). May 19, 2014 at 6:37

2 Answers 2

1

I've used Telerik's JustMock for mocking up SharePoint objects when unit testing and it works fairly well.

The syntax goes something like this:

SPWeb web = Mock.Create<SPWeb>();
Mock.Arrange(() => web.Url).Returns("http://sharepointsite");

It can be used in conjunction with any Unit testing such as NUnit and VSTest and so on.

1

The official story is not really a good one. Microsoft built an emulator that enables you to write code that simulates access to a SharePoint server. I have no idea if anyone is using the emulator, I rarely see anything on it.

Here's a session from TechEd 2013 that talks about the emulator: Testing and Debugging Microsoft SharePoint Applications with Microsoft Visual Studio 2012

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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