Permalink
Browse files

GRAILS-3237 - Replace JUnit 3 with JUnit 4.

Our custom runner mimics JUnit 3 behaviours like the “test”, “setUp” and “tearDown” conventions for backwards compatibility.
  • Loading branch information...
1 parent 041c47b commit 8a6d774ed31c556f143f67c8e0fb534ff83ac5f6 @ldaley ldaley committed Mar 9, 2010
Showing with 658 additions and 479 deletions.
  1. +1 −1 build.properties
  2. +2 −2 dependencies.txt
  3. +1 −1 grails.ipr
  4. +2 −2 ivy.xml
  5. BIN lib/junit-3.8.2.jar
  6. BIN lib/junit-4.8.1.jar
  7. +1 −1 maven/grails-core.pom.in
  8. +1 −1 maven/grails-crud.pom.in
  9. +1 −1 maven/grails-gorm.pom.in
  10. +1 −1 maven/grails-scripts.pom.in
  11. +1 −1 maven/grails-spring.pom.in
  12. +2 −1 maven/grails-test.mf
  13. +1 −1 maven/grails-test.pom.in
  14. +1 −1 maven/grails-web.pom.in
  15. +1 −1 maven/grails-webflow.pom.in
  16. +5 −5 scripts/_GrailsTest.groovy
  17. +2 −2 src/java/org/codehaus/groovy/grails/resolve/IvyDependencyManager.groovy
  18. +0 −100 src/java/org/codehaus/groovy/grails/test/junit3/JUnit3GrailsEnvironmentTestSuite.groovy
  19. +0 −140 src/java/org/codehaus/groovy/grails/test/junit3/JUnit3GrailsTestType.java
  20. +0 −101 src/java/org/codehaus/groovy/grails/test/junit3/JUnit3GrailsTestTypeRunner.java
  21. +0 −76 src/java/org/codehaus/groovy/grails/test/junit3/JUnit3ListenerEventPublisherAdapter.java
  22. +116 −0 src/java/org/codehaus/groovy/grails/test/junit4/JUnit4GrailsTestType.groovy
  23. +118 −0 src/java/org/codehaus/groovy/grails/test/junit4/listener/PerTestRunListener.groovy
  24. +83 −0 src/java/org/codehaus/groovy/grails/test/junit4/listener/SuiteRunListener.groovy
  25. +20 −25 ...JUnit3GrailsTestTypeResult.groovy → junit4/result/JUnit4ResultGrailsTestTypeResultAdapter.groovy}
  26. +141 −0 src/java/org/codehaus/groovy/grails/test/junit4/runner/GrailsTestCaseRunner.groovy
  27. +54 −0 src/java/org/codehaus/groovy/grails/test/junit4/runner/GrailsTestCaseRunnerBuilder.groovy
  28. +75 −0 src/java/org/codehaus/groovy/grails/test/junit4/runner/GrailsTestInvokeMethod.groovy
  29. +1 −1 src/java/org/codehaus/groovy/grails/test/support/ControllerNameExtractor.groovy
  30. +2 −2 ...ehaus/groovy/grails/test/{junit3/JUnit3GrailsTestTypeMode.groovy → support/GrailsTestMode.groovy}
  31. +13 −0 src/java/org/codehaus/groovy/grails/test/support/GrailsTestTypeSupport.groovy
  32. +12 −12 src/test/org/codehaus/groovy/grails/resolve/IvyDependencyManagerTests.groovy
