Menu

#3 request for JMockit test creation to add @RunWith(JMockit.class)

v1.0 (example)
closed
None
5
2015-01-21
2014-06-19
No

It would be great if generating a test of JMockit style added the @RunWith(JMockit.class) annotation to the class.

Keep up the great work, thanks!

Discussion

  • Nicolas Demengel

    Hi dear Alchemist :-)

    I apologize for the very late answer :-\

    Indeed, it looks like something is missing here. We added the JMockit support at the request of another user, but as we aren't ourselves using JMockit, we based our template solely on her example.

    Unfortunately we haven't worked hard on MoreUnit this year. But this surely something we could integrate in a future version. Meanwhile, you can add you own template for JMockit, see http://moreunit.sourceforge.net/#doc-mocksupport (at the very bottom of the page, sorry for the succint documentation).

    Regards,
    Nicolas

     
  • The Alchemist

    The Alchemist - 2014-07-28

    I submitted a pull request, but I'm not sure why it doesn't work. Any ideas, Nicolas?

     
  • Vera Henneberger

    Hi Alchemist,

    sorry for the late answer (again).
    At the moment we are both very busy with our personal lives...
    We hope to give you some feedback soon.

    Vera

     
  • Nicolas Demengel

    Hi Alchemist,

    I finally had a look at your template: it works perfectly for me. That said, I don't know how you tested it: did you build MoreUnit with that change, or did you put the template in your <workspace>/.metadata/.plugins/org.moreunit.mock/templates directory ? In the later case, be sure to give the template a different id, or it will be rejected (normally with an error in a popup window).

    It should work if you put a .xml file in the previously mentioned directory, with the following content :
    <?xml version="1.0" encoding="UTF-8" ?>

    <mocking-templates version="1.0">
        <category id="org.moreunit.mock.jmockit" name="JMockit"/>
        <mocking-template
            id="org.moreunit.mock.jmockitUsingJunitRunWith"
            category="org.moreunit.mock.jmockit"
            name="Using JUnit's @RunWith">
            <code-template id="jmockitRunnerDeclaration" part="test-class-annotation">
                <include-if condition="test-type" value="junit4"/>
                <pattern><![CDATA[@${runWith:newType(org.junit.runner.RunWith)}(${runner:newType(mockit.integration.junit4.JMockit)}.class)]]></pattern>
            </code-template>
            <code-template id="dependencyDeclaration" part="test-class-fields">
                <pattern><![CDATA[
    
                    @${injectableAnnotation:newType(mockit.Injectable)} private ${dependencyType} ${dependency};
                ]]></pattern>
            </code-template>
            <code-template id="objectUnderTestDeclaration" part="test-class-fields">
                <pattern><![CDATA[
    
                    @${mockAnnotation:newType(mockit.Tested)} private ${objectUnderTestType} ${objectUnderTest};
                ]]></pattern>
            </code-template>
        </mocking-template>
    </mocking-templates>
    

    You can then either restart Eclipse or click on Preferences > MoreUnit > Java > Mock Generation > Reload templates, and then choose the template JMockit > Using JUnit's @RunWith

    Also, I will include your template in the next version of MoreUnit, as another JMockit template named "Using JUnit's @RunWith", in order to let the default template aligned with what seems to be JMockit's default way of configuring it.

    As an aside: unfortunately we have been very bad at answering MoreUnit's users for one year... I shall be more available now, at the very least until mid-September, so don't hesitate to ask for more help if needed.

    Nicolas

     
  • The Alchemist

    The Alchemist - 2014-08-21

    @Nicolas: I tested it by running MoreUnit as an Eclipse application (Run As -> Eclipse Application/PlugIn; I forget which one exactly).

    Thanks for including it!

    May I suggest making it the default if "JMockit" is selected? Otherwise, it might not work properly and people might blame MoreUnit. :(

     
  • Nicolas Demengel

    Conversely, users used to the current behavior might be surprised!

    That said, given the magic needed for JMockit to work without @RunWith, it's likely better to follow your advice and make it the default, with another profile called "Without JUnit's @RunWith" for people liking the current behavior.

    Many thanks for your help!

     
  • The Alchemist

    The Alchemist - 2014-08-22

    No problem, thanks for the great piece of software!

     
  • Nicolas Demengel

    Ready to ship: @RunWith(JMockit.class) is now the default. And some more documentation has been written, and there is now an XSD.

     

    Last edit: Nicolas Demengel 2015-01-21
  • Nicolas Demengel

    • status: open --> closed
    • assigned_to: Nicolas Demengel
     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.