Skip to content

feat: run tests for files changed in the Git working tree - #386

Merged
RoiSoleil merged 6 commits into
masterfrom
feature/run-tests-for-changed-files
Sep 19, 2026
Merged

RoiSoleil merged 6 commits into
masterfrom
feature/run-tests-for-changed-files

Conversation

@RoiSoleil

@RoiSoleil RoiSoleil commented Sep 19, 2026 •

Copy link
Copy Markdown
Contributor

What

Adds a Run Tests for Changed Files command to Java projects: MoreUnit asks EGit/JGit for the files that changed since the last commit, finds the tests that correspond to them, and runs those tests.

Right-click a Java project in the Package Explorer → MoreUnit → Run Tests for Changed Files. The command is also available from org.moreunit.runtestsforchangedfiles (no default shortcut, it can be bound in Preferences → General → Keys), so it also works from the editor with the project of the open file.

Behaviour

  • Changed files are read from the Git working tree with JGit — no git executable is spawned.
  • Staged, unstaged and untracked files are taken into account, as well as deleted and conflicting ones.
  • A changed test file is run as is; for a changed class under test, all its corresponding test cases are run.
  • Abstract test cases and test interfaces are replaced by their concrete subclasses.
  • Tests are grouped by test type (JUnit 3/4/5, TestNG, Spock) so each group is run by the proper runner — this matters when a workspace mixes them.
  • When there is nothing to run, an information dialog explains why (no changed Java file / no corresponding test).
  • When several projects are selected, their changed files are merged and duplicates are removed.

Git integration

EGit is now a required dependency of the MoreUnit For Java feature:

  • org.moreunit requires org.eclipse.egit.core and org.eclipse.jgit (Require-Bundle), and org.moreunit.feature declares the same requirements, so p2 installs them together with MoreUnit.
  • GitRepositories locates the repository of a workspace resource: the closest repository is looked up from the project location with JGit (always up to date), and EGit is asked through the public org.eclipse.egit.core.info.GitInfo adapter when that lookup finds nothing — for instance when the project has been connected to a repository which is not one of its parent directories.
  • GitWorkingTreeChanges reads the changed files through the JGit status command.
  • GitRepository is a handle which closes the repository only when MoreUnit opened it: the ones owned by EGit are left open.

org.moreunit.git is exported with x-friends for org.moreunit.test, so the tests can exercise it directly.

Target platform

The EGit update site (https://download.eclipse.org/egit/updates/) is added to org.moreunit.build/eclipse-latest.target with the org.eclipse.jgit and org.eclipse.egit.core units, so the build and the tests can compile and run against them.

Tests

All green locally:

  • GitWorkingTreeChangesTest (8 tests), GitRepositoriesTest (4) and GitChangedFilesProviderTest (4) — the Git ones run against real temporary repositories created with JGit
  • ChangedTestsFinderTest (5), RunChangedTestsActionExecutorTest (7), JavaProjectsTest (4)
  • RunChangedTestsSWTBotTest (1) asserts the menu entry is present on a Java project
  • Full build (clean verify, SWTBot excluded as in CI): BUILD SUCCESS, 903 tests in org.moreunit.test, 0 failure

The help page (org.moreunit.plugin/help/documentation.html) documents the new command.

Notes

  • The first commit of this branch used the git executable, then JGit as an optional dependency; this final version uses JGit/EGit as a required dependency.

Add a "Run Tests for Changed Files" command on Java projects: it asks Git
for the files changed since the last commit (staged, unstaged and
untracked), maps them to their tests, and runs those tests.

- a changed test file is run as is
- for a changed class, all its corresponding test cases are run
  (abstract test cases are replaced by their concrete subclasses)
- tests are grouped by test type so that each group is run by the proper
  test runner
- when nothing can be run, the user is told why

Git support lives in org.moreunit.core.git: a small command runner
interface, its native implementation (with a timeout, and
--no-optional-locks to avoid interfering with other tools), and the
parsing of "git status --porcelain=v1 -z".
Replace the external "git" process by JGit, on which EGit is built: no
dependency on a git executable anymore, and the repositories EGit has
already opened are reused when EGit is installed.

- GitRepositories locates the repository of a workspace resource: it asks
  EGit first (through the public GitInfo adapter, which handles linked
  working trees, submodules and non-standard layouts), then falls back to
  JGit's FileRepositoryBuilder.
- GitWorkingTreeChanges reports the changed files of a working tree
  (staged, unstaged, untracked, deleted and conflicting) through the JGit
  status command.
- GitRepository is a small handle which closes the repository only when
  MoreUnit opened it: the ones owned by EGit are left open.

JGit and EGit are optional dependencies of the plug-in (optional
Import-Package), and the "Run Tests for Changed Files" command is hidden
when JGit is not installed. The EGit update site is part of the target
platform so that the build and the tests can use them.
EGit and JGit become required dependencies of MoreUnit For Java instead
of optional ones:

- org.moreunit requires org.eclipse.egit.core and org.eclipse.jgit, and
  org.moreunit.feature declares the same requirements so that p2 installs
  them together with MoreUnit.
- the code can rely on them: GitSupport (bundle detection) and
  EgitRepositories (lazy loading of EGit types) are removed, and the
  "Git support is not installed" message with them.
- the closest repository is now looked up from the project location with
  JGit first (always up to date), and EGit is asked through the GitInfo
  adapter when that lookup finds nothing, for instance when the project
  is connected to a repository which is not one of its parent
  directories.
- the test bundles require EGit/JGit so that the test runtime resolves
  them.
The previous test needed the "git" executable and left files which
cannot be deleted on Windows when git is missing, failing the test with
"Failed to close extension context". The new test writes the ".git"
file of a linked working tree itself, so it runs everywhere.
JGit may keep a file handle for a short while after a repository is
closed, which makes the deletion of its directory fail on Windows and,
in turn, fails the test with 'Failed to close extension context'. The
Git tests now delete their temporary files themselves, retrying a few
times, and JUnit is told not to clean the directory up.
@RoiSoleil
RoiSoleil merged commit 30139e0 into master Sep 19, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant