[2.x] test: Add nested-testquick scripted test (#8901)

**Problem**
The tests/nested-testquick scripted test only verified test and testQuick but did not exercise testOnly against individual test
classes, nor did it verify that a failing nested test class is detected.

**Solution**
- Added GoodCalcTest.java (with a Nested inner class) as a passing test.
- Added changed/BadCalcTest.java (with a Nested`inner class) as a deliberately failing test.
This commit is contained in:
atoz96 2026-03-13 20:05:43 -05:00 committed by GitHub
parent a944018716
commit b268321412
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
7 changed files with 104 additions and 0 deletions

View File

@ -0,0 +1,11 @@
Global / cacheStores := Seq.empty
ThisBuild / scalaVersion := "2.12.21"
lazy val root = (project in file("."))
.settings(
crossPaths := false,
autoScalaLibrary := false,
libraryDependencies += "com.github.sbt" % "junit-interface" % "0.13.2" % Test,
Test / parallelExecution := false,
)

View File

@ -0,0 +1,18 @@
package com.example;
import static org.junit.Assert.*;
import org.junit.Test;
public class BadCalcTest {
@Test
public void testBadAdd() {
assertEquals(99, Calc.add(1, 2));
}
public static class Nested {
@Test
public void testBadAddNegative() {
assertEquals(99, Calc.add(1, -2));
}
}
}

View File

@ -0,0 +1,7 @@
package com.example;
public class Calc {
public static int add(int a, int b) {
return a * b;
}
}

View File

@ -0,0 +1,7 @@
package com.example;
public class Calc {
public static int add(int a, int b) {
return a + b;
}
}

View File

@ -0,0 +1,19 @@
package com.example;
import static org.junit.Assert.*;
import org.junit.Test;
public class CalcTest {
@Test
public void testAdd() {
assertEquals(3, Calc.add(1, 2));
}
public static class Nested {
@Test
public void testAddNegative() {
assertEquals(-1, Calc.add(1, -2));
}
}
}

View File

@ -0,0 +1,18 @@
package com.example;
import static org.junit.Assert.*;
import org.junit.Test;
public class GoodCalcTest {
@Test
public void testAddPositive() {
assertEquals(3, Calc.add(1, 2));
}
public static class Nested {
@Test
public void testAddZero() {
assertEquals(0, Calc.add(0, 0));
}
}
}

View File

@ -0,0 +1,24 @@
# Verify that testQuick works with nested test classes.
# Nested test classes use $ encoding (e.g. CalcTest$Nested)
# and we need to verify that testQuick properly tracks them.
# Run all tests -- should pass.
> testOnly com.example.CalcTest com.example.GoodCalcTest
# testQuick should be a no-op since all tests passed.
> testQuick
# Verify testOnly picks up a good test.
> testOnly com.example.GoodCalcTest
# Copy in BadCalcTest and verify it fails.
$ copy-file changed/BadCalcTest.java src/test/java/com/example/BadCalcTest.java
> compile
-> testOnly com.example.BadCalcTest
# Introduce a bug in Calc.java (add -> multiply).
$ copy-file changed/Calc.java src/main/java/com/example/Calc.java
> compile
# testQuick should re-run and fail because the source changed.
-> testQuick