Neotest adapter for Java, using JUnit.
- ✅ Maven and Gradle projects
- ✅ Multimodule projects
- ✅ Debugging tests with
nvim-dap
Check ROADMAP.md to see what's coming!
- Make sure you have installed nvim-treesitter parsers. Use
:TSInstall java groovy
- Add neotest-java to your config:
LazyVim distro installation
return {
{
"rcasia/neotest-java",
ft = "java",
dependencies = {
"mfussenegger/nvim-jdtls",
"mfussenegger/nvim-dap", -- for the debugger
"rcarriga/nvim-dap-ui", -- recommended
"theHamsta/nvim-dap-virtual-text", -- recommended
},
init = function()
-- override the default keymaps.
-- needed until neotest-java is integrated in LazyVim
local keys = require("lazyvim.plugins.lsp.keymaps").get()
-- run test file
keys[#keys + 1] = {"<leader>tt", function() require("neotest").run.run(vim.fn.expand("%")) end, mode = "n" }
-- run nearest test
keys[#keys + 1] = {"<leader>tr", function() require("neotest").run.run() end, mode = "n" }
-- debug test file
keys[#keys + 1] = {"<leader>tD", function() require("neotest").run.run({ strategy = "dap" }) end, mode = "n" }
-- debug nearest test
keys[#keys + 1] = {"<leader>td", function() require("neotest").run.run({ vim.fn.expand("%"), strategy = "dap" }) end, mode = "n" }
end,
},
{
"nvim-neotest/neotest",
dependencies = {
"nvim-neotest/nvim-nio",
"nvim-lua/plenary.nvim",
"antoinemadec/FixCursorHold.nvim",
"nvim-treesitter/nvim-treesitter"
},
opts = {
adapters = {
["neotest-java"] = {
-- config here
},
},
},
},
}
lazy.nvim plugin manager
return {
{
"rcasia/neotest-java",
ft = "java",
dependencies = {
"mfussenegger/nvim-jdtls",
"mfussenegger/nvim-dap", -- for the debugger
"rcarriga/nvim-dap-ui", -- recommended
"theHamsta/nvim-dap-virtual-text", -- recommended
},
},
{
"nvim-neotest/neotest",
dependencies = {
"nvim-neotest/nvim-nio",
"nvim-lua/plenary.nvim",
"antoinemadec/FixCursorHold.nvim",
"nvim-treesitter/nvim-treesitter"
},
opts = {
adapters = {
["neotest-java"] = {
-- config here
},
},
},
},
}
- Run
:NeotestJava setup
Note
It will download the JUnit standalone jar from https://mvnrepository.com/artifact/org.junit.platform/junit-platform-console-standalone
{
junit_jar = nil, -- default: stdpath("data") .. /nvim/neotest-java/junit-platform-console-standalone-[version].jar
incremental_build = true
}
Feel free to contribute to this project by creating issues for bug reports, feature requests, or suggestions.
You can also submit pull requests for any enhancements, bug fixes, or new features.
Your contributions are greatly appreciated. See CONTRIBUTING.md