spockframework / spockframework/spock

Spock fails with insufficient invocation count when route cause was underneath exception

Open
#849 5 comments 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Java
Stars
3.6k
Forks
483
PR merge metrics
No merged PRs in 30d

Description

Assuming we use groovy and assuming we have such service method:

method(input){ Long val = Optional.ofNullable(input).map(Integer::longValue).orElse(doesntmatter);
return otherService.something(val);
}

Also assuming we expect that second service Mock will be invoked once (1 * otherService...).
When passing Long as "input" parameter i would expect exception:

java.lang.ClassCastException: java.lang.Long cannot be cast to java.lang.Integer

But what i get is failed invocation count for otherService shadowing underneath exception.

Removing count check results in correct behaviour - exception being properly handled.

For me it looks like Spock completely ignores underneath exceptions in case of failed invocation count checks.

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

Start with a minimal Groovy specification using an interaction count check and the service method described in the issue, then inspect how failed invocation counts and underlying exceptions are handled. Done means the ClassCastException is reported instead of being hidden by the insufficient invocation count failure.

Written by the indexing model from the issue text.

Assessment

Tech stack
groovy, java
Domain
testing
Issue type
Bug
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.