View
@@ -19,7 +19,7 @@ bundlor.spring.version=3.0.0.RELEASE
bundlor.ant.version=1.7.1
bundlor.ivy.version=2.0.0
bundlor.gant.version=1.9.1
-bundlor.junit.version=3.8.2
+bundlor.junit.version=4.8.1
bundlor.commons.logging.version=1.1.0
bundlor.commons.beanutils.version=1.8.0
bundlor.commons.lang.version=2.4.0
View
@@ -120,8 +120,8 @@ The following libraries are included in Grails because they are required either
- Java Transaction API
- required for running Grails applications
-* junit-3.8.2.jar
-- JUnit 3.8.2 (http://junit.org) CPL 1.0 License
+* junit-4.8.1.jar
+- JUnit 4.8.1 (http://junit.org) CPL 1.0 License
- required for building Grails core
- required for the command line tools (Gant)
View
@@ -624,7 +624,7 @@
</library>
<library name="JUnit">
<CLASSES>
- <root url="jar://$PROJECT_DIR$/lib/junit-3.8.2.jar!/" />
+ <root url="jar://$PROJECT_DIR$/lib/junit-4.8.1.jar!/" />
<root url="jar://$PROJECT_DIR$/lib/ant-junit-1.7.1.jar!/" />
</CLASSES>
<JAVADOC />
View
@@ -1,4 +1,4 @@
-<?xml version="1.0" encoding="UTF-8"?>
+<?xml version="1.0" encoding="UTF-8"?>
<ivy-module version="2.0">
<info organisation="codehaus" module="grails"/>
<dependencies>
@@ -16,7 +16,7 @@
<dependency org="apache" name="commons-pool" rev="1.2"/>
<dependency org="apache" name="commons-validator" rev="1.3.0"/>
<dependency org="dom4j" name="dom4j" rev="1.6.1"/>
- <dependency org="junit" name="junit" rev="3.8.1"/>
+ <dependency org="junit" name="junit" rev="4.8.1"/>
<!--<dependency org="rhino" name="js" rev="1.6R2"/> -->
<dependency org="log4j" name="log4j" rev="1.2.8"/>
<!--<dependency org="ognl" name="ognl" rev="2.6.9"/>
View
Binary file not shown.
View
Binary file not shown.
View
@@ -231,7 +231,7 @@
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
- <version>3.8.2</version>
+ <version>4.8.1</version>
<scope>test</scope>
</dependency>
</dependencies>
View
@@ -81,7 +81,7 @@
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
- <version>3.8.2</version>
+ <version>4.8.1</version>
<scope>test</scope>
</dependency>
</dependencies>
View
@@ -184,7 +184,7 @@
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
- <version>3.8.2</version>
+ <version>4.8.1</version>
<scope>test</scope>
</dependency>
</dependencies>
@@ -77,7 +77,7 @@
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
- <version>3.8.2</version>
+ <version>4.8.1</version>
</dependency>
<dependency>
@@ -65,7 +65,7 @@
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
- <version>3.8.2</version>
+ <version>4.8.1</version>
<scope>test</scope>
</dependency>
</dependencies>
View
@@ -19,4 +19,5 @@ Import-Template:
org.codehaus.groovy.ant.*;version="${groovy.version:[=.=.=, =.+1.0)}",
org.codehaus.groovy.tools.*;version="${groovy.version:[=.=.=, =.+1.0)}",
org.codehaus.groovy.grails.*;version="${grails.version:[=.=.=, +1.0.0)}",
- org.springframework.*;version="${spring.version:[=.=.=, +1.0.0)}"
+ org.springframework.*;version="${spring.version:[=.=.=, +1.0.0)}",
+ org.junit.*;version="${junit.version:[=.=.=, +1.0.0)}"
View
@@ -64,7 +64,7 @@
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
- <version>3.8.2</version>
+ <version>4.8.1</version>
<scope>runtime</scope>
</dependency>
View
@@ -121,7 +121,7 @@
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
- <version>3.8.2</version>
+ <version>4.8.1</version>
<scope>test</scope>
</dependency>
</dependencies>
@@ -142,7 +142,7 @@
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
- <version>3.8.2</version>
+ <version>4.8.1</version>
<scope>test</scope>
</dependency>
</dependencies>
View
@@ -20,8 +20,8 @@ import org.codehaus.groovy.grails.support.PersistenceContextInterceptor
import org.codehaus.groovy.grails.web.context.GrailsConfigUtils
import grails.util.GrailsUtil
-import org.codehaus.groovy.grails.test.junit3.JUnit3GrailsTestType
-import org.codehaus.groovy.grails.test.junit3.JUnit3GrailsTestTypeMode
+import org.codehaus.groovy.grails.test.junit4.JUnit4GrailsTestType
+import org.codehaus.groovy.grails.test.support.GrailsTestMode
import org.codehaus.groovy.grails.test.report.junit.JUnitReportsFactory
import org.codehaus.groovy.grails.test.report.junit.JUnitReportProcessor
@@ -128,14 +128,14 @@ target(allTests: "Runs the project's tests.") {
if (rawType instanceof CharSequence) {
def rawTypeString = rawType.toString()
if (phaseName in ['integration', 'functional']) {
- def mode = new JUnit3GrailsTestTypeMode(
+ def mode = new GrailsTestMode(
autowire: true,
wrapInTransaction: phaseName == "integration",
wrapInRequestEnvironment: phaseName == "integration"
)
- new JUnit3GrailsTestType(rawTypeString, rawTypeString, mode)
+ new JUnit4GrailsTestType(rawTypeString, rawTypeString, mode)
} else {
- new JUnit3GrailsTestType(rawTypeString, rawTypeString)
+ new JUnit4GrailsTestType(rawTypeString, rawTypeString)
}
} else {
rawType
@@ -294,7 +294,7 @@ public class IvyDependencyManager extends AbstractIvyDependencyManager implement
// dependencies needed for running tests
- test "junit:junit:3.8.2",
+ test "junit:junit:4.8.1",
"org.grails:grails-test:$grailsVersion",
"org.springframework:org.springframework.test:3.0.0.RELEASE"
@@ -359,7 +359,7 @@ public class IvyDependencyManager extends AbstractIvyDependencyManager implement
}
/**
- * For usages such as addPluginDependency("foo", [group:"junit", name:"junit", version:"3.8.2"])
+ * For usages such as addPluginDependency("foo", [group:"junit", name:"junit", version:"4.8.1"])
*
* This method is designed to be used by the internal framework and plugins and not be end users.
* The idea is that plugins can provide dependencies at runtime which are then inherited by
@@ -1,100 +0,0 @@
-/*
- * Copyright 2009 the original author or authors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.codehaus.groovy.grails.test.junit3
-
-import junit.framework.Test
-import junit.framework.TestResult
-import junit.framework.TestSuite
-
-import org.springframework.context.ApplicationContext
-
-import java.util.regex.Matcher
-import java.util.regex.Pattern
-
-import org.codehaus.groovy.grails.test.support.GrailsTestAutowirer
-import org.codehaus.groovy.grails.test.support.GrailsTestRequestEnvironmentInterceptor
-import org.codehaus.groovy.grails.test.support.GrailsTestTransactionInterceptor
-import org.codehaus.groovy.grails.test.support.ControllerNameExtractor
-
-import grails.util.GrailsNameUtils
-
-/**
- * A Grails specific test suite that runs tests in a “Grails” environment. That is,
- * subjects the tests to autowiring of dependencies (by name), establishes a request like environment,
- * and inside a rollback only transaction (unless the test is not transactional).
- *
- * @see GrailsTestAutowirer
- * @see GrailsTestRequestEnvironmentInterceptor
- * @see GrailsTestTransactionInterceptor
- */
-class JUnit3GrailsEnvironmentTestSuite extends TestSuite {
-
- GrailsTestAutowirer autowirer
- GrailsTestRequestEnvironmentInterceptor requestEnvironmentInterceptor
- GrailsTestTransactionInterceptor transactionInterceptor
-
- final JUnit3GrailsTestTypeMode mode
-
- /**
- * @see TestSuite(Class)
- */
- JUnit3GrailsEnvironmentTestSuite(Class test, ApplicationContext applicationContext, JUnit3GrailsTestTypeMode mode) {
- super(test)
- init(applicationContext, mode)
- }
-
- JUnit3GrailsEnvironmentTestSuite(ApplicationContext applicationContext, JUnit3GrailsTestTypeMode mode) {
- init(applicationContext, mode)
- }
-
- protected init(ApplicationContext applicationContext, JUnit3GrailsTestTypeMode mode) {
- this.mode = mode
- autowirer = new GrailsTestAutowirer(applicationContext)
- requestEnvironmentInterceptor = new GrailsTestRequestEnvironmentInterceptor(applicationContext)
- transactionInterceptor = new GrailsTestTransactionInterceptor(applicationContext)
- }
-
- void runTest(Test test, TestResult result) {
- if (mode.autowire) {
- autowirer.autowire(test)
- }
-
- def rawRunner = { test.run(result) }
-
- def inTransactionRunner
- if (mode.wrapInTransaction && transactionInterceptor.isTransactional(test)) {
- inTransactionRunner = { transactionInterceptor.doInTransaction(rawRunner) }
- } else {
- inTransactionRunner = rawRunner
- }
-
- def inRequestRunner
- if (mode.wrapInRequestEnvironment) {
- def controllerName = ControllerNameExtractor.extractControllerNameFromTestClassName(test.class.name, JUnit3GrailsTestType.TESTS_SUFFIX)
- if (controllerName) {
- controllerName = GrailsNameUtils.getPropertyName(controllerName)
- inRequestRunner = { requestEnvironmentInterceptor.doInRequestEnvironment(controllerName, inTransactionRunner) }
- } else {
- inRequestRunner = { requestEnvironmentInterceptor.doInRequestEnvironment(inTransactionRunner) }
- }
- } else {
- inRequestRunner = inTransactionRunner
- }
-
- inRequestRunner()
- }
-}
Oops, something went wrong.

0 comments on commit 8a6d774

Please sign in to comment.