spockframework / spockframework/spock

Dynamic method names in interactions

Open
#254 6 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

Originally reported on Google Code with ID 132

Specify interactions on method names defined by a variable

It is very useful when several methods share testing code. You could parameterize the
methods name to test. Example:

def 'm1, m2 and m3 delegate its execution'(){
given:
def myObject = myObject(delegateMock)

when: 
myObject."$methodName"()
then:
1 * delegateMock."do$methodName"()

where:
 methodName << ['m1', 'm2', 'm3']
}


Reported by eamodeorubio on 2010-10-15 15:26:48

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 source file, test, or entry point. Start by locating existing interaction and data-driven specification tests, then try the supplied parameterized method-name example. Done means interactions accept method names built from variables and the example passes for m1, m2, and m3.

Written by the indexing model from the issue text.

Assessment

Tech stack
groovy
Domain
testing
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.