Merge pull request #8402 from anatoliykmetyuk/fix/forked-test-resources-access

Fix #8345: forked test execution doesn't access main resources
This commit is contained in:
eugene yokota 2025-12-08 23:14:35 -05:00 committed by GitHub
commit 507d221048
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 21 additions and 0 deletions

View File

@ -0,0 +1,6 @@
val scalatest = "org.scalatest" %% "scalatest" % "3.2.19"
scalaVersion := "3.7.3"
Test / fork := true
libraryDependencies += scalatest % Test

View File

@ -0,0 +1,2 @@
test resource content

View File

@ -0,0 +1,10 @@
import org.scalatest.funsuite.AnyFunSuite
class ResourceTest extends AnyFunSuite {
test("access main resource from forked test") {
val loader = Thread.currentThread().getContextClassLoader()
val resource = loader.getResource("foo")
assert(resource != null, "Resource 'foo' from src/main/resources should be accessible in forked test execution")
}
}

View File

@ -0,0 +1,2 @@
> test

View File

@ -325,6 +325,7 @@ public class ForkTestMain {
}
private void runTests(TestInfo info, ClassLoader classLoader) throws Exception {
Thread.currentThread().setContextClassLoader(classLoader);
final ExecutorService executor = executorService(info.parallel);
final TaskDef[] tests = info.taskDefs.toArray(new TaskDef[] {});
final int nFrameworks = info.testRunners.size();