3
votes

I'm writing some code for Dynamics CRM Online 2011.

I'd like to have a set of integration tests be run in CRM Online and be able to examine:

  • Some log output
  • Assertion failures

Under the control of a test runner on my local machine.

Right now, I'm doing:

var passes = new List<string>();
var fails = new List<Tuple<string,Exception>>();
foreach(Action<StringWriter> testAction in EnumTests())
{
    var log = stringWriter();
    try 
    {
        testAction(log);
        passes.Add(log.ToString());
    }
    catch(Exception e)
    {
        fails.Add(log.ToString(),e);
    }
}

throw new Exception( "PASSES: " + string.Join("======", passes.ToArray()) 
    + "FAILS: " + string.Join("=======",fails.Select(f=>f.ToString()).ToArray());

I trigger this code by plugin action wired to Contact Create:

  1. upload the plugin
  2. create a contact
  3. hit save
  4. download the exception data file

There has to be a better way but I simply cannot find any reference within the docs or blogs or forums) to triggering plugin code via a test (and getting exception output).

I want to be able to call a method in the plugin and then have the results including a full stack trace and log output arrive back within the context of a xUnit test.

Is that possible? Have others done anything similar? Surely not all CRM 2011 devs are stuck in a whackamole with a mouse loop?


NB I'm not interested in debugging on premise and ideally would prefer not to have to store results into bespoke entities. I know I could screenscrape the page but am hoping there's some way I can do the equivalent of a webservice call. Or that someone has a nice framework that simply does it all (or I can tweak).

EDIT: Looks like I'll probably end up asking whether anyone has some nice WatiN code against CRM Online next

1
@Jon C Thanks for the response - was wondering if there was anyone out there at all. I'm comfortable with how to Unit Test and/or Mock stuff and/or debug on-premise and I dont want to pause it. I see the codeplex thing for shipping around serialized PluginContexts. I dont want any of that - I want to a) trigger running of my code in CRM Online without screenscraping b) get the response back onto a client machine for interpretation. Sorry if I was unclear on my constraints. I really find it hard to believe that there isnt a mechanism for this, but extensive searching has turned up nothing.Ruben Bartelink
Do you want the exception data returned every time any user creates a contact, or just when you're testing?Peter Majeed
@Peter Majeed: Only when I'm driving it via my test (and I dont want people interactively or concurrently running it injecting results into my result stream - i.e., I would really like to avoid storing it in a cusotm entity or in the log).Ruben Bartelink

1 Answers

2
votes

I'm not sure I understand everything you're looking to accomplish, but I'm betting based on your comment that you've already had a look at CRM 2011 Plugin Testing Tools on codePlex. As the Project Description and Release Notes both mention that a MS employee helped develop that project, you can quickly see that MS's support for what you're asking for is limited.

As Jon C mentioned, Josh Painter mentioned in an answer to another question that there's a built-in plugin-debugger you can use, which would be executed on the client machine.

Also, Erik Pool posted on his blog a great entry on manually instantiating a IPluginExecutionContext for your plugins.

Hope one of these three solutions works!