CRM Online 2011 Integration Testing running in Production environment
Asked Answered
G

1

3

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

Gibb answered 13/12, 2011 at 11:6 Comment(3)
@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.Gibb
Do you want the exception data returned every time any user creates a contact, or just when you're testing?Lisa
@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).Gibb
L
2

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!

Lisa answered 14/12, 2011 at 20:19 Comment(5)
+1 Thanks Peter. Good food for thought there - will have a look... Had seen the Erik Pool one - while it accomplishes much, it doesnt run my code on the server though - i.e., I won't know if I'm doing things Medium Trust prevents thoughGibb
@RubenBartelink - I see what you mean there. The only other way I can think of to handle this then is to create a test organization separate from your prod org where you can do whatever you want, as anything deployed to an organization, AFAIK, affects all users in that organization.Lisa
Yes, I'm actually using an account specially for the purpose (my actuak work is backend plumbing supporting people who will write the real plugins). Part 1 of the same series temptingly even shows how to easily update an assembly... (I had originally titled the question Acceptance instead of Integration testing as it is actually Acceptance from the point of view of the layer I'm delivering whereas most plugin devs would consider acceptance to be working with real data delivering real UIs, i.e., WatiN/Selenium)Gibb
The @Josh Painter answer is neat (taken with Part 1 of the Erik Porter 'unit testing' blog) - and if I was doing significant debugger-driven development of a plugin, it would be a must have technique. crm2011plugintest is obviously of interest if one is doing more complex manipulations based on input context (which doesnt really descrie my situation). But thanks very much once again for the answer - I have no doubt it'll serve someone very well as a top to bottom summary of testing approaches in general. ... blogs.msdn.com/b/devkeydet/archive/2011/12/08/…Gibb
I also see pluginregcrm2011.codeplex.com/documentation provides a console app for uploading plugins which will form part of my overall solution....Gibb

© 2022 - 2024 — McMap. All rights reserved.