Geeks With Blogs

News
View Szymon Kobalczyk's profile on LinkedIn

Szymon Kobalczyk's Blog A Developer's Notebook

Here is another gem from the message boards (thanks to Justin Burtch):

One of the advantages of MVP is that it allows easier unit-testing. For this you need to declare all public methods of view that the presenter uses as an interface, and then you can easily substitute the actual view with its mock implementation. But to test all your components properly you need to run them in the same environment as when you run it in a GUI. By this I mean that you have some WorkItem that adds these items into the ManagedObjectCollections of the WorkItem. The WorkItem internally uses the ObjectBuilder to create the objects and initialize the properties as specified in the attributes that adorn the properties.

In the VSTS Test project for CAB, there is an object called TestableRootWorkItem. Create one of those and then add the view and controller into it's Items collection. That will get the ServiceDependency to be detected and initialized. Though the initialization you are doing by adding this WorkItem into the mix means that you're testing the CAB dependency injection framework and without a little manipulation of configuration of services, you are also testing your service. Just means that if the test breaks, you have a couple of classes you have to investigate.

Here is one example of such test from the SC-BAT project:

[TestMethod]  
public void ShowAppraisalCalledInResponseToEventBrokerEvent()
{
   TestableRootWorkItem wi = new TestableRootWorkItem();
   wi.Services.AddNew();
   AppraisalDetailPresenter presenter = wi.Items.AddNew();
   MockView view = new MockView();
   presenter.View = view;
   wi.EventTopics[Constants.EventTopics.WorkingAppraisalSelected]
     .Fire(this, new DataEventArgs("1"), wi, PublicationScope.Global);
   Assert.IsTrue( view.ShowAppraisalWasCalled);
}
Posted on Friday, January 13, 2006 8:54 PM Development , Smart Client | Back to top


Comments on this post: Unit-testing in CAB applications

# re: Unit-testing in CAB applications
Requesting Gravatar...
Your thread is interesting here, and I've stumbled across it looking for better samples of the framework's implemenation on how to best use it. Your example has helped. Do you think that you might be able to make your sample code available?

Thanks... good work.
Left by geoff on Jan 18, 2006 11:53 PM

# re: Unit-testing in CAB applications
Requesting Gravatar...
The sample is not complete yet but drop me your email and I can send you the code in current state.
Left by Szymon on Jan 19, 2006 6:00 AM

# re: Unit-testing in CAB applications
Requesting Gravatar...
Hey Szymon,

Was looking at this example here. Can you please send in the sample code to me as well, or provide me the link if its uploaded somewhere!

Thanking you in anticipation.

Regards,
Joteep
Left by Joteep on Apr 05, 2007 8:38 AM

# re: Unit-testing in CAB applications
Requesting Gravatar...
Sorry I forgot, my Email ID is: joteep@gmail.com
Left by Joteep on Apr 05, 2007 8:42 AM

# re: Unit-testing in CAB applications
Requesting Gravatar...
Can you send me the sample code for this testable workitem.

Regards,
Sathish. R
Left by Sathish on Oct 30, 2008 2:34 AM

# re: Unit-testing in CAB applications
Requesting Gravatar...
Can you please email me the source as well, or update the post?

Thanks!
Left by Brian H on Dec 10, 2008 5:23 PM

# re: Unit-testing in CAB applications
Requesting Gravatar...
Can you please email me the sample code
Left by Ajay on Sep 30, 2009 6:01 AM

# re: Unit-testing in CAB applications
Requesting Gravatar...
Sorry, I forgot my mail id

k_ajay_kumar@yahoo.com
Left by Ajay on Sep 30, 2009 6:04 AM

Your comment:
 (will show your gravatar)


Copyright © Szymon Kobalczyk | Powered by: GeeksWithBlogs.net