spockframework / spockframework/spock

Mock Argument mismatch is hidden by Exceptions

Open
#1,071 2 comments 0 reactions 1 assignee View on GitHub

@leonard84 is already working on this.

Since Jan 10, 2020.

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

Description

  def "NPE"() {
    given:
    List<String> list = Mock()

    when:
    def len = list.get(1).length()

    then:
    len == 5
    1 * list.get(0) >> "hello"
  }

Fails with java.lang.NullPointerException: Cannot invoke method length() on null object. We loose any information, that this was caused by a wrong argument to the mock.

If there are Unmatched invocations, then they should be reported as well.

Too few invocations for:

1 * list.get(0) >> "hello"   (0 invocations)

Unmatched invocations (ordered by similarity):

1 * list.get(1)
One or more arguments(s) didn't match:
0: argument == expected
   |        |  |
   1        |  0
            false

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.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.