https://github.com/joke/spock-deepmock
Deep mocking for the Spock Framework
https://github.com/joke/spock-deepmock
mocking spock-extension spock-framework
Last synced: 5 months ago
JSON representation
Deep mocking for the Spock Framework
- Host: GitHub
- URL: https://github.com/joke/spock-deepmock
- Owner: joke
- License: apache-2.0
- Created: 2016-10-31T08:04:30.000Z (over 9 years ago)
- Default Branch: main
- Last Pushed: 2025-11-07T18:28:20.000Z (8 months ago)
- Last Synced: 2025-11-07T20:26:59.423Z (8 months ago)
- Topics: mocking, spock-extension, spock-framework
- Language: Java
- Homepage:
- Size: 298 KB
- Stars: 6
- Watchers: 1
- Forks: 1
- Open Issues: 11
-
Metadata Files:
- Readme: README.adoc
- Changelog: CHANGELOG.md
- Contributing: CONTRIBUTING.adoc
- License: LICENSE
- Codeowners: .github/CODEOWNERS
Awesome Lists containing this project
README
= `spock-deepmock`
:icons: font
image:https://github.com/joke/spock-deepmock/workflows/build/badge.svg?branch=master[]
image:https://img.shields.io/github/license/joke/spring-factory[GitHub]
image:https://img.shields.io/maven-central/v/io.github.joke/spock-deepmock?label=latest%20version[link=https://search.maven.org/artifact/io.github.joke/spock-deepmock]
image:https://img.shields.io/badge/Conventional%20Commits-1.0.0-yellow.svg[link=https://conventionalcommits.org]
image:https://img.shields.io/badge/pre--commit-enabled-brightgreen?logo=pre-commit[pre-commit, link=https://github.com/pre-commit/pre-commit]
`spock-deepmock` adds deep mocking capabilities to the http://spockframework.org/[Spock Framework].
In contrast to builtin http://spockframework.org/spock/docs/1.3/all_in_one.html#_mocking[mocks]
a deep mock will return another deep mock object automatically. This way there
is no need to define chains of nested mocks.
* Adds `DeepMock()` and `GroovyDeepMock()` for deep mocking
* Build deep mocking chains for nested objects
* Uses same syntax as the builtins `Mock()` and `GroovyMock()`
* Supports interaction verification
* Works with Spock Framework 2.0, 2.1, 2.2 and 2.3
== Gradle Dependency
image:https://img.shields.io/maven-central/v/io.github.joke/spock-deepmock?label=latest%20version[link=https://search.maven.org/artifact/io.github.joke/spock-deepmock]
.build.gradle
[source,groovy]
----
dependencies {
testImplementation 'io.github.joke:spock-deepmock:x.y.z'
}
----
== Maven Dependency
.pom.xml
[source,xml]
----
io.github.joke
spock-deepmock
x.y.z
test
----
== Usage
Deep mocks can be defined as any other mock. Features like options are supported.
.Define deep mocks
[source,groovy]
----
def mock = DeepMock(Nested)
Nested mock = DeepMock()
def mock = DeepMock(name: 'customName')
Nested mock = DeepMock(name: 'customName')
----
.CallerTest.groovy
[source,groovy]
----
def 'calling nested mock'() {
setup:
Nested mock = DeepMock()
def caller = new Caller(mock)
when:
// calls mock.getChild().getChild().getName()
def res = caller.nameOfSubSubChild()
then:
1 * mock.child.child.name >> 'Hello'
expect:
res == 'Hello'
}
----
Further examples in link:examples-java[] or link:examples-groovy[].