Groovy Kitchen Mac OS
- Groovy Kitchen Mac Os X
- Groovy Kitchen Mac Os Download
- Groovy Kitchen Mac Os Catalina
- Groovy Kitchen Mac Os Update
1. Overview
I believe this is because the default Mac OS file system supports mixed case filenames but file name searches are case insensitive. It appears that groovy searches the FS for a class that matches the token to determine if it is a class. Script614.groovy: 6: unable to resolve class MRJAboutHandler @ line 6, column 1. Class ConsoleMacOsSupport implements MRJQuitHandler, MRJAboutHandler. INTRODUCTION Here's a typical workflow for implementing and running Kitchen Terraform tests outside of the GCP environment, for example, from an IDE on a Mac laptop. Enable 'gcloud' Access Command: The first step is to ensure we can interact with GCP using the gcloud command using our user credential. This is needed because the tests.
- Org.codehaus.groovy.syntax.SyntaxException: Cannot use a class expression on the left hand side of an assignment. I believe this is because the default Mac OS file system supports mixed case filenames but file name searches are case insensitive. It appears that groovy searches the FS for a class that matches the token to determine if it is a class.
- I need to know the directory path on my Mac OS where Grails and/or Groovy has been installed (not sure if these will be the same)? Macos grails groovy. Improve this question. Follow asked Jul 15 '16 at 13:01. AbuMariam AbuMariam. 2,502 7 7 gold badges 33 33 silver badges 63 63 bronze badges.
In this tutorial, we'll take a look at Spock extensions.
Sometimes, we might need to modify or enhance our spec's lifecycle. For example, we'd like to add some conditional execution, retry on randomly failing integration test, and more. For this, we can use Spock's extension mechanism.
Spock has a wide range of various extensions that we can hook onto a specification's lifecycle.
Let's discover how to use the most common extensions.
2. Maven Dependencies
Before we start, let's set up our Maven dependencies:
3. Annotation-Based Extensions
Most of Spock‘s built-in extensions are based on annotations.
We can add annotations on a spec class or feature to trigger a specific behavior.
3.1. @Ignore
Sometimes we need to ignore some feature methods or spec classes. Like, we might need to merge our changes as soon as possible, but continuous integration still fails. We can ignore some specs and still make a successful merge.
We can use @Ignore on a method level to skip a single specification method:
Spock won't execute this test method. And most IDEs will mark the test as skipped.
Additionally, we can use @Ignore on the class level:
We can simply provide a reason why our test suite or method is ignored:
3.2. @IgnoreRest
Likewise, we can ignore all specifications except one, which we can mark with a @IgnoreRest annotation:
3.3. @IgnoreIf
Sometimes, we'd like to conditionally ignore a test or two. In that case, we can use @IgnoreIf, which accepts a predicate as an argument:
Spock provides the set of properties and helper classes, to make our predicates easier to read and write:
- os – Information about the operating system (see spock.util.environment.OperatingSystem).
- jvm – the JVM's information (see spock.util.environment.Jvm).
- sys – System's properties in a map.
- env – Environment variables in a map.
We can re-write the previous example throughout the use of os property. Actually, it's the spock.util.environment.OperatingSystem class with some useful methods, like for example isWindows():
Note, that Spock uses System.getProperty(…) underhood. The main goal is to provide a clear interface, rather than defining complicated rules and conditions.
Also, as in the previous examples, we can apply the @IgnoreIf annotation at the class level.
3.4. @Requires
Sometimes, it's easier to invert our predicate logic from @IgnoreIf. In that case, we can use @Requires:
So, while the @Requires makes this test run only if the OS is Windows, the @IgnoreIf, using the same predicate, makes the test run only if the OS is not Windows.
In general,it's much better to say under which condition the test will execute, rather than when it gets ignored.
3.5. @PendingFeature
In TDD, we write tests first. Then, we need to write a code to make these tests pass. In some cases, we will need to commit our tests before the feature is implemented.
This is a good use case for @PendingFeature:
There is one main difference between @Ignore and @PendingFeature. In @PedingFeature, tests are executed, but any failures are ignored.
If a test marked with @PendingFeature ends without error, then it will be reported as a failure, to remind about removing annotation.
In this way, we can initially ignore fails of not implemented features, but in the future, these specs will become a part of normal tests, instead of being ignored forever.
3.6. @Stepwise
We can execute a spec's methods in a given order with the @Stepwise annotation:
In general, tests should be deterministic. One should not depend on another. That's why we should avoid using @Stepwise annotation.
But if we have to, we need to be aware that @Stepwise doesn't override the behavior of @Ignore, @IgnoreRest, or @IgnoreIf. We should be careful with combining these annotations with @Stepwise.
3.7. @Timeout
We can limit the execution time of a spec's single method and fail earlier:
Note, that this is the timeout for a single iteration, not counting the time spent in fixture methods.
By default, the spock.lang.Timeout uses seconds as a base time unit. But, we can specify other time units:
@Timeout on the class level has the same effect as applying it to every feature method separately:
Using @Timeout on a single spec method always overrides class level.
3.8. @Retry
Sometimes, we can have some non-deterministic integration tests. These may fail in some runs for reasons such as async processing or depending on other HTTP clients response. Moreover, the remote server with build and CI will fail and force us to run the tests and build again.
To avoid this situation, we can use @Retry annotation on a method or class level, to repeat failed tests:
By default, it will retry three times.
It's very useful to determine the conditions, under which we should retry our test. We can specify the list of exceptions:
Or when there is a specific exception message:
Very useful is a retry with a delay:
And finally, like almost always, we can specify retry on the class level:
3.9. @RestoreSystemProperties
We can manipulate environment variables with @RestoreSystemProperties.
This annotation, when applied, saves the current state of variables and restores them afterward. It also includes setup or cleanup methods:
Please note that we shouldn't run the tests concurrently when we're manipulating the system properties. Our tests might be non-deterministic.
3.10. Human-Friendly Titles
We can add a human-friendly test title by using the @Title annotation:
Similarly, we can add a description of the spec with @Narrative annotation and with a multi-line Groovy String:
3.11. @See
To link one or more external references, we can use the @See annotation:
To pass more than one link, we can use the Groovy [] operand for creating a list:
Groovy Kitchen Mac Os X
3.12. @Issue
We can denote that a feature method refers to an issue or multiple issues:
3.13. @Subject
And finally, we can indicate which class is the class under test with @Subject:
Right now, it's only for informational purposes.
4. Configuring Extensions
We can configure some of the extensions in the Spock configuration file. This includes describing how each extension should behave.
Usually, we create a configuration file in Groovy, called, for example, SpockConfig.groovy.
Of course, Spock needs to find our config file. First of all, it reads a custom location from the spock.configuration system property and then tries to find the file in the classpath. When not found, it goes to a location in the file system. If it's still not found, then it looks for SpockConfig.groovy in the test execution classpath.
Eventually, Spock goes to a Spock user home, which is just a directory .spock within our home directory. We can change this directory by setting system property called spock.user.home or by an environment variable SPOCK_USER_HOME.
For our examples, we'll create a file SpockConfig.groovy and put it on the classpath (src/test/resources/SpockConfig.Groovy).
4.1. Filtering the Stack Trace
By using a configuration file, we can filter (or not) the stack traces:
The default value is true.
To see how it works and practice, let's create a simple test which throws a RuntimeException:
When filterStackTrace is set to false, then we'll see in the output:
By setting this property to true, we'll get:
Although keep in mind, sometimes it's useful to see the full stack trace.
4.2. Conditional Features in Spock Configuration File
Sometimes, we might need to filter stack traces conditionally. For example, we'll need to see full stack traces in a Continuous Integration tool, but this isn't necessary on our local machine.
We can add a simple condition, based for example on the environment variables:
The Spock configuration file is a Groovy file, so it can contain snippets of Groovy code.
4.3. Prefix and URL in @Issue
Previously, we talked about the @Issue annotation. We can also configure this using the configuration file, by defining a common URL part with issueUrlPrefix.
The other property is issueNamePrefix. Then, every @Issue value is preceded by the issueNamePrefix property.
We need to add these two properties in the report:
4.4. Optimize Run Order
The other very helpful tool is optimizeRunOrder. Spock can remember which specs failed and how often and how much time it needs to execute a feature method.
Based on this knowledge, Spock will first run the features which failed in the last run. In the first place, it will execute the specs which failed more successively. Furthermore, the fastest specs will run first.
This behavior may be enabled in theconfiguration file. To enable optimizer, we use optimizeRunOrder property:
By default, the optimizer for run order is disabled.
4.5. Including and Excluding Specifications
Spock can exclude or include certain specs. We can lean on classes, super-classes, interfaces or annotations, which are applied on specification classes. The library can be of capable excluding or including single features, based on the annotation on a feature level.
We can simply exclude a test suite from class TimeoutTest by using the exclude property:
TimeoutTest and all its subclasses will be excluded. If TimeoutTest was an annotation applied on a spec's class, then this spec would be excluded.
We can specify annotations and base classes separately:
The above example will exclude test classes or methods with the @Issue annotation as well as TimeoutTest or any of its subclasses.
To include any spec, we simply use include property. We can define the rules of include in the same way as exclude.
4.6. Creating a Report
Based on the test results and previously known annotations, we can generate a report with Spock. Additionally, this report will contain things like @Title, @See, @Issue, and @Narrative values.
We can enable generating a report in the configuration file. By default, it won't generate the report.
All we have to do is pass values for a few properties:
The properties above are:
- enabled – should or not generate the report
- logFileDir – directory of report
- logFileName – the name of the report
- logFileSuffix – a suffix for every generated report basename separated with a dash
When we set enabled to true, then it's mandatory to set logFileDir and logFileName properties. The logFileSuffix is optional.
We can also set all of them in system properties: enabled, spock.logFileDir, spock.logFileName and spock.logFileSuffix.
5. Conclusion
In this article, we described the most common Spock extensions.
We know that most of them are based on annotations. In addition, we learned how to create a Spock configuration file, and what the available configuration options are. In short, our newly acquired knowledge is very helpful for writing effective and easy to read tests.
The implementation of all our examples can be found in our Github project.
Get started with Spring 5 and Spring Boot 2, through the Learn Spring course:
>> CHECK OUT THE COURSE1. Overview
In this tutorial, we'll take a look at Spock extensions.
Sometimes, we might need to modify or enhance our spec's lifecycle. For example, we'd like to add some conditional execution, retry on randomly failing integration test, and more. For this, we can use Spock's extension mechanism.
Spock has a wide range of various extensions that we can hook onto a specification's lifecycle.
Let's discover how to use the most common extensions.
2. Maven Dependencies
Before we start, let's set up our Maven dependencies:
3. Annotation-Based Extensions
Most of Spock‘s built-in extensions are based on annotations.
We can add annotations on a spec class or feature to trigger a specific behavior.
3.1. @Ignore
Sometimes we need to ignore some feature methods or spec classes. Like, we might need to merge our changes as soon as possible, but continuous integration still fails. We can ignore some specs and still make a successful merge.
We can use @Ignore on a method level to skip a single specification method:
Spock won't execute this test method. And most IDEs will mark the test as skipped.
Additionally, we can use @Ignore on the class level:
We can simply provide a reason why our test suite or method is ignored:
3.2. @IgnoreRest
Likewise, we can ignore all specifications except one, which we can mark with a @IgnoreRest annotation:
3.3. @IgnoreIf
Sometimes, we'd like to conditionally ignore a test or two. In that case, we can use @IgnoreIf, which accepts a predicate as an argument:
Spock provides the set of properties and helper classes, to make our predicates easier to read and write:
- os – Information about the operating system (see spock.util.environment.OperatingSystem).
- jvm – the JVM's information (see spock.util.environment.Jvm).
- sys – System's properties in a map.
- env – Environment variables in a map.
We can re-write the previous example throughout the use of os property. Actually, it's the spock.util.environment.OperatingSystem class with some useful methods, like for example isWindows():
Note, that Spock uses System.getProperty(…) underhood. The main goal is to provide a clear interface, rather than defining complicated rules and conditions.
Also, as in the previous examples, we can apply the @IgnoreIf annotation at the class level.
3.4. @Requires
Sometimes, it's easier to invert our predicate logic from @IgnoreIf. In that case, we can use @Requires:
So, while the @Requires makes this test run only if the OS is Windows, the @IgnoreIf, using the same predicate, makes the test run only if the OS is not Windows.
In general,it's much better to say under which condition the test will execute, rather than when it gets ignored.
3.5. @PendingFeature
In TDD, we write tests first. Then, we need to write a code to make these tests pass. In some cases, we will need to commit our tests before the feature is implemented.
This is a good use case for @PendingFeature:
There is one main difference between @Ignore and @PendingFeature. In @PedingFeature, tests are executed, but any failures are ignored.
If a test marked with @PendingFeature ends without error, then it will be reported as a failure, to remind about removing annotation.
In this way, we can initially ignore fails of not implemented features, but in the future, these specs will become a part of normal tests, instead of being ignored forever.
3.6. @Stepwise
We can execute a spec's methods in a given order with the @Stepwise annotation:
In general, tests should be deterministic. One should not depend on another. That's why we should avoid using @Stepwise annotation.
But if we have to, we need to be aware that @Stepwise doesn't override the behavior of @Ignore, @IgnoreRest, or @IgnoreIf. We should be careful with combining these annotations with @Stepwise.
3.7. @Timeout
We can limit the execution time of a spec's single method and fail earlier:
Note, that this is the timeout for a single iteration, not counting the time spent in fixture methods.
By default, the spock.lang.Timeout uses seconds as a base time unit. But, we can specify other time units:
@Timeout on the class level has the same effect as applying it to every feature method separately:
Using @Timeout on a single spec method always overrides class level.
3.8. @Retry
Sometimes, we can have some non-deterministic integration tests. These may fail in some runs for reasons such as async processing or depending on other HTTP clients response. Moreover, the remote server with build and CI will fail and force us to run the tests and build again.
To avoid this situation, we can use @Retry annotation on a method or class level, to repeat failed tests:
By default, it will retry three times.
It's very useful to determine the conditions, under which we should retry our test. We can specify the list of exceptions:
Or when there is a specific exception message:
Very useful is a retry with a delay:
And finally, like almost always, we can specify retry on the class level:
3.9. @RestoreSystemProperties
We can manipulate environment variables with @RestoreSystemProperties.
This annotation, when applied, saves the current state of variables and restores them afterward. It also includes setup or cleanup methods:
Please note that we shouldn't run the tests concurrently when we're manipulating the system properties. Our tests might be non-deterministic.
3.10. Human-Friendly Titles
We can add a human-friendly test title by using the @Title annotation:
Similarly, we can add a description of the spec with @Narrative annotation and with a multi-line Groovy String:
3.11. @See
To link one or more external references, we can use the @See annotation:
To pass more than one link, we can use the Groovy [] operand for creating a list:
3.12. @Issue
We can denote that a feature method refers to an issue or multiple issues:
3.13. @Subject
And finally, we can indicate which class is the class under test with @Subject:
Right now, it's only for informational purposes.
4. Configuring Extensions
We can configure some of the extensions in the Spock configuration file. This includes describing how each extension should behave.
Usually, we create a configuration file in Groovy, called, for example, SpockConfig.groovy.
Of course, Spock needs to find our config file. First of all, it reads a custom location from the spock.configuration system property and then tries to find the file in the classpath. When not found, it goes to a location in the file system. If it's still not found, then it looks for SpockConfig.groovy in the test execution classpath.
Eventually, Spock goes to a Spock user home, which is just a directory .spock within our home directory. We can change this directory by setting system property called spock.user.home or by an environment variable SPOCK_USER_HOME.
For our examples, we'll create a file SpockConfig.groovy and put it on the classpath (src/test/resources/SpockConfig.Groovy).
4.1. Filtering the Stack Trace
By using a configuration file, we can filter (or not) the stack traces:
The default value is true.
To see how it works and practice, let's create a simple test which throws a RuntimeException:
When filterStackTrace is set to false, then we'll see in the output:
By setting this property to true, we'll get:
Although keep in mind, sometimes it's useful to see the full stack trace.
4.2. Conditional Features in Spock Configuration File
Sometimes, we might need to filter stack traces conditionally. For example, we'll need to see full stack traces in a Continuous Integration tool, but this isn't necessary on our local machine.
We can add a simple condition, based for example on the environment variables:
The Spock configuration file is a Groovy file, so it can contain snippets of Groovy code.
4.3. Prefix and URL in @Issue
Previously, we talked about the @Issue annotation. We can also configure this using the configuration file, by defining a common URL part with issueUrlPrefix.
Groovy Kitchen Mac Os Download
The other property is issueNamePrefix. Then, every @Issue value is preceded by the issueNamePrefix property.
We need to add these two properties in the report:
4.4. Optimize Run Order
The other very helpful tool is optimizeRunOrder. Spock can remember which specs failed and how often and how much time it needs to execute a feature method.
Based on this knowledge, Spock will first run the features which failed in the last run. In the first place, it will execute the specs which failed more successively. Furthermore, the fastest specs will run first.
This behavior may be enabled in theconfiguration file. To enable optimizer, we use optimizeRunOrder property:
Groovy Kitchen Mac Os Catalina
By default, the optimizer for run order is disabled.
4.5. Including and Excluding Specifications
Spock can exclude or include certain specs. We can lean on classes, super-classes, interfaces or annotations, which are applied on specification classes. The library can be of capable excluding or including single features, based on the annotation on a feature level.
We can simply exclude a test suite from class TimeoutTest by using the exclude property:
TimeoutTest and all its subclasses will be excluded. If TimeoutTest was an annotation applied on a spec's class, then this spec would be excluded.
We can specify annotations and base classes separately:
The above example will exclude test classes or methods with the @Issue annotation as well as TimeoutTest or any of its subclasses.
To include any spec, we simply use include property. We can define the rules of include in the same way as exclude.
4.6. Creating a Report
Based on the test results and previously known annotations, we can generate a report with Spock. Additionally, this report will contain things like @Title, @See, @Issue, and @Narrative values.
Groovy Kitchen Mac Os Update
We can enable generating a report in the configuration file. By default, it won't generate the report.
All we have to do is pass values for a few properties:
The properties above are:
- enabled – should or not generate the report
- logFileDir – directory of report
- logFileName – the name of the report
- logFileSuffix – a suffix for every generated report basename separated with a dash
When we set enabled to true, then it's mandatory to set logFileDir and logFileName properties. The logFileSuffix is optional.
We can also set all of them in system properties: enabled, spock.logFileDir, spock.logFileName and spock.logFileSuffix.
5. Conclusion
In this article, we described the most common Spock extensions.
We know that most of them are based on annotations. In addition, we learned how to create a Spock configuration file, and what the available configuration options are. In short, our newly acquired knowledge is very helpful for writing effective and easy to read tests.
The implementation of all our examples can be found in our Github project.