From 87981f798dc47cdca9387f0c69522d34c25638e8 Mon Sep 17 00:00:00 2001 From: Marco Kursawe Date: Sat, 10 Jan 2026 17:30:24 +0100 Subject: [PATCH] feat: add JavaTestRunAllTests and JavaTestDebugAllTests commands --- lua/java-test/api.lua | 34 ++++++++++++++++++++++++++++++++++ lua/java-test/init.lua | 28 ++++++++++++++++++++++++++++ plugin/java.lua | 12 ++++++++++++ 3 files changed, 74 insertions(+) diff --git a/lua/java-test/api.lua b/lua/java-test/api.lua index 93e327a..71103f6 100644 --- a/lua/java-test/api.lua +++ b/lua/java-test/api.lua @@ -157,4 +157,38 @@ function M:find_current_test_method() end end +---Run all tests in the workspace +---@param report java-test.JUnitTestReport +---@param config java-dap.DapLauncherConfigOverridable +function M:execute_all_tests(report, config) + log.debug('running all tests') + + local projects = self.test_client:find_java_projects() + + if #projects < 1 then + notify.warn('No Java projects found') + return + end + + -- Discover test classes from all projects + local all_tests = {} + for _, project in ipairs(projects) do + local packages = self.test_client:find_test_packages_and_types(project.jdtHandler) + for _, pkg in ipairs(packages or {}) do + -- Package children are the test classes + for _, test_class in ipairs(pkg.children or {}) do + table.insert(all_tests, test_class) + end + end + end + + if #all_tests < 1 then + notify.warn('No tests found in workspace') + return + end + + log.debug('found ' .. #all_tests .. ' test classes') + self:run_test(all_tests, report, config) +end + return M diff --git a/lua/java-test/init.lua b/lua/java-test/init.lua index 2b2f481..2c525cc 100644 --- a/lua/java-test/init.lua +++ b/lua/java-test/init.lua @@ -71,6 +71,34 @@ function M.run_current_method() .run() end +function M.run_all_tests() + log.info('run all tests') + + return runner(function() + local test_api = JavaTestApi:new({ + client = lsp_utils.get_jdtls(), + runner = DapRunner(), + }) + return test_api:execute_all_tests(M.get_report(), { noDebug = true }) + end) + .catch(get_error_handler('failed to run all tests')) + .run() +end + +function M.debug_all_tests() + log.info('debug all tests') + + return runner(function() + local test_api = JavaTestApi:new({ + client = lsp_utils.get_jdtls(), + runner = DapRunner(), + }) + return test_api:execute_all_tests(M.get_report(), {}) + end) + .catch(get_error_handler('failed to debug all tests')) + .run() +end + function M.view_last_report() if M.last_report then M.last_report:show_report() diff --git a/plugin/java.lua b/plugin/java.lua index 524dc3d..5feba3f 100644 --- a/plugin/java.lua +++ b/plugin/java.lua @@ -35,6 +35,18 @@ local cmd_map = { end, }, + JavaTestRunAllTests = { + function() + require('java-test').run_all_tests() + end, + }, + + JavaTestDebugAllTests = { + function() + require('java-test').debug_all_tests() + end, + }, + JavaTestViewLastReport = { function() require('java-test').view_last_report()