Skip to content

An extension to mark tests as belonging to a (set of) scopes (e.g. a global feature or a major aspect of the application) for the Spock Framework (see http://spockframework.org/).

Notifications You must be signed in to change notification settings

mkutz/spock-scope-extension

Repository files navigation

Spock Scope Extension

Build Status Coverage Status Maven Central

An extension to mark tests as belonging to a (set of) scopes (e.g. a global feature or a major aspect of the application) for the Spock Framework.

When executing a Specification marked @Scope([FeatureA, FeatureB]) and the configured current scope is [FeatureC, FeatureD], the test will be set "ignored" while all tests that are marked with a set of scopes containing at least one FeatureC or FeatureD will still be executed. Specification not having a @Scope annotation will be executed as well.

Usage

For a detailed view on how to use this extension please have a look into the demonstation folder of this repository.

Add this as a test dependency to your project.

For instance in your pom.xml:

<dependency>
  <groupId>de.assertagile.spockframework.extensions</groupId>
  <artifactId>spock-scope-extension</artifactId>
  <version>${spock-scope-extension.version}</version>
  <scope>test</scope>
</dependency>

Now you can mark your Specifications or their feature methods with the @Scope(…) annotation with one or more subclasses of SpecScope representing scopes.

When you execute your tests you can pass -Dspock.scopes=… to your test execution, all tests that are not annotated with at least one of the given scopes, it will be ignored.

You can as well pass -Dspock.excludedScopes=… to ignore all tests that have at least one of the given scopes (since v0.3).

Note that all unscoped Specification and feature methods will be ignored when you set scopes (included or exclued). If you want to include unscoped tests, you can use the pseudo scope UNSCOPED (since v0.4).

To ease usage in IDE's you can as well create a SpockScopeConfig.groovy to your projects resources and add a list of includedScopes and excludedScopes instead of the -Dspock.scopes=… and -Dspock.excludedScopes=… parameters:

includedScopes = [FeatureA, FeatureC]
excludedScopes = [FeatureB]

Note that if neither includedScopes nor excludedScopes is configured and neither -Dspock.scopes=… nor -Dspock.excludedScopes=… are set the extension will not ignore any test.

Also note that the -Dspock.scopes=… and -Dspock.excludedScopes=… parameters will always replace the configuration in SpockScopeConfig.groovy if given.

Alternative

Instead of using this custom extension, you could also use Spock's own (undocumented) runner configuration mechanism.

Check the source in this demonstration folder for some examples how to use it.

This was derived from the IncludeExcludeExtensionSpec in the spock-example project. Checkout the GroovyDoc on the file for more details.

About

An extension to mark tests as belonging to a (set of) scopes (e.g. a global feature or a major aspect of the application) for the Spock Framework (see http://spockframework.org/).

Resources

Stars

Watchers

Forks

Packages

No packages published

Contributors 2

  •  
  •  

Languages