Page 2 of 2 FirstFirst 12
Results 11 to 13 of 13

Thread: How do I set a variable in flow scope in a unit test?

  1. #11

    Default

    Quote Originally Posted by theseion View Post
    Well, I'd say there's definitely room for improvement on this matter. What's the use of such a construct if you can't have it in you test...
    Allow me to disagree on that. A var declared inside the flow is part of the flow being unit tested. So it doesn't make sense to replace it with something else. That would be analogous to unit testing a piece of code and wanting to replace its local variables during testing. Local variables are part of the code being tested. Unit testing is only supposed to provide different implementations of the flow's dependencies, not its internal variables.
    Nazaret Kazarian

  2. #12
    Join Date
    Apr 2009
    Posts
    22

    Default

    I want to answer that later, not enough time right now. Just on a quick notice, I did find a solution to my original question in this thread: http://forum.springsource.org/showth...on-render+test

    To set a flowScope variable, e.g. to test a specific state without going through all the other states, do the following:

    Code:
    setCurrentState("stateName"); //this configures the execution environment
    getFlowScope().put("varName", someObject); //set the variable
    One of my problems while playing around had been that I getFlowScope() would return null. The trick is to call setCurrentState() before that.

    I'll be back later to answer you last post.

    theseion

  3. #13
    Join Date
    Apr 2009
    Posts
    22

    Default

    So, finally I found time to answer your last post.

    I've thought about what you wrote and I agree. Still I find the current situation pretty annoying since every change to the flow not only requires a change to the tests but also an updated copy of the flow without the <var> declarations.

    I don't really have an understanding of the internals of Webflow but maybe something like a test switch parameter to the <var> tag could be a solution. E.g.:
    Code:
    <var name="myClass" class="com.package.MyClass" mock="true" />
    I'm not only sugesting this because I find it annoying to have a modified copy of the flow for the test but also because I found this setup do be error-prone: if I modify the flow, run the test but forgot to replace the test copy of the flow I will maybe discover any errors made later, once I do replace the test copy. But tracking a bug down at this point will be much more difficult since I was probably expecting problems in completely different area.

    Sorry for keeping you waiting so long.

    Cheers.

    -theseion

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •