/neotest-java

Neotest adapter for Java.

Primary LanguageLuaMIT LicenseMIT

neotest-java

Neotest adapter for Java, using JUnit.

👷 There is still Work In Progress

🌕 🌕 🌕 🌕 🌕 🌕 🌕 🌕 🌕 🌗

🔧 Installation

It requires nvim-treesitter

Warning

Make sure you have the java parser installed. Use :TSInstall java

vim-plug:

Plug 'rcasia/neotest-java'

LazyVim distro:

return {
  {
    "rcasia/neotest-java",
    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("jdtls.dap").test_class() end, mode = "n" }
      -- debug nearest test
      keys[#keys + 1] = {"<leader>td", function() require("jdtls.dap").test_nearest_method() end, mode = "n" }
    end,
  },
  {
    "nvim-neotest/neotest",
    dependencies = {
      "nvim-neotest/nvim-nio",
      "nvim-lua/plenary.nvim",
      "antoinemadec/FixCursorHold.nvim",
      "nvim-treesitter/nvim-treesitter"
    },
    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 and place it in the default directory

⚙️ Configuration

require("neotest").setup({
  adapters = {
    require("neotest-java")({
        ignore_wrapper = false, -- whether to ignore maven/gradle wrapper
        junit_jar = "path/to/junit-standalone.jar",
        -- default: .local/share/nvim/neotest-java/junit-platform-console-standalone-[version].jar
    })
  }
})

:octocat: Contributing

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