Writing under-the-UI acceptance tests with Caliburn

Topics: Bootstrappers & IoC
Mar 14, 2012 at 1:16 PM
Edited Mar 14, 2012 at 1:16 PM

First up... I'm a fan! I still haven't wrapped my head around the Coroutines stuff in the Mix10 talk but that's me not being able to concentrate :)

Here's my question.(I've gone through Rob's Mix10 talk > 2 times ; though not really built non-trivial apps with caliburn. So have a slight idea about the theory but no practice).

Caliburn.Micro is a View-Model first framework (which is great).

I'm assuming that the preferred approach of composing the app is also via composing viewmodels (and attaching the right views to them as a secondary step)

Following the MVP / MVVM pattern has made unit tests easy. Does Caliburn.Micro scale this idea to the system-level too ? (More details on where I'm headed). I'm trying to "peel the UI off" the app and test via the VM layer.

Technically I'd like to

  • load up the whole app in-process within my test-runner process
  • then find existing ViewModel instances from the container (this step should fail if an instance doesn't exist at that point of time).. i.e. this is != _container.ComposeExportedValue<VMType>
  • prod and poke the VM properties/commands to manipulate the app

Does this appear feasible with Caliburn ?


public void TestSomething()
   InitializeApp(); // do whatever is needed to mimic startup
   var vm = GetViewModel<LoginViewModel>()
   vm.UserName = "uname"
   vm.Password = "pwd"


How difficult would it be to implement InitializeApp() and GetViewModel ?

I see the Bootstrapper takes a UseApplication flag that looks useful. RFC

Mar 14, 2012 at 1:29 PM

It is completely possible and has been done before :)  In fact a very similar approach to testing was used with NhProf (http://nhprof.com/)

If you can push all state into your view models, it makes testing really easy. Also remember that with Caliburn.Micro, you don't need to use command objects, you can just use normal methods, so it can make tests even simpler. If you want to invoke CM's full action pipeline as part of the test, you can do that too using a helper method: Action.Invoke (just be careful that if your actions make use of view dependencies, that you have those set up).

Mar 14, 2012 at 3:01 PM
Edited Mar 14, 2012 at 3:02 PM

At work, Prism is pervasive. The prism documentation didn't explicitly mention that it did not support viewmodel-first composition & I lost weeks trying to get an answer. The official answer was no :( It's View-first centric design basically outlawed testing without the UI.

Thanks Rob for the confirmation. I'll now take a deep-dive into this project & docs before I ask more questions. Do you have any pointers to existing & public test-code that I could use as reference (instead of learning by trial-and-error) ?