Giter Club home page Giter Club logo

spock-example's Introduction

License Apache%202.0 blue
badge
spock

Spock Framework Example Project

The purpose of this project is to help you get started with Spock. The project includes several example specifications and build scripts for Gradle and Maven. It also makes it easy to create an Eclipse or IDEA project, allowing you to run the example specs from within your IDE.

All builds (Gradle and Maven) will automatically download all required dependencies, compile the project, and finally run the example specs. The Gradle build goes one step further by bootstrapping itself, alleviating the need to have a build tool preinstalled.

Prerequisites

  • JDK 8 or higher

  • Maven use mvnw wrapper

  • Gradle use gradlew wrapper

Note
This example shows the usage of Spock 2.0, which uses the JUnit Platform. If you want to see how to get Spock 1.x with JUnit 4 up and running see the Spock-1.x Branch.

Building with Gradle

Type:

./gradlew clean test

Downloaded files (including the Gradle distribution itself) will be stored in the Gradle user home directory (typically user_home/.gradle).

Building with Maven

Type:

./mvnw clean test

Downloaded files will be stored in the local Maven repository (typically user_home/.m2/repository).

Creating an Eclipse project

Install the Buildship plugin if you want to use gradle as build tool.

Creating an IDEA project

Just open the project directory with Intelli IDEA and it should auto-detect the project settings.

Further Resources

If you have any comments or questions, please direct them to the Spock discussion group. We appreciate all feedback!

Happy spec’ing!

The Spock Framework Team

spock-example's People

Contributors

aaabramov avatar davidbuhler avatar dependabot[bot] avatar dmavrodiev avatar kriegaex avatar leonard84 avatar msgilligan avatar pniederw avatar renovate[bot] avatar roytruelove avatar sbglasius avatar sdelamo avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

spock-example's Issues

Run Spock Tests with Maven 3

Hi,

I have just downloaded your sample, and tried to run the Spock Tests with Maven.

As I am using Maven 3, i deleted the Spock plugin, according to the Warning message displayed in the console window.

After that, I run a "mvn clean test", and the console windows display : "There are no tests to run". What am I missing ?

Thanks a lot.

Manu

New to Spock

Hi
I tried to use the web console and can not load it.

Can't execute JUnit Test

I added a java directory in src/test and wrote a JUnit Test,like this:

- src
  - test
     + groovy
     - java
         + HelloTest.java

then execute the mvn command: mvn clean && mvn test
but in the result, I can't find the HelloTest

[INFO] -------------------------------------------------------
[INFO]  T E S T S
[INFO] -------------------------------------------------------
[INFO] Running account.fb.manager.HelloSpockSpec
[INFO] Tests run: 3, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.134 s - in account.fb.manager.HelloSpockSpec
[INFO] Running DatabaseDrivenSpec
[INFO] Tests run: 3, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.043 s - in DatabaseDrivenSpec
[INFO] Running DataDrivenSpec
[INFO] Tests run: 8, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.014 s - in DataDrivenSpec
[INFO] Running DerivedSpec
base setupSpec()
derived setupSpec()
base field initializer
derived field initializer
base setup()
derived setup()
base spec method
derived cleanup()
base cleanup()
base field initializer
derived field initializer
base setup()
derived setup()
derived spec method
derived cleanup()
base cleanup()
derived cleanupSpec()
base cleanupSpec()
[INFO] Tests run: 2, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.035 s - in DerivedSpec
[INFO] Running EmptyStackSpec
[INFO] Tests run: 4, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.033 s - in EmptyStackSpec
[INFO] Running HamcrestMatchersSpec
[INFO] Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.03 s - in HamcrestMatchersSpec
[INFO] Running IncludeExcludeExtensionSpec
[INFO] Tests run: 3, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.002 s - in IncludeExcludeExtensionSpec
[INFO] Running OrderedInteractionsSpec
[INFO] Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.05 s - in OrderedInteractionsSpec
[INFO] Running PublisherSpec
[INFO] Tests run: 2, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.036 s - in PublisherSpec
[INFO] Running StackWithOneElementSpec
[INFO] Tests run: 4, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.003 s - in StackWithOneElementSpec
[INFO] Running StackWithThreeElementsSpec
[INFO] Tests run: 4, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.006 s - in StackWithThreeElementsSpec
[INFO] Running StepwiseExtensionSpec
[INFO] Tests run: 3, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.002 s - in StepwiseExtensionSpec
[INFO] Running UsingJUnitRulesSpec
entering 'retrieve test name at runtime'
leaving 'retrieve test name at runtime'
[INFO] Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.03 s - in UsingJUnitRulesSpec
[INFO]
[INFO] Results:
[INFO]
[INFO] Tests run: 39, Failures: 0, Errors: 0, Skipped: 0

