none
Unittest on service RRS feed

  • Question

  • Hello,

    Does someone know how to write a unittest for a Robotics (MSRDS 4.0) service? I cannot figure out how I can do this. Could not find any info about this subject on internet as well.

    I tried to let Resharper create a Shadow class and use and _Accessor but I don't know how to let this work.

    Any help is appreciated!

    Tuesday, September 17, 2013 10:01 AM

Answers

  • That is correct.  To test the service itself requires other services interacting with it.  That takes you out of the realm of "unit testing" and into the realm of functional or end-to-end testing.

    Monday, September 30, 2013 5:20 PM

All replies

  • Hi Gershon,

    I looked at the links you send me but this doesn't provide me with any clue.

    I have the following code as unittest which was generated.

    [TestMethod()] [DeploymentItem("PlanQueueManager.dll")] public void HasQueueActionPlanItemWithAlarmIdTest() { PrivateObject param0 = null; // TODO: Initialize to an appropriate value PlanQueueManagerService_Accessor target = new ActionPlanQueueManagerService_Accessor(param0); // TODO: Initialize to an appropriate value

    ActionPlanItem actionPlanItem = new ActionPlanItem(1);

    bool expected = true; bool actual = target.HasQueueActionPlanItemWithAlarmId(actionPlanItem); Assert.AreEqual(expected, actual); Assert.Inconclusive("Verify the correctness of this test method."); }

    The problem is that I don't know how to initialize param0. And so I cannot start up the service correctly. Any clues?
     
    Wednesday, September 18, 2013 5:57 AM
  • What is a valid initialization for that PrivateObject?
    Why can't you initialize it in place there instead of null?
    Is it something that changes for each test run?  If so, you could look at data-driven testing where there is a TestContext property of the TestClass that is varied for each call to your test method according to your data.

    You also might try posting in the Visual Studio Test forums.

    -G

    Monday, September 23, 2013 9:05 PM
  • Can you provide a sample for how to do a unittest for a service? I know how to write a normal unittest but that won't do it for MSRDS.
    Friday, September 27, 2013 9:15 AM
  • I asked around, and here is what we can suggest:

    1) Unit tests are generally very low-level, basic functionality tests.  Ideally you design all of your services so that the core business functionality is encapsulated in its own class or classes separate from the communication glue, and the RDS Service instantiates these classes as needed and uses them to do the work.  This encapsulation allows you to test the "business logic" separately from the Service "glue" and is a good design practice. It also allows you to change the "glue" should you ever decide to use something other than DSS for the communication. Writing unit tests for these separate business logic classes should be like for any other class. They will generally take something like a message as input and produce a response as output.  If you don't make this distinction, then you cannot truly unit-test the functionality...  it is entangled with the communication.

    2) When it does come to doing integration or end-to-end testing (different from unit testing) we have not found any way to use the Visual Studio unit test framework for this. Instead you will need to create your own "test harness" that includes "test services" that can be inserted into the service graph and act as monitors or data-injectors. 

    I wish I had a simpler answer...  maybe someone else out there in RDS land has a suggestion?

    Friday, September 27, 2013 8:05 PM
  • Ok your advise makes sense. It is indeed a good practice to have the business logic in a seperate class. If doing so I can write unittest for the business logic.

    Still there is no way to test the service. So I cannot test the communication on the level of the service.

    The only thing I could come up with is to write another service and do the testing from there (as you descibe it like a test harness). But this is not a nice way to go...

    Monday, September 30, 2013 8:45 AM
  • That is correct.  To test the service itself requires other services interacting with it.  That takes you out of the realm of "unit testing" and into the realm of functional or end-to-end testing.

    Monday, September 30, 2013 5:20 PM