Announcement Announcement Module
No announcement yet.
Is there a way to use Mockito-flex with Spring Actionscript Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Is there a way to use Mockito-flex with Spring Actionscript

    Hi, all.
    I'm writing tests that exercise an application managed using spring-actionscript. I would like to be able to mock one of the classes managed by spring-actionscript. Wondering if anyone can suggest a way to do this. I'll need to not only replace the instance used by spring-as, but I'll also need to be able to set up the instance for verification before any objects are requested from spring-as.
    Thanks much.

  • #2
    I got this response from Kris on the mockito-flex forum where I posted the same question.

    Using IoC ensures that the dependencies are provided externally to the
    entities. I assume the class you are testing requires several external
    dependencies and some of them you want to mock. I'd create all needed stuff
    and assign manually in the test - if you are unit testing.

    I assume you want to run more of a functional/integration style of test
    where you have everything real except say the service endpoints. I'm not
    familiar with spring-actionscript, but in projects I was working on we were
    able to replace beans with mocks in contexts before initializing and
    autowiring the context itself.

    The algorithm is:
    1) create new instance of a context
    2) create mock replacements
    3) replace beans with mocks
    4) run context initialization
    I think you should get closer with the spring-action script guys. I know
    they were using mockito for testing and may have some better idea.


    I'm unsure where the extension points should be. Any pointers would be much appreciated. Can I tell the context, "when you get a request for this bean, use this mock instead"? Another hurdle is how to deal with the asynchronous class preparation process involved in mocking. Can the context be paused while some (for example) factory method asynchronously creates a mock? My understanding is that SpringAS's wiring is synchronous.

    Thanks much.
    Last edited by jaabio; Nov 17th, 2010, 03:27 PM.


    • #3
      test framework

      Hey Kris,

      to be honest, we don't have any experience with Mockito, nor do we use it in Spring Actionscript itself. Have you had a look at the new testing framework that was added in the 1.1 release?

      It integrates with Flex unit 4, and when using ASMock in combination with that, the asynchronous creation of the mocks will be solved automatically as well, since the ASMock testrunner will generate all the mocks before any tests are running.

      If you have no choice but to use Mockito then i can't really help you much, since I'm not familiar with the library, I'm sorry. Currently there is no support for asynchronous classes in Spring Actionscript.

      Hope that help a little, good luck and if you have any more questions please feel free to ask.




      • #4
        Thanks Roland.
        Are there any examples or resources on using SpringAS with ASMock? I'm having difficulty understanding how SpringAS uses the mocks when the mock classes can't be defined in the SpringAS configuration XML since their names are not known till runtime. Do you have to mock the classes, create the context, request the mocks from ASMock and then, in code, add object definitions to the context for the mocks before calling load()?
        Last edited by jaabio; Nov 18th, 2010, 03:27 PM.


        • #5
          I'm not sure if the questions has been answered, or if you've found a solution to it on your own, but the testing framework allows you to load test specific contexts. I'm having a little trouble understanding the use-case though. If the name of the class is not known until runtime, it could never be declared in an application context. You could declare a factory in the application context and use that to generate the runtime classes though. Can you be more specific about a particular use-case you are trying to implement?