Showing posts with label Unit Testing. Show all posts
Showing posts with label Unit Testing. Show all posts

Monday, July 30, 2012

Continuous integration with SharePoint (and automated unit tests)

I've been working a lot with SharePoint lately and as with any project, we add it to our Cruise Control.NET server. The first challenge was that we had to install SharePoint on the CC.NET server. It was not really a challenge, but more of a time-consuming task.


The second challenge was setting up automated unit tests. In our case we use WCF services that receive an SPToken (actually, the string representation of the SPToken). This token expires every now and then, and we had to come up with a way to get a token in order to connect to a WCF service. The solution was creating a method in a service that creates a token and sends it back. It's really not the best practice, and it's not something you want to deploy to production, but it works fine for a continuous integration environment. These are the steps we followed:


1) Create a new service that is used only in the CC.NET sandbox
2) Create a method in that service that returns a token. The method should run with elevated privileges and return a token of a hardcoded user account (preferably an administrator account)
3) Reference this service from the project that contains the unit tests (we use XUnit)
4) Instantiate a service client from the test case (something like this)



  XUnitServiceClient client = new XUnitServiceClient("BasicHttpBinding_IXUnitService");
  client.Endpoint.Address = new System.ServiceModel.EndpointAddress("http://mypc/_vti_bin/XUnitService.svc/soap");
  string result = client.GetToken();



5) Then just call the method you're trying to test and pass the token.

Friday, October 8, 2010

Maintainable JavaScript

This is a great screencast on best practices to write maintainable JavaScript code, check it out!

Thursday, October 7, 2010

YUI 3.0 Keeping test cases in different files

In this thread Nicholas Zakas explains how to keep test cases in separate files (instead of using just one file). I tried his solution and it worked... for a few minutes.

YUI 3.0 was supposed to be released one year ago, yet their documentation is not as good as it used to be (like in YUI 2.0). This is one of the reasons I prefer YUI 2.0. It's not as painful as learning Dojo, but it has (what I consider) major changes that are not explained in their documentation. How do they expect us to use their tools?


Thursday, September 30, 2010

JavaScript Unit Testing

YUI Test is probably the best JavaScript testing framework I've found so far. Check it out here.

I have still yet to find a way to call YUI test from a Continuous Integration environment. The default way to call it is by running the website to be tested, but there should be a way to call it remotely and make sure the test passed.