That`s right, not just custom solutions testing but overall deployment. Unit testing is something that we too often find applicable to individual unit of functionality: a webpart, a feature, an event handler, a web service etc. How do we go about testing our entire deployment; whether it`s a public site or intranet or extranet, how do we ensure SharePoint works up to our specification as a whole.
Here are few things to include in your Test Project in VS:
1. Has the site template been deployed ?
2. Have necessary services been provisioned and configured (search, publishing infrastructure etc) ?
3. Have all the subsites been created ?
4. Have features on the subsites been installed and activated (page and resources provisioning features) ?
5. Critical document libraries provisioned (ex. libraries holding images for landing pages) ?
6. Content types deployed (if any)?
7. Any event receivers activated on content types?
Custom components like webpart, feature, event handler etc code has to be tested separately in their respective unit tests.
Here are some snippets when testing general site items from above:
1. Checks whether web application features like kresources have been deployed and activated
[TestMethod]
public void WebAppFeaturesExist()
{
using (SPSite rootSite = new SPSite(TestConfig.SharePointUrl))
{
// Resources deployed
Assert.IsTrue(rootSite.WebApplication.Features.Exists(new Guid(“798D8335-69C3-4ec0-AAA4-470787D3DCBE”)));
}
}
2. Check whether site template has been deployed and exists
[TestMethod]
public void SiteTemplatesExist()
{
using (SPSite rootSite = new SPSite(TestConfig.SharePointUrl))
{////Application Site Template deployed
//Assert.IsTrue(rootSite.GetWebTemplates(1033).Exists(“CustomIntranetTemplate#0″));
}
}
3. Have you created any libraries or lists that are required , maybe libraries that store images for landing pages, all sorts of lists, templates that lists are based on?
[TestMethod]
public void LibrariesExist()
{
using (SPSite rootSite = new SPSite(TestConfig.SharePointUrl))
{
using (SPWeb rootWeb = rootSite.OpenWeb())
{
//Custom library created
Assert.IsTrue(rootWeb.ListTemplates.Exists(“Custom Library Template”));
using (SPWeb web = rootSite.OpenWeb(“/”))
{
Assert.IsTrue(web.Lists.Exists(“Custom Library”));
}
}
}
}
4. Content types deployed and event receivers activated on them?
[TestMethod]
public void ContentTypesExist()
{
using (SPSite rootSite = new SPSite(TestConfig.SharePointUrl))
{
using (SPWeb rootWeb = rootSite.OpenWeb())
{
Assert.IsTrue(rootWeb.ContentTypes.Exists(“IntranetMainPage”));//Event Receivers deployed on those content types
Assert.IsTrue(rootWeb.ContentTypes["IntranetMainPage"].EventReceivers.Count > 0);
Assert.IsTrue(rootWeb.ContentTypes["IntranetMainPage"].EventReceivers[0].Name == “CustomEventReceiver”);
}
}
}
5. Do you have any custom features on webs, have they been deployed and activated?
[TestMethod]
public void FeaturesExist()
{
using (SPSite rootSite = new SPSite(TestConfig.SharePointUrl))
{
// Has home page feature been activatedAssert.IsTrue(rootSite.RootWeb.Features.Exists(new Guid(“798D8335-69C3-4ec0-AAA4-470787D3DCBE”)));
}
}