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
NOTE: JUnit Jupiter also supports https://junit.org/junit5/docs/5.7.0/user-guide/#writing-tests-parallel-execution[parallel execution], both rely on the JUnit Platform implementation, but function independently of each other.
23
+
NOTE: JUnit Jupiter also supports https://junit.org/junit5/docs/5.7.0/user-guide/#writing-tests-parallel-execution[parallel execution], both rely on the JUnit Platform implementation, but function independently of each other.
24
24
If you enable parallel execution in Spock it won't affect Jupiter and vice versa.
25
25
The JUnit Platform executes the test engines (Spock, Jupiter) sequentially, so there should not be any interference between engines.
Copy file name to clipboardExpand all lines: docs/spock_primer.adoc
+29-11Lines changed: 29 additions & 11 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -17,7 +17,7 @@ To learn more about unit testing, go to https://en.wikipedia.org/wiki/Unit_testi
17
17
18
18
Let's start with a few definitions: Spock lets you write https://en.wikipedia.org/wiki/Specification_by_example[_specifications_]
19
19
that describe expected _features_ (properties, aspects) exhibited by a system of interest. The system of interest could be
20
-
anything between a single class and a whole application, and is also called the _system under specification or SUS_.
20
+
anything between a single class and a whole application, and is also called the _system under specification_ or _SUS_.
21
21
The description of a feature starts from a specific snapshot of the SUS and its collaborators; this snapshot is called the feature's _fixture_.
22
22
23
23
The following sections walk you through all building blocks of which a Spock specification may be composed. A typical
@@ -48,9 +48,9 @@ A specification is represented as a Groovy class that extends from `spock.lang.S
48
48
usually relates to the system or system operation described by the specification. For example, `CustomerSpec`,
49
49
`H264VideoPlayback`, and `ASpaceshipAttackedFromTwoSides` are all reasonable names for a specification.
50
50
51
-
Class `Specification` contains a number of useful methods for writing specifications. Furthermore it instructs JUnit to
52
-
run specification with `Sputnik`, Spock's JUnit runner. Thanks to Sputnik, Spock specifications can be run by most modern
53
-
Java IDEs and build tools.
51
+
Class `Specification` contains a number of useful methods for writing specifications. Furthermore it marks the specification
52
+
as `@Testable`, which instructs tools that only look at the source code - like typically IDEs and similar - that this
53
+
class is something that executes tests via a JUnit Platform engine.
54
54
55
55
== Fields
56
56
@@ -841,20 +841,38 @@ block descriptions are enhanced diagnostic messages, and textual reports that ar
841
841
842
842
As we have seen, Spock offers lots of functionality for writing specifications. However, there always comes a time
843
843
when something else is needed. Therefore, Spock provides an interception-based extension mechanism. Extensions are
844
-
activated by annotations called _directives_. Currently, Spock ships with the following directives:
844
+
activated by annotations called _directives_. Currently, Spock ships - among others - with the following directives:
845
845
846
846
[horizontal]
847
847
`@Timeout`:: Sets a timeout for execution of a feature or fixture method.
848
848
849
849
`@Ignore`:: Ignores any feature method carrying this annotation.
850
850
851
-
`@IgnoreRest`:: Any feature method carrying this annotation will be executed, all others will be ignored. Useful for quickly running just a single method.
851
+
`@IgnoreRest`:: Any feature method carrying this annotation will be executed, all others will be ignored. Useful for quickly running just a few features.
852
852
853
853
`@FailsWith`:: Expects a feature method to complete abruptly. `@FailsWith` has two use cases: First, to document known bugs that cannot
854
854
be resolved immediately. Second, to replace exception conditions in certain corner cases where the latter cannot be
855
855
used (like specifying the behavior of exception conditions). In all other cases, exception conditions are preferable.
856
856
857
-
Go to the <<extensions.adoc#extensions,Extensions>> chapter to learn how to implement your own directives and extensions.
857
+
Go to the <<extensions.adoc#extensions,Extensions>> chapter to learn how to implement your own directives and extensions,
858
+
to learn where to find some of the 3rd party extensions, and to learn about all built-in extensions and directives.
859
+
860
+
[NOTE]
861
+
--
862
+
JUnit Jupiter is a separate test engine also running on JUnit Platform and thus is a sibling of the Spock engine.
863
+
Extensions written for JUnit Jupiter do _not_ work in Spock specifications out of the box. Often terms are mixed up and
864
+
some extension says it is for JUnit 5+, actually meaning it is for JUnit Jupiter, as there are no generic JUnit Platform
865
+
extensions. If you want to use an extension written for JUnit Jupiter, you can check whether the project also provides
866
+
a Spock extension, if not ask them to also provide a Spock extension, search for an alternative extension that supports
867
+
Spock, or port the Jupiter extension to being a Spock extension yourself.
868
+
869
+
There is also at least one 3rd party extension that as of this writing provides a partly functioning integration of
870
+
JUnit Jupiter extensions within Spock specifications. This extension though is neither maintained, nor recommended,
871
+
nor discouraged by the Spock maintainers. It can eventually make some JUnit Jupiter extensions work within Spock specifications,
872
+
but it is always preferable to instead use a native Spock extension. Often porting a JUnit Jupiter extension to also support
873
+
Spock is not a big effort, so you might strongly consider to request a port by the extension maintainer or contribute
874
+
a port to its project.
875
+
--
858
876
859
877
== Comparison to JUnit
860
878
@@ -864,10 +882,10 @@ Although Spock uses a different terminology, many of its concepts and features a
0 commit comments