Skip to content

Commit

Permalink
Make Spock Framework the default test framework for Grails 2.3
Browse files Browse the repository at this point in the history
  • Loading branch information
graemerocher committed Jun 4, 2013
1 parent 47d50d5 commit b079427
Show file tree
Hide file tree
Showing 14 changed files with 95 additions and 72 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Expand Up @@ -44,7 +44,7 @@ ext {
springLoadedVersion = "1.1.1" springLoadedVersion = "1.1.1"
springVersion = "3.2.3.RELEASE" springVersion = "3.2.3.RELEASE"
ehcacheVersion = "2.4.6" ehcacheVersion = "2.4.6"
junitVersion = "4.10" junitVersion = "4.11"
concurrentlinkedhashmapVersion = "1.3.1" concurrentlinkedhashmapVersion = "1.3.1"
} }


Expand Down
Expand Up @@ -134,7 +134,7 @@ class TestExecutionContext extends ExecutionContext {
@Override @Override
protected List<File> buildMinimalIsolatedClasspath(BuildSettings buildSettings) { protected List<File> buildMinimalIsolatedClasspath(BuildSettings buildSettings) {
final classpath = super.buildMinimalIsolatedClasspath(buildSettings) final classpath = super.buildMinimalIsolatedClasspath(buildSettings)
classpath << buildSettings.testDependencies.find { File f -> f.name.startsWith('junit') } classpath.addAll buildSettings.testDependencies.findAll { File f -> f.name.startsWith('junit') || f.name.contains('spock') || f.name.startsWith('hamcrest') }
classpath.addAll process.findSystemClasspathJars(buildSettings) classpath.addAll process.findSystemClasspathJars(buildSettings)
return classpath return classpath
} }
Expand Down
7 changes: 7 additions & 0 deletions grails-plugin-testing/build.gradle
Expand Up @@ -53,6 +53,13 @@ dependencies {
compile("org.springframework:spring-test:${springVersion}") { compile("org.springframework:spring-test:${springVersion}") {
exclude group: 'commons-logging', module:'commons-logging' exclude group: 'commons-logging', module:'commons-logging'
} }

compile("org.spockframework:spock-core:${spockVersion}") {
exclude group:'junit', module: 'junit-dep'
}
compile "junit:junit:${junitVersion}", {
exclude group:'org.hamcrest', module: 'hamcrest-core'
}
} }