then I try to remove the Spec from pom.xml

<includes>
     <include>**/*Test.java</include>
      <!--  <include>**/*Spec.java</include>-->
</includes>

and execute:

[INFO] --- maven-surefire-plugin:3.0.0-M4:test (default-test) @ spock-example ---
[INFO]
[INFO] -------------------------------------------------------
[INFO]  T E S T S
[INFO] -------------------------------------------------------
[INFO]
[INFO] Results:
[INFO]
[INFO] Tests run: 0, Failures: 0, Errors: 0, Skipped: 0
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  5.473 s
[INFO] Finished at: 2020-07-27T15:10:59+08:00
[INFO] ------------------------------------------------------------------------

Is that something wrong?
Thanks for answer

no main manifest attribute, in spock-example-1.0.jar

i am trying to run the tests as one jar, by adding the following in build.gradle

apply plugin: 'application'

task uberJar(type: Jar,dependsOn:[':compileGroovy']) {
    zip64 true
    from files(sourceSets.main.output.classesDir)
    from configurations.runtime.asFileTree.files.collect {zipTree(it) }
    with jar
}

but when i run it as java -jar spock-example-1.0.jar

i get error:

no main manifest attribute, in spock-example-1.0.jar

is it because there is no main() entry point in the jar ? if not then how can i run it ?
either via command line, or gradle, since it seems in order to run a jar via gradle, there needs to be a main(), but groovy files do not have main() hence the confusion

Missing build.xml

Readme.md says there is an example of running Spock using Ant but it seems that the Ant example was deleted in a PR earlier. May you please add the example again or let us know the reason behind deleting the example ?

Shouldn't use GMaven in Maven example

GMaven doesn't work with newer Groovy versions. One example is that it's impossible for GMaven to compile Groovy classes that use traits. The last GMaven update I did was to make the 2.0 provider use Groovy 2.0.1, so really GMaven should not be used beyond the 2.0.x line. I (and others) recommend GMavenPlus, but Groovy-Eclipse would work for those who don't need things like invokedynamic. I've tried to give a neutral overview of the options (including non-Maven options) here.

Setting Spock config file in static block does not work in IncludeExcludeExtensionSpec

System.setProperty "spock.configuration", "IncludeFastConfig.groovy"

I ran the test from both Maven and IDEA, but the property is not picked up unless I set it from outside. Always all three feature methods get executed. I assume that setting the property in the static class initialiser is too late in Spock's lifecycle to be picked up before the decision is made which tests to execute.

The POM for Spock Core 1.0-groovy-2.3-SNAPSHOT is missing

When running mvn clean test I see this during the build:

[WARNING] The POM for org.spockframework:spock-core:jar:1.0-groovy-2.3-SNAPSHOT is missing, no dependency information available

The build eventually fails with this message:

