spockframework / spockframework/spock
Mock Argument mismatch is hidden by Exceptions
Open
@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
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.