spockframework / spockframework/spock

Test Mixins

Open
#340 8 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Module-Core Type-NewFeature
Dominant language
Java
Stars
3.6k
Forks
483
PR merge metrics
No merged PRs in 30d

Description

Originally reported on Google Code with ID 218

There are situations where a bunch of tests should be applied to a code base. We are
currently using derived classes which is a pain, especially when your code under tests
should support either only a subset or  multiple category of tests (which results in
many abstract base specs and many concrete specs for the code under test ...)

This could be solved with test mixins in an elegant way. Here is an example 

class SpecMixin (extends SpecificationMixin?) {

  def "test something"() {
    when:
    objectUnderTest.doSomething()
    then:
    objectUnderTest.somethingDone()
  }

}

@Mixin(SpecMixin)
class RealSpec extends Specification {
  def objectUnderTest = new ObjectUnderTest()
}

The mixin, as well as the test should be able to access properties (as done with objectUnderTest
in this example) and the test lifecycle methods should be mixed in as well.

Reported by peter.rietzler@gmx.net on 2011-12-02 18:16:03

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

The issue names no implementation files, tests, or entry points. Start by locating Spock's specification and mixin handling, then assess how the requested example should support shared properties, test methods, and lifecycle methods; done means the mixin can be applied to a specification with those behaviors working together.

Written by the indexing model from the issue text.

Assessment

Tech stack
groovy
Domain
testing
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.