[ERROR] Failed to execute goal on project spock-example: Could not resolve dependencies for project org.spockframework:spock-example:jar:1.0-SNAPSHOT: Could not find artifact org.spockframework:spock-core:jar:1.0-groovy-2.3-SNAPSHOT in nexus_sprn (http://10.184.244.244:8081/nexus/content/groups/sprn-maven2)

Using -e option does not help. Suggestions?

Test sources not recognised by IDEA after Maven (re-)import

I have my own Maven setup for Spock/Geb and when importing projects using that setup, IDEA automatically recognises Spock tests under src/test/groovy or src/test/java. Now I wanted to use your repository just because I was curious. I did not import the Gradle but the Maven project and the Spock specs are all imported as Groovy scripts only, the test folder is not recognised unless I manually mark it as such in the project settings. But with Maven auto-import active, whenever I change something in the POM, the setting is gone again.

Please fix your Maven project so as to enable auto-import from IDEA.

Add travis support

It would be useful to have CI builds for examples repository.

What do you think?

Dependency Dashboard

This issue lists Renovate updates and detected dependencies. Read the Dependency Dashboard docs to learn more.

Open

These updates have all been created already. Click a checkbox below to force a retry/rebase of any.

Detected dependencies

github-actions
.github/workflows/main.yml
  • actions/checkout v4
  • actions/setup-java v4
  • gradle/gradle-build-action v3
  • gradle/gradle-build-action v3
  • actions/checkout v4
  • actions/cache v4
  • actions/setup-java v4
gradle
settings.gradle
build.gradle
  • org.apache.groovy:groovy-bom 4.0.22
  • org.spockframework:spock-bom 2.3-groovy-4.0
  • org.hamcrest:hamcrest-core 2.2
  • net.bytebuddy:byte-buddy 1.14.19
  • org.objenesis:objenesis 3.4
  • com.h2database:h2 2.2.224
gradle-wrapper
gradle/wrapper/gradle-wrapper.properties
  • gradle 8.7
maven
pom.xml
  • org.codehaus.gmavenplus:gmavenplus-plugin 3.0.2
  • org.apache.maven.plugins:maven-surefire-plugin 3.2.5
  • org.apache.maven.plugins:maven-deploy-plugin 3.1.2
  • org.spockframework:spock-bom 2.3-groovy-4.0
  • org.apache.groovy:groovy 4.0.22
  • net.bytebuddy:byte-buddy 1.14.19
  • org.objenesis:objenesis 3.4
  • org.hamcrest:hamcrest-core 2.2
  • com.h2database:h2 2.2.224
  • org.apache.groovy:groovy-sql 4.0.22
maven-wrapper
.mvn/wrapper/maven-wrapper.properties
  • maven 3.9.7
  • maven-wrapper 3.2.0

  • Check this box to trigger a request for Renovate to run again on this repository

Error:Groovyc: While compiling tests of flyway: Could not instantiate global transform class org.spockframework.compiler.SpockTransform specified at jar:file: spock-core-2.0-groovy-3.0.jar!/META-INF/services/org.codehaus.groovy.transform.ASTTransformation because of exception java.lang.NullPointerException

Error:Groovyc: While compiling tests of flyway: Could not instantiate global transform class org.spockframework.compiler.SpockTransform specified at jar:file:/home/xxx/.m2/repository/org/spockframework/spock-core/2.0-groovy-3.0/spock-core-2.0-groovy-3.0.jar!/META-INF/services/org.codehaus.groovy.transform.ASTTransformation because of exception java.lang.NullPointerException

     <dependency>
            <groupId>org.spockframework</groupId>
            <artifactId>spock-core</artifactId>
            <version>2.0-groovy-3.0</version>
            <scope>test</scope>
        </dependency>

below is the maven dependency tree:

[INFO] Scanning for projects...
[INFO] 
[INFO] -------------------------< com.abc:flyway >-------------------------
[INFO] Building flyway 0.0.1-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
[INFO] 
[INFO] --- maven-dependency-plugin:3.1.2:tree (default-cli) @ flyway ---
 
[INFO] +- com.oracle.database.jdbc:ojdbc8:jar:19.11.0.0:compile
[INFO] +- org.spockframework:spock-core:jar:2.0-groovy-3.0:test
[INFO] |  +- org.codehaus.groovy:groovy:jar:2.5.14:test
[INFO] |  +- org.junit.platform:junit-platform-engine:jar:1.7.1:test
[INFO] |  |  +- org.apiguardian:apiguardian-api:jar:1.1.0:test
[INFO] |  |  +- org.opentest4j:opentest4j:jar:1.2.0:test
[INFO] |  |  \- org.junit.platform:junit-platform-commons:jar:1.7.1:test
[INFO] |  \- org.hamcrest:hamcrest:jar:2.2:test
[INFO] \- org.flywaydb:flyway-core:jar:7.11.4:compile
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  1.561 s
[INFO] Finished at: 2021-09-03T17:52:37+08:00
[INFO] ------------------------------------------------------------------------

The input type of the launch configuration does not exist - eclipse

Hallo spock-example contributors,

cloning the project and exectuing it on eclipse I got the error:

The input type of the launch configuration does not exist

but only when the test cases are executed separately as JUnits.

One fix is to rename the file or the name of the class, i.e.;

  • PublisherSubscriberSpec.groovy -> PublisherSpec.groovy
  • SpecInheritanceSpec.groovy -> DerivedSpec.groovy

Then to split the test cases of StackSpec.groovy into seprate files i.e:

  • class EmptyStackSpec -> EmptyStackSpec.groovy
  • class StackWithOneElementSpec -> StackWithOneElementSpec.groovy
  • class StackWithThreeElementsSpec -> StackWithThreeElementsSpec.groovy

Best Regards,
Kosta

Missing dependency: 1.0-groovy-2.0-SNAPSHOT

I cloned your repo and attempted to do a build with Maven (mvn clean test), but I get this message, which causes the build to fail:

[INFO] Unable to find resource 'org.spockframework:spock-core:jar:1.0-groovy-2.0-SNAPSHOT' in repository spock-snapshots (http://oss.sonatype.org/content/reposi
tories/snapshots/)

This is just a clone; I have made no modifications.

My system info:
Apache Maven 2.2.1 (r801777; 2009-08-06 12:16:01-0700)
Java version: 1.7.0_17

NoSuchMethodError: Node$DynamicTestExecutor.execute(org.junit.platform.engine.TestDescriptor, org.junit.platform.engine.EngineExecutionListener)

Hi, I am getting this error when I try to run spock tests.


[ERROR] uk.co.wowcher.vouchervalidityextension.voucherExtension.domain.model.aggregate.VoucherExtensionSpec.voucher extension should return the correct cost(Object,Object,Object,Object)  Time elapsed: 0.003 s  <<< ERROR!
java.lang.NoSuchMethodError: 'java.util.concurrent.Future org.junit.platform.engine.support.hierarchical.Node$DynamicTestExecutor.execute(org.junit.platform.engine.TestDescriptor, org.junit.platform.engine.EngineExecutionListener)'
	at org.spockframework.runtime.ParameterizedFeatureChildExecutor.execute(ParameterizedFeatureChildExecutor.java:104)
	at org.spockframework.runtime.PlatformParameterizedSpecRunner$1.runIteration(PlatformParameterizedSpecRunner.java:72)
	at org.spockframework.runtime.extension.IDataDriver.lambda$static$0(IDataDriver.java:37)
	at org.spockframework.runtime.PlatformParameterizedSpecRunner.runParameterizedFeature(PlatformParameterizedSpecRunner.java:47)
	at org.spockframework.runtime.ParameterizedFeatureNode.execute(ParameterizedFeatureNode.java:40)
	at org.spockframework.runtime.ParameterizedFeatureNode.execute(ParameterizedFeatureNode.java:16)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$5(NodeTestTask.java:135)
	at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$7(NodeTestTask.java:125)
	at org.spockframework.runtime.SpockNode.sneakyInvoke(SpockNode.java:40)
	at org.spockframework.runtime.FeatureNode.lambda$around$0(FeatureNode.java:41)
	at org.spockframework.runtime.PlatformSpecRunner.lambda$createMethodInfoForDoRunFeature$4(PlatformSpecRunner.java:199)
	at org.spockframework.runtime.model.MethodInfo.invoke(MethodInfo.java:156)

I am using the same configuration as in https://github.com/spockframework/spock-example/blob/master/pom.xml

I can see execute() is called with 2 params, but the execute() interface expects ony 1 param:

class ParameterizedFeatureChildExecutor {  // org.junit.platform:junit-platform-engine:jar:1.6.2

    public CompletableFuture<ExecutionResult> execute(TestDescriptor testDescriptor) {
       ...
       this.delegate.execute(testDescriptor, this.executionListener);
       ...
}



public interface Node<C extends EngineExecutionContext> { // org.spockframework:spock-core:jar:2.3-groovy-4.0

    public interface DynamicTestExecutor {
        void execute(TestDescriptor var1);
 }

The maven dependencies I have are:

[INFO] +- org.spockframework:spock-core:jar:2.3-groovy-4.0:test
[INFO] |  +- org.apache.groovy:groovy:jar:4.0.4:test
[INFO] |  \- org.junit.platform:junit-platform-engine:jar:1.6.2:test
[INFO] |     +- org.apiguardian:apiguardian-api:jar:1.1.0:test
[INFO] |     +- org.opentest4j:opentest4j:jar:1.2.0:test
[INFO] |     \- org.junit.platform:junit-platform-commons:jar:1.6.2:test
[INFO] +- org.spockframework:spock-spring:jar:2.3-groovy-4.0:test
[INFO] \- org.spockframework:spock-junit4:jar:2.3-groovy-4.0:test
[INFO]    \- junit:junit:jar:4.13:test
[INFO]       \- org.hamcrest:hamcrest-core:jar:2.2:test

Any ideas please?

Mvn clean install on spock-example provokes a TestNG error message

Hi all,

I cloned the spock-example project and got this message when running mvn clean install:

[INFO]
[INFO] -------------------------------------------------------
[INFO] T E S T S
[INFO] -------------------------------------------------------
[INFO] Running TestSuite
[TestNG] [ERROR] No test suite found. Nothing to run
Usage:

[options] The XML suite files to run
Options:
-configfailurepolicy
Configuration failure policy (skip or continue)
-d
Output directory
-dataproviderthreadcount
Number of threads to use when running data providers
...

After this message, the Spock tests run as expected.

Kind regards,

Rodrigo

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.