Mixing in test cases and/or mocks other than through inheritance

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Mixing in test cases and/or mocks other than through inheritance

Michael Bailey
Hi,

I love Spock, and have been promoting it at my job, but I have 2 cases where the basic inheritance mechanism of Spock is thwarting me:

1) Most important:  I am unable to share common test cases other than through inheritance. For example, I have a set of tests to do basic authentication, and a set to do basic authorization. In order to optionally these, I wind up with:

  • abstract OurFramework extends Specification
  • AuthenticationSpec extends OurFramework
  • AuthorizationSpec extends AuthenticationSpec
  • MySpec extends AuthenticationSpec

I can have MySpec extends AuthenticationSpec if that's all I needed, but if I just wanted AuthorizationSpec, I'd end up with a pile of duplicate code. This quickly becomes very complex, and leads to more duplication the more orthagonal the set of shared cases.

2) Less important but a nice-to-have:  you can't instantiate a Mock or Spy outside of a Specification. Whenever I need shared test setup, I end up using Mockito, which is nice, but not as concise as Spock Mocks.

Both of these needs would be addressed from a user point-of-view by allowing a trait to contain test cases or mocks. I've also heard about Groovy's Mixins, but this seems to be deprecated.

Does anything which would better handle these two cases exist, or might it be coming soon?

Thanks

--
You received this message because you are subscribed to the Google Groups "Spock Framework - User" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/spockframework.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Mixing in test cases and/or mocks other than through inheritance

Michael Bailey
Does anyone please have any ideas or thoughts on this?


On Wednesday, March 9, 2016 at 11:26:07 PM UTC-7, Michael Bailey wrote:
Hi,

I love Spock, and have been promoting it at my job, but I have 2 cases where the basic inheritance mechanism of Spock is thwarting me:

1) Most important:  I am unable to share common test cases other than through inheritance. For example, I have a set of tests to do basic authentication, and a set to do basic authorization. In order to optionally these, I wind up with:

  • abstract OurFramework extends Specification
  • AuthenticationSpec extends OurFramework
  • AuthorizationSpec extends AuthenticationSpec
  • MySpec extends AuthenticationSpec

I can have MySpec extends AuthenticationSpec if that's all I needed, but if I just wanted AuthorizationSpec, I'd end up with a pile of duplicate code. This quickly becomes very complex, and leads to more duplication the more orthagonal the set of shared cases.

2) Less important but a nice-to-have:  you can't instantiate a Mock or Spy outside of a Specification. Whenever I need shared test setup, I end up using Mockito, which is nice, but not as concise as Spock Mocks.

Both of these needs would be addressed from a user point-of-view by allowing a trait to contain test cases or mocks. I've also heard about Groovy's Mixins, but this seems to be deprecated.

Does anything which would better handle these two cases exist, or might it be coming soon?

Thanks

--
You received this message because you are subscribed to the Google Groups "Spock Framework - User" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/spockframework.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Mixing in test cases and/or mocks other than through inheritance

Kostis Kapelonis
Hello

Have you seen the presentation "Idiomatic Spock"?

http://www.slideshare.net/gr8conf/idiomatic-spock

Look at page 7 onwards that I think is close to your first question.

Kostis

On Thu, Mar 31, 2016 at 6:32 PM, Michael Bailey <[hidden email]> wrote:

> Does anyone please have any ideas or thoughts on this?
>
>
> On Wednesday, March 9, 2016 at 11:26:07 PM UTC-7, Michael Bailey wrote:
>>
>> Hi,
>>
>> I love Spock, and have been promoting it at my job, but I have 2 cases
>> where the basic inheritance mechanism of Spock is thwarting me:
>>
>> 1) Most important:  I am unable to share common test cases other than
>> through inheritance. For example, I have a set of tests to do basic
>> authentication, and a set to do basic authorization. In order to optionally
>> these, I wind up with:
>>
>> abstract OurFramework extends Specification
>> AuthenticationSpec extends OurFramework
>> AuthorizationSpec extends AuthenticationSpec
>> MySpec extends AuthenticationSpec
>>
>>
>> I can have MySpec extends AuthenticationSpec if that's all I needed, but
>> if I just wanted AuthorizationSpec, I'd end up with a pile of duplicate
>> code. This quickly becomes very complex, and leads to more duplication the
>> more orthagonal the set of shared cases.
>>
>> 2) Less important but a nice-to-have:  you can't instantiate a Mock or Spy
>> outside of a Specification. Whenever I need shared test setup, I end up
>> using Mockito, which is nice, but not as concise as Spock Mocks.
>>
>> Both of these needs would be addressed from a user point-of-view by
>> allowing a trait to contain test cases or mocks. I've also heard about
>> Groovy's Mixins, but this seems to be deprecated.
>>
>> Does anything which would better handle these two cases exist, or might it
>> be coming soon?
>>
>> Thanks
>
> --
> You received this message because you are subscribed to the Google Groups
> "Spock Framework - User" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [hidden email].
> To post to this group, send email to [hidden email].
> Visit this group at https://groups.google.com/group/spockframework.
> For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Spock Framework - User" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/spockframework.
For more options, visit https://groups.google.com/d/optout.
Loading...