Unit testing screen initalization

Topics: Getting Started
Nov 18, 2012 at 3:54 PM

I am trying to write unit tests for the initialization of my screens. The initialization process is triggered in the OnInitialize methods of my screens. These methods are protected as it makes no sense that they are called from the outside world...

The question is: how do I unit-test them? Should I make them public just for the sake of unit tests? Did I miss something?

Thanks in advance!

Nov 18, 2012 at 3:57 PM

Can't you use reflection to invoke OnInitialize method?

Nov 18, 2012 at 4:03 PM

I can, but it kinda felt "dirty"... But maybe it's only because I'm new to CM and unit-testing...

Nov 18, 2012 at 4:10 PM

Another simple option is to just call Activate on the view model. Initialization is just a synonim for first activation.

Nov 18, 2012 at 4:21 PM

OK, thanks for the fast answers!

By any chance, do you know of any open-source projects using CM (preferrably with unit tests) I could have a look at to improve my knowledge?

Nov 18, 2012 at 9:27 PM

I don't know of a fully tested CM project, but check the forum, I recall some posts about testing you could find quite useful.

Oct 22, 2013 at 2:47 PM
Hi Guys,

I was searching for the same thing today and found this post, as there was not a "complete" answer to the question I thought I would link to this post that I created that explains how I solved it:

http://www.developanddesign.co.uk/?p=93

Essentially you cast to IActivate and call the Activate method!


Cheers!