Szymon Kobalczyk's Blog

A Developer's Notebook

  Home  |   Contact  |   Syndication    |   Login
  81 Posts | 5 Stories | 150 Comments | 380 Trackbacks

News

Skype Me™! View Szymon Kobalczyk's profile on LinkedIn

Twitter












Article Categories

Archives

Post Categories

Image Galleries

Blogs I Read

Tools I Use

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

Feedback

# re: Unit-testing in CAB applications 1/18/2006 11:53 PM geoff
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.

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

# re: Unit-testing in CAB applications 4/5/2007 8:38 AM Joteep
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

# re: Unit-testing in CAB applications 4/5/2007 8:42 AM Joteep
Sorry I forgot, my Email ID is: joteep@gmail.com

Post Feedback

Title:
Name:
Email: (never displayed)
Url:
Comments: 
Please add 5 and 6 and type the answer here: