You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/interaction_based_testing.adoc
+11Lines changed: 11 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -952,6 +952,8 @@ it is only used to describe the interaction.
952
952
NOTE: A global mock can only be created for a class type. It effectively replaces
953
953
all instances of that type for the duration from mock creation up until the end of the feature method.
954
954
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
+
955
957
CAUTION: The declaration order of global mocks is relevant.
956
958
The `GroovySpy(global:true, <type>)` must come before all creations of new mocked/spied objects of `<type>`.
957
959
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
983
985
global mocks on the same types are properly guarded against each other, because a global mock changes the global state
984
986
for the mocked `Class` during execution.
985
987
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
+
986
997
.How Are Global Groovy Mocks Implemented?
987
998
****
988
999
Global Groovy mocks get their super powers from Groovy meta-programming. To be more precise,
Copy file name to clipboardExpand all lines: docs/parallel_execution.adoc
+1Lines changed: 1 addition & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -643,6 +643,7 @@ skinparam shadowing false
643
643
@endwbs
644
644
....
645
645
646
+
[[isolated-execution]]
646
647
=== Isolated Execution
647
648
648
649
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.
Copy file name to clipboardExpand all lines: docs/release_notes.adoc
+3Lines changed: 3 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -8,6 +8,9 @@ include::include.adoc[]
8
8
=== Breaking Changes
9
9
10
10
* 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>>
0 commit comments