eclipse { eclipse {
Expand Down
19 changes: 11 additions & 8 deletions grails-resources/src/grails/templates/testing/Controller.groovy
@@ -1,15 +1,18 @@
@artifact.package@ @artifact.package@import grails.test.mixin.TestFor

import spock.lang.Specification
import grails.test.mixin.*
import org.junit.*


/** /**
* See the API for {@link grails.test.mixin.web.ControllerUnitTestMixin} for usage instructions * See the API for {@link grails.test.mixin.web.ControllerUnitTestMixin} for usage instructions
*/ */
@TestFor(@artifact.testclass@) @TestFor(@artifact.testclass@)
class @artifact.name@ { class @artifact.name@ extends Specification {

def setup() {
}

def cleanup() {
}


void testSomething() { void "test something"() {
fail "Implement me"
} }
} }
19 changes: 11 additions & 8 deletions grails-resources/src/grails/templates/testing/DomainClass.groovy
@@ -1,15 +1,18 @@
@artifact.package@ @artifact.package@import grails.test.mixin.TestFor

import spock.lang.Specification
import grails.test.mixin.*
import org.junit.*


/** /**
* See the API for {@link grails.test.mixin.domain.DomainClassUnitTestMixin} for usage instructions * See the API for {@link grails.test.mixin.domain.DomainClassUnitTestMixin} for usage instructions
*/ */
@TestFor(@artifact.testclass@) @TestFor(@artifact.testclass@)
class @artifact.name@ { class @artifact.name@ extends Specification {

def setup() {
}

def cleanup() {
}


void testSomething() { void "test something"() {
fail "Implement me"
} }
} }
18 changes: 11 additions & 7 deletions grails-resources/src/grails/templates/testing/Filters.groovy
@@ -1,11 +1,15 @@
@artifact.package@ @artifact.package@import grails.test.mixin.Mock

import spock.lang.Specification
import grails.test.mixin.*


@Mock(@artifact.testclass@) @Mock(@artifact.testclass@)
class @artifact.name@ { class @artifact.name@ extends Specification {

def setup() {
}

def cleanup() {
}


void testSomething() { void "test something"() {
fail "Implement me"
} }
} }
26 changes: 13 additions & 13 deletions grails-resources/src/grails/templates/testing/Generic.groovy
@@ -1,20 +1,20 @@
@artifact.package@import static org.junit.Assert.* @artifact.package@
import org.junit.* import grails.test.mixin.TestMixin
import grails.test.mixin.support.GrailsUnitTestMixin
import spock.lang.*


class @artifact.name@ { /**
* See the API for {@link grails.test.mixin.support.GrailsUnitTestMixin} for usage instructions
*/
@TestMixin(GrailsUnitTestMixin)
class @artifact.name@ extends Specification {


@Before def setup() {
void setUp() {
// Setup logic here
} }


@After def cleanup() {
void tearDown() {
// Tear down logic here
} }


@Test void "test something"() {
void testSomething() {
fail "Implement me"
} }
} }
19 changes: 11 additions & 8 deletions grails-resources/src/grails/templates/testing/Service.groovy
@@ -1,15 +1,18 @@
@artifact.package@ @artifact.package@import grails.test.mixin.TestFor

import spock.lang.Specification
import grails.test.mixin.*
import org.junit.*


/** /**
* See the API for {@link grails.test.mixin.services.ServiceUnitTestMixin} for usage instructions * See the API for {@link grails.test.mixin.services.ServiceUnitTestMixin} for usage instructions
*/ */
@TestFor(@artifact.testclass@) @TestFor(@artifact.testclass@)
class @artifact.name@ { class @artifact.name@ extends Specification {

def setup() {
}

def cleanup() {
}


void testSomething() { void "test something"() {
fail "Implement me"
} }
} }
19 changes: 11 additions & 8 deletions grails-resources/src/grails/templates/testing/TagLib.groovy
@@ -1,15 +1,18 @@
@artifact.package@ @artifact.package@import grails.test.mixin.TestFor

import spock.lang.Specification
import grails.test.mixin.*
import org.junit.*


/** /**
* See the API for {@link grails.test.mixin.web.GroovyPageUnitTestMixin} for usage instructions * See the API for {@link grails.test.mixin.web.GroovyPageUnitTestMixin} for usage instructions
*/ */
@TestFor(@artifact.testclass@) @TestFor(@artifact.testclass@)
class @artifact.name@ { class @artifact.name@ extends Specification {

def setup() {
}

def cleanup() {
}


void testSomething() { void "test something"() {
fail "Implement me"
} }
} }
21 changes: 8 additions & 13 deletions grails-resources/src/grails/templates/testing/UnitTest.groovy
@@ -1,24 +1,19 @@
@artifact.package@import static org.junit.Assert.* @artifact.package@import grails.test.mixin.TestMixin

import grails.test.mixin.support.GrailsUnitTestMixin
import grails.test.mixin.* import spock.lang.Specification
import grails.test.mixin.support.*
import org.junit.*


/** /**
* See the API for {@link grails.test.mixin.support.GrailsUnitTestMixin} for usage instructions * See the API for {@link grails.test.mixin.support.GrailsUnitTestMixin} for usage instructions
*/ */
@TestMixin(GrailsUnitTestMixin) @TestMixin(GrailsUnitTestMixin)
class @artifact.name@ { class @artifact.name@ extends Specification {


void setUp() { def setup() {
// Setup logic here
} }


void tearDown() { def cleanup() {
// Tear down logic here
} }


void testSomething() { void "test something"() {
fail "Implement me"
} }
} }
4 changes: 3 additions & 1 deletion grails-scripts/build.gradle
Expand Up @@ -4,7 +4,9 @@ configurations {


dependencies { dependencies {
// Testing // Testing
compile "junit:junit:${junitVersion}" compile "junit:junit:${junitVersion}", {
exclude group:'org.hamcrest', module: 'hamcrest-core'
}


scripts project(":grails-web"), scripts project(":grails-web"),
project(':grails-docs'), project(':grails-docs'),
Expand Down
5 changes: 4 additions & 1 deletion grails-test/build.gradle
Expand Up @@ -7,7 +7,10 @@ dependencies {
compile "org.apache.ant:ant-junit:${antVersion}" compile "org.apache.ant:ant-junit:${antVersion}"


// Testing // Testing
compile "junit:junit:${junitVersion}", project(":grails-plugin-converters"), project(":grails-plugin-mimetypes") compile "junit:junit:${junitVersion}", {
exclude group:'org.hamcrest', module: 'hamcrest-core'
}
compile project(":grails-plugin-converters"), project(":grails-plugin-mimetypes")


compile project(":grails-web") compile project(":grails-web")


Expand Down
Expand Up @@ -38,7 +38,7 @@ import org.junit.runners.Suite
*/ */
class JUnit4GrailsTestType extends GrailsTestTypeSupport { class JUnit4GrailsTestType extends GrailsTestTypeSupport {


static final List<String> SUFFIXES = ["Test", "Tests"].asImmutable() static final List<String> SUFFIXES = ["Test", "Tests", "Spec"].asImmutable()


protected suite protected suite
protected GrailsTestMode mode protected GrailsTestMode mode
Expand Down
4 changes: 2 additions & 2 deletions scripts/_GrailsCreateArtifacts.groovy
Expand Up @@ -132,7 +132,7 @@ createIntegrationTest = { Map args = [:] ->
def superClass = args["superClass"] ?: "GroovyTestCase" def superClass = args["superClass"] ?: "GroovyTestCase"
createArtifact( createArtifact(
name: args["name"], name: args["name"],
suffix: "${args['suffix']}Tests", suffix: "${args['suffix']}Spec",
type: args.testType ?: args['suffix'], type: args.testType ?: args['suffix'],
path: "test/integration", path: "test/integration",
superClass: superClass, superClass: superClass,
Expand All @@ -144,7 +144,7 @@ createUnitTest = { Map args = [:] ->
def superClass = args["superClass"] ?: "GrailsUnitTestCase" def superClass = args["superClass"] ?: "GrailsUnitTestCase"
createArtifact( createArtifact(
name: args["name"], name: args["name"],
suffix: "${args['suffix']}Tests", suffix: "${args['suffix']}Spec",
type: args.testType ?: args['suffix'], type: args.testType ?: args['suffix'],
path: "test/unit", path: "test/unit",
superClass: superClass, superClass: superClass,
Expand Down

0 comments on commit b079427

Please sign in to comment.