Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions lua/java-test/api.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
28 changes: 28 additions & 0 deletions lua/java-test/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
12 changes: 12 additions & 0 deletions plugin/java.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down