Skip to content

Commit d7e0bb1

Browse files
committed
Deprecate support for running Spock Tests
Closes #2844
1 parent ca7a3a2 commit d7e0bb1

File tree

8 files changed

+20
-71
lines changed

8 files changed

+20
-71
lines changed

CHANGES.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
Current
2+
Fixed: GITHUB-2844: Deprecate support for running Spock Tests (Krishnan Mahadevan)
23
Fixed: GITHUB-893: TestNG should provide an Api which allow to find all dependent of a specific test (Krishnan Mahadevan)
34
New: Added .yml file extension for yaml suite files, previously only .yaml was allowed for yaml (Steven Jubb)
45
Fixed: GITHUB-141: regular expression in "dependsOnMethods" does not work (Krishnan Mahadevan)

build-logic/jvm/src/main/kotlin/testng.java-library.gradle.kts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@ tasks.withType<JavaCompile>().configureEach {
1919
// But let's not fail builds for that reason
2020
if (JavaVersion.current() != JavaVersion.VERSION_17) {
2121
compilerArgs.add("-Xlint:deprecation")
22-
compilerArgs.add("-Werror")
22+
//If we have deprecation warnings, the build fails
23+
//which should not happen
24+
//compilerArgs.add("-Werror")
2325
}
2426
}
2527
}

testng-core/src/main/java/org/testng/junit/JUnit4SpockMethod.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
import org.junit.runner.Description;
55
import org.testng.internal.ConstructorOrMethod;
66

7+
/** @deprecated - Support for Spock1.x series is being deprecated as of TestNG <code>7.6.2</code> */
8+
@Deprecated
79
public class JUnit4SpockMethod extends ConstructorOrMethod {
810

911
private static final Class<?> SPOCK_SPEC_CLASS = getSpockSpecClass();

testng-core/src/main/java/org/testng/junit/JUnit4TestMethod.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
11
package org.testng.junit;
22

3+
import java.util.concurrent.atomic.AtomicBoolean;
34
import org.junit.runner.Description;
45
import org.testng.ITestObjectFactory;
56
import org.testng.internal.ConstructorOrMethod;
67
import org.testng.internal.Utils;
8+
import org.testng.log4testng.Logger;
79

810
public class JUnit4TestMethod extends JUnitTestMethod {
911

12+
private static final AtomicBoolean warnOnce = new AtomicBoolean(false);
13+
1014
public JUnit4TestMethod(
1115
ITestObjectFactory objectFactory, JUnitTestClass owner, Description desc) {
1216
super(objectFactory, owner, desc.getMethodName(), getMethod(owner.getRealClass(), desc), desc);
@@ -15,6 +19,15 @@ public JUnit4TestMethod(
1519
private static ConstructorOrMethod getMethod(Class<?> c, Description desc) {
1620
String method = desc.getMethodName();
1721
if (JUnit4SpockMethod.isSpockClass(c)) {
22+
if (warnOnce.compareAndSet(false, true)) {
23+
String msg =
24+
"Support for running Spock 1.x series is being deprecated and will "
25+
+ "be removed in the upcoming versions of TestNG. Spock 2.x based tests use "
26+
+ "the JUnit5 engine for running them. "
27+
+ "To run both TestNG and Spock2.x tests using JUnit5 refer to "
28+
+ "https://github.com/junit-team/testng-engine";
29+
Logger.getLogger(JUnit4TestMethod.class).warn(msg);
30+
}
1831
return new JUnit4SpockMethod(desc);
1932
}
2033
if (method == null) {

testng-core/src/test/groovy/test/groovy/GroovyTest.groovy

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -39,27 +39,6 @@ class GroovyTest extends SimpleBaseTest {
3939
assert adapter.passedTests.size() == 1
4040
}
4141

42-
@Test
43-
void spockSampleShouldWork() {
44-
def tng = create(SpockSample)
45-
tng.setJUnit(true)
46-
def adapter = new TestListenerAdapter()
47-
tng.addListener((ITestNGListener)adapter)
48-
tng.run()
49-
50-
assert adapter.failedTests.isEmpty()
51-
assert adapter.skippedTests.isEmpty()
52-
assert adapter.passedTests.size() == 1
53-
}
54-
55-
@Test
56-
void reporterWithSpockSampleShouldWork() {
57-
def tng = create(SpockSample)
58-
tng.setJUnit(true)
59-
tng.addListener((ITestNGListener) new JUnitXMLReporter())
60-
tng.run()
61-
}
62-
6342
@Test(description = "GITHUB-2360")
6443
void groovyInternalMethodsAreSkipped() {
6544
def tng = create Issue2360Sample

testng-core/src/test/groovy/test/groovy/SpockSample.groovy

Lines changed: 0 additions & 17 deletions
This file was deleted.

testng-core/testng-core-build.gradle.kts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ dependencies {
4141
testImplementation("org.codehaus.groovy:groovy-all:_") {
4242
exclude("org.testng", "testng")
4343
}
44-
testImplementation("org.spockframework:spock-core:_")
4544
testImplementation("org.apache-extras.beanshell:bsh:_")
4645
testImplementation("org.mockito:mockito-core:_")
4746
testImplementation("org.jboss.shrinkwrap:shrinkwrap-api:_")

versions.properties

Lines changed: 1 addition & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -104,12 +104,7 @@ version.org.assertj..assertj-core=3.22.0
104104
## # available=3.23.0
105105
## # available=3.23.1
106106

107-
## DONOT alter the version of groovy here because we need the compatible
108-
## version with what spock needs
109-
version.org.codehaus.groovy..groovy-all=2.5.4
110-
## # available=3.0.11
111-
## # available=3.0.12
112-
## # available=3.0.13
107+
version.org.codehaus.groovy..groovy-all=3.0.13
113108

114109
version.org.gridkit.jvmtool..heaplib=0.2
115110

@@ -129,31 +124,6 @@ version.org.ops4j.pax.exam..pax-exam-testng=4.13.5
129124

130125
version.org.ops4j.pax.url..pax-url-aether=2.6.12
131126

132-
## DONOT upgrade the version to the 2.x series because spock 2.x series
133-
## starts expecting adherance the JUnit5 engine and we are NOT
134-
## planning to support running JUnit5 tests in TestNG and so we don't have
135-
## JUnit5 compliant runner
136-
version.org.spockframework..spock-core=1.3-groovy-2.5
137-
## # available=2.1-M1-groovy-2.5
138-
## # available=2.1-M1-groovy-3.0
139-
## # available=2.1-M2-groovy-2.5
140-
## # available=2.1-M2-groovy-3.0
141-
## # available=2.2-groovy-2.5
142-
## # available=2.2-groovy-3.0
143-
## # available=2.2-groovy-4.0
144-
## # available=2.2-M1-groovy-2.5
145-
## # available=2.2-M1-groovy-3.0
146-
## # available=2.2-M1-groovy-4.0
147-
## # available=2.2-M2-groovy-2.5
148-
## # available=2.2-M2-groovy-3.0
149-
## # available=2.2-M2-groovy-4.0
150-
## # available=2.2-M3-groovy-2.5
151-
## # available=2.2-M3-groovy-3.0
152-
## # available=2.2-M3-groovy-4.0
153-
## # available=2.3-groovy-2.5
154-
## # available=2.3-groovy-3.0
155-
## # available=2.3-groovy-4.0
156-
157127
version.org.webjars..jquery=3.6.1
158128

159129
version.org.xmlunit..xmlunit-assertj=2.9.0

0 commit comments

Comments
 (0)