[jira] Created: (JMOCK-222) An ability to use annotation to create mock objects

View: New views
6 Messages — Rating Filter:   Alert me  

[jira] Created: (JMOCK-222) An ability to use annotation to create mock objects

by JIRA jira@codehaus.org :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

An ability to use annotation to create mock objects
---------------------------------------------------

                 Key: JMOCK-222
                 URL: http://jira.codehaus.org/browse/JMOCK-222
             Project: jMock
          Issue Type: Improvement
          Components: JMock 2.x.x Library
    Affects Versions: 2.5.0
            Reporter: Ignat Zapolsky


Hi,

it could be very nice to have an ability to mark fields in test case to be mocked.

For example, any field in test case marked with annotation @Mocked will be assigned a value.

Actually, I have implemented such feature for Jmock 2.5.0 & Junit 4.4 and I'll include sample code.

--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://jira.codehaus.org/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

       

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email



[jira] Updated: (JMOCK-222) An ability to use annotation to create mock objects

by JIRA jira@codehaus.org :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


     [ http://jira.codehaus.org/browse/JMOCK-222?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Ignat Zapolsky updated JMOCK-222:
---------------------------------

    Attachment: JMockRunner.java
                Mocked.java

Annotation source code, Runner source code.

> An ability to use annotation to create mock objects
> ---------------------------------------------------
>
>                 Key: JMOCK-222
>                 URL: http://jira.codehaus.org/browse/JMOCK-222
>             Project: jMock
>          Issue Type: Improvement
>          Components: JMock 2.x.x Library
>    Affects Versions: 2.5.0
>            Reporter: Ignat Zapolsky
>         Attachments: JMockRunner.java, Mocked.java
>
>
> Hi,
> it could be very nice to have an ability to mark fields in test case to be mocked.
> For example, any field in test case marked with annotation @Mocked will be assigned a value.
> Actually, I have implemented such feature for Jmock 2.5.0 & Junit 4.4 and I'll include sample code.

--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://jira.codehaus.org/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

       

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email



[jira] Commented: (JMOCK-222) An ability to use annotation to create mock objects

by JIRA jira@codehaus.org :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


    [ http://jira.codehaus.org/browse/JMOCK-222?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=174026#action_174026 ]

Steve Freeman commented on JMOCK-222:
-------------------------------------

it's true that we trigger a certain amount of repetitive code which mockito, for one, avoids with annotations.

My problem with this suggestion is that for it to work I'd have to turn off the compiler warning about using uninitialised values. I've developed a habit of making as many fields final as possible to reduce mutability.

> An ability to use annotation to create mock objects
> ---------------------------------------------------
>
>                 Key: JMOCK-222
>                 URL: http://jira.codehaus.org/browse/JMOCK-222
>             Project: jMock
>          Issue Type: Improvement
>          Components: JMock 2.x.x Library
>    Affects Versions: 2.5.0
>            Reporter: Ignat Zapolsky
>         Attachments: JMockRunner.java, Mocked.java
>
>
> Hi,
> it could be very nice to have an ability to mark fields in test case to be mocked.
> For example, any field in test case marked with annotation @Mocked will be assigned a value.
> Actually, I have implemented such feature for Jmock 2.5.0 & Junit 4.4 and I'll include sample code.

--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://jira.codehaus.org/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

       

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email



[jira] Commented: (JMOCK-222) An ability to use annotation to create mock objects

by JIRA jira@codehaus.org :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


    [ http://jira.codehaus.org/browse/JMOCK-222?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=174043#action_174043 ]

Ignat Zapolsky commented on JMOCK-222:
--------------------------------------

I'd rather use annotation that could force compiler to emit extra code, since mock object type is available from declaration type. This change could require more efforts than runtime version (which is mostly straightforward).

Unfortunately there is no well-defined @SuppresWarnings annotation value to get rid of "usage of uninitialized variable".

> An ability to use annotation to create mock objects
> ---------------------------------------------------
>
>                 Key: JMOCK-222
>                 URL: http://jira.codehaus.org/browse/JMOCK-222
>             Project: jMock
>          Issue Type: Improvement
>          Components: JMock 2.x.x Library
>    Affects Versions: 2.5.0
>            Reporter: Ignat Zapolsky
>         Attachments: JMockRunner.java, Mocked.java
>
>
> Hi,
> it could be very nice to have an ability to mark fields in test case to be mocked.
> For example, any field in test case marked with annotation @Mocked will be assigned a value.
> Actually, I have implemented such feature for Jmock 2.5.0 & Junit 4.4 and I'll include sample code.

--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://jira.codehaus.org/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

       

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email



[jira] Commented: (JMOCK-222) An ability to use annotation to create mock objects

by JIRA jira@codehaus.org :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


    [ http://jira.codehaus.org/browse/JMOCK-222?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=174589#action_174589 ]

Nat Pryce commented on JMOCK-222:
---------------------------------

I like this suggestion.  Code that creates named mock objects is repetitive and this could solve that.  I've run the idea past a few people and they all like it.

My one reservation is that test setup is no longer explicit.  I think implementing this as a subclass of the JMock test-runner is a good idea, maybe named JMockMagic or something similar to warn the reader that magic set-up is happening.

Unused variable warnings can be avoided by making the variables package-protected.  I usually don't bother to make fields private in test classes anyway.  I do like them to be final, but there may be some reflection workaround for that.

The code submitted is not acceptable as it stands. It will fail if there are two mock objects of the same type, for example, does not  name the mock objects after the field names, and is written to an old version of JUnit 4.  

However, we'll implement something like this in a forthcoming JMock version.



> An ability to use annotation to create mock objects
> ---------------------------------------------------
>
>                 Key: JMOCK-222
>                 URL: http://jira.codehaus.org/browse/JMOCK-222
>             Project: jMock
>          Issue Type: Improvement
>          Components: JMock 2.x.x Library
>    Affects Versions: 2.5.0
>            Reporter: Ignat Zapolsky
>         Attachments: JMockRunner.java, Mocked.java
>
>
> Hi,
> it could be very nice to have an ability to mark fields in test case to be mocked.
> For example, any field in test case marked with annotation @Mocked will be assigned a value.
> Actually, I have implemented such feature for Jmock 2.5.0 & Junit 4.4 and I'll include sample code.

--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://jira.codehaus.org/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

       

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email



[jira] Commented: (JMOCK-222) An ability to use annotation to create mock objects

by JIRA jira@codehaus.org :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


    [ http://jira.codehaus.org/browse/JMOCK-222?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=174590#action_174590 ]

Steve Freeman commented on JMOCK-222:
-------------------------------------

I think there's a good case to be made for an alternative lighter-weight API in general.
We can do this as an extension and people can use the version they like.

> An ability to use annotation to create mock objects
> ---------------------------------------------------
>
>                 Key: JMOCK-222
>                 URL: http://jira.codehaus.org/browse/JMOCK-222
>             Project: jMock
>          Issue Type: Improvement
>          Components: JMock 2.x.x Library
>    Affects Versions: 2.5.0
>            Reporter: Ignat Zapolsky
>         Attachments: JMockRunner.java, Mocked.java
>
>
> Hi,
> it could be very nice to have an ability to mark fields in test case to be mocked.
> For example, any field in test case marked with annotation @Mocked will be assigned a value.
> Actually, I have implemented such feature for Jmock 2.5.0 & Junit 4.4 and I'll include sample code.

--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://jira.codehaus.org/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

       

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email