Skip to content

Selfie JVM Snapshot Garbage Collection is overly zealous when using multiple test suites in gradle #574

Description

@aelfric

In a project I was using a separate integrationTest source set with the JVM Test Suite approach recommended by Gradle link to instructions.

When done this way, the integration test sources will be in src/integrationTest instead of src/test. The classes in src/test will not be on the classpath of the integration tests.

When running Selfie with JUnit5, the current garbage collection logic is hardcoded to only look for *.ss files in src/test/ and performs a Class.forName(...)  to see if that test still exists and has tests that match the snapshot. If it doesn't find a match, it deletes the file. 

Since the unit tests are invisible on the integrationTest classpath, though, Class.forName(...) throws a ClassNotFoundException so selfie assumes this is a stale file and deletes. As a consequence, all the unit test snapshots are deleted when running the integrationTest task.

Is there some way to get the correct source root from Junit or something like that to avoid deleting unmanaged files?

A reproducer of the described issue can be found here with instructions in the README https://github.com/aelfric/selfie-bug-report-reproducer

Activity

  1. nedtwigg commented on May 6, 2026

    @nedtwigg
    Member

    I think you can fix this by providing a SelfieSettings class which implements this:

    /**
    * If Selfie should look for test sourcecode in places other than the rootFolder, you can specify
    * them here. Selfie will not store snapshots in these folders.
    */
    open val otherSourceRoots: List<File>
    get() {
    return buildList {
    val rootDir = rootFolder
    val userDir = File(System.getProperty("user.dir"))
    for (standardDir in STANDARD_DIRS) {
    val candidate = userDir.resolve(standardDir)
    if (candidate.isDirectory && candidate != rootDir) {
    add(candidate)
    }
    }
    }
    }

    But very possible I'm misremembering. Happy to take a PR which makes this easier.

  2. aelfric commented on May 7, 2026

    @aelfric
    Author

    Yes, the SelfieSettings approach works, although I had to override rootFolder rather than otherSourceRoots to avoid deleting the unit test snapshots. I started reviewing the junit listener code in a bit more detail. I'm not sure if there is any sort of quick fix to PR but I'll keep looking.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingjvm

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions