Dan Newcome on technology

I'm bringing cyber back

MockCrm for testing MS CRM code

with one comment

I’ve been debating whether to release some code I’ve been playing with for a while for unit testing Microsoft CRM projects. I had hacked something together back in CRM 4 to test a project that was slow and tricky to test manually against a real CRM installation. But there wasn’t good test coverage on this code and there were a lot of cases that it didn’t handle.

I revisited the idea of creating a CRM mock service this week and created a version for CRM 2011 and it seems to be better suited for the new API.

The mock lets you set up some data at the top of the test like this:

m_service = new MockCrmService();
Entity de = new Entity();
de.LogicalName = "mydynamic";
de["prop1"] = "foo";
Guid deID = m_service.Create( de );

Then we can run a test on the fixture that we created in the code above like this:

		public void TestDynamic() {
			QueryBase query = CrmQuery
				.From( "mydynamic" )
				.Where( "mydynamic", "prop1", ConditionOperator.Equal, new object[] { "foo" } ).Query;

			EntityCollection bec = m_service.RetrieveMultiple( query );
			Fest.AssertTrue( bec.Entities.Count > 0, "found more than zero entities" );

Note that these examples use my micro .NET unit testing library Fest and my CrmQuery DSL for building CRM queries.

The reason I’m debating releasing this code is that I don’t know if I can spare the time and effort to polish this up. On the other hand I’ve benefited from Phil Haack’s experiments in mocking .NET HttpContext and mocking email servers. I guess sometimes it is useful to just see the approach that others are trying when it comes to testing. You don’t always need the polish. What do you guys think?

Written by newcome

January 27, 2011 at 1:59 am

Posted in Uncategorized

One Response

Subscribe to comments with RSS.

  1. […] This post was mentioned on Twitter by Good CRM, JordyAlexandro93. JordyAlexandro93 said: MockCrm for testing MS CRM code « Dan Newcome, blog: I've been debating whether to release some code I've been p… http://bit.ly/e2sAxP […]

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: