FlexUnit tests for mediators and mock objects

yung.melissa's Avatar

yung.melissa

11 Jul, 2013 03:13 PM

Hey guys

I am implementing FlexUnit tests and have started with my MainMediator and am wondering about the call to onRegister() in the test setup. I am hitting an error once it reaches the line addContextListener(...) in my onRegister() method. I am creating all the required instances prior to the test. My MainMediator, MainView and my ApplicationModel and injecting them.

Error #1009: Cannot access a property or method of a null object reference.
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at org.robotlegs.base::EventMap/mapListener()[/Development/Projects/Robotlegs/robotlegs-framework/src/org/robotlegs/base/EventMap.as:118]
at org.robotlegs.mvcs::Mediator/addContextListener()[/Development/Projects/Robotlegs/robotlegs-framework/src/org/robotlegs/mvcs/Mediator.as:140]

Note that when I don't call the onRegister, my test works but I'm not too confident I'm doing it right!

Read a lot on the internet but got confused once I started reading about mocking objects and how it all fit together and how to get them to work. I suspect that that should/might be the way of proceeding instead of creating all those required dependent objects.

Bit confused right now.
Would love your help if you could please advise!

Thanks!

  1. 1 Posted by Stray on 11 Jul, 2013 04:00 PM

    Stray's Avatar

    In the test set up function you need to supply the mediator with an instance of an eventDispatcher to use - normally this gets injected when the mediator is created.

    myTestMediatorInstance.eventDispatcher = new EventDispatcher();

    will do it.

    hth,

    Stray

  2. 2 Posted by yung.melissa on 12 Jul, 2013 08:59 AM

    yung.melissa's Avatar

    ah oops!

    That did help.
    Thanks! :)

  3. yung.melissa closed this discussion on 15 Jul, 2013 12:52 PM.

Comments are currently closed for this discussion. You can start a new one.

Keyboard shortcuts

Generic

? Show this help
ESC Blurs the current field

Comment Form

r Focus the comment reply box
^ + ↩ Submit the comment

You can use Command ⌘ instead of Control ^ on Mac