Skip to content

Commit 19fae4e

Browse files
committed
Update documentation
1 parent e501cfd commit 19fae4e

File tree

3 files changed

+15
-0
lines changed

3 files changed

+15
-0
lines changed

docs/interaction_based_testing.adoc

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -952,6 +952,8 @@ it is only used to describe the interaction.
952952
NOTE: A global mock can only be created for a class type. It effectively replaces
953953
all instances of that type for the duration from mock creation up until the end of the feature method.
954954

955+
CAUTION: Using global mocks for standard types from the JDK, for example `ArrayList`, is a bad idea and can lead to unforeseen and widespread consequences.
956+
955957
CAUTION: The declaration order of global mocks is relevant.
956958
The `GroovySpy(global:true, <type>)` must come before all creations of new mocked/spied objects of `<type>`.
957959
The global spies will only take effect on objects of that type, if the `GroovySpy(global:true, <type>)` was
@@ -983,6 +985,15 @@ When `Specifications` or `Features` are executed concurrently you have to make s
983985
global mocks on the same types are properly guarded against each other, because a global mock changes the global state
984986
for the mocked `Class` during execution.
985987

988+
[[global-mocks-parallel-execution]]
989+
==== Global mocks and parallel execution
990+
991+
Creating a global `GroovyMock`/`GroovyStub`/`GroovySpy` when <<parallel-execution.adoc#parallel-execution,parallel execution>> is enabled,
992+
requires that the spec is annotated with <<parallel-execution.adoc#isolated-execution, @Isolated>> or `@@ResourceLock(org.spockframework.runtime.model.parallel.Resources.META_CLASS_REGISTRY)`.
993+
If it is only used for a feature, then it suffices that the feature is annotated with `@ResourceLock(org.spockframework.runtime.model.parallel.Resources.META_CLASS_REGISTRY)`.
994+
The rule of thumb to choose between `@ResourceLock` and `@Isolated`, is to look at how widespread the mocked type is used.
995+
If it is widely used, then `@Isolated` is the safe choice, otherwise `@ResourceLock` may be sufficient.
996+
986997
.How Are Global Groovy Mocks Implemented?
987998
****
988999
Global Groovy mocks get their super powers from Groovy meta-programming. To be more precise,

docs/parallel_execution.adoc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -643,6 +643,7 @@ skinparam shadowing false
643643
@endwbs
644644
....
645645

646+
[[isolated-execution]]
646647
=== Isolated Execution
647648

648649
Sometimes, you want to modify and test something that affects every other feature, you could put a `READ` `@ResourceLock` on _every_ feature, but that is impractical.

docs/release_notes.adoc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ include::include.adoc[]
88
=== Breaking Changes
99

1010
* Calling `old(...)` with multiple arguments is now a compilation error. Previously the additional arguments were simply ignored.
11+
* Creating `GroovyMock`/`GroovyStub`/`GroovySpy` for an already mocked type will now fail.
12+
* Creating a global `GroovyMock`/`GroovyStub`/`GroovySpy` when <<parallel-execution.adoc#parallel-execution, parallel execution>> is enabled,
13+
will now require that the spec is annotated with <<parallel-execution.adoc#isolated-execution, @Isolated>> or `@@ResourceLock(org.spockframework.runtime.model.parallel.Resources.META_CLASS_REGISTRY)`. See <<interaction-based-testing.adoc#global-mocks-parallel-execution, Global mocks and parallel execution>>
1114

1215
== 2.4-M1 (2022-11-30)
1316

0 commit comments

Comments
 (0)