nvim btw...
rcasia / neotest-java Goto Github PK
View Code? Open in Web Editor NEWNeotest adapter for Java.
License: MIT License
Neotest adapter for Java.
License: MIT License
I'm relatively new to using DAP, so I'll need to delve into its functionalities and documentation to better understand the 'what' and 'how-to's. This is important for LazyVim/LazyVim#1984.
neotest-java/plugin/neotest-java.lua
Lines 12 to 30 in 9af20db
First, if the directory neotest-java doesn't exist, curl won't create it and will instead raise an error.
Second, curl writes some information to stderr even if it completes successfully, causing this function to raise an error regardless.
It needs to have the same features as currently supported for Maven.
Error is presented when a literal is printed during a test like in this example:
class ReactorPlaygroundApplicationTests {
@Test
void play() {
System.out.println("some literal");
}
}
Error message:
neotest-java: /home/rico/.local/share/nvim/lazy/neotest/lua/nio/init.lua:105: The coroutine failed with this message:
...REPOS/neotest-java/lua/neotest-java/util/test_parser.lua:55: attempt to index field 'table' (a nil value)
stack traceback:
...REPOS/neotest-java/lua/neotest-java/util/test_parser.lua: in function 'parse_html_gradle_report'
...OS/neotest-java/lua/neotest-java/core/result_builder.lua:74: in function 'read_testcases_from_html'
...OS/neotest-java/lua/neotest-java/core/result_builder.lua:136: in function 'results'
...al/share/nvim/lazy/neotest/lua/neotest/client/runner.lua:131: in function '_run_spec'
...al/share/nvim/lazy/neotest/lua/neotest/client/runner.lua:89: in function <...al/share/nvim/lazy/neotest/lua/neotest/client/runner.lua:88>
The neotest-java veredict says it is a skipped
test.
Hi, I'm experiencing the following error when I try to run the test in my project:
neotest-java: ...iu/AppData/Local/nvim-data/lazy/neotest/lua/nio/init.lua:105: The coroutine failed with this message:
...m-data/lazy/plenary.nvim/lua/plenary/context_manager.lua:47: C:\Users\ciriu\Documents\Projects\expense-app-v3\expenses-domain/target/surefire-reports/TEST-src\test\com\clt\usecase\PayUseCaseTest.xml: No such file or directory
stack traceback:
[C]: in function 'assert'
...m-data/lazy/plenary.nvim/lua/plenary/context_manager.lua:47: in function 'open'
...zy/neotest-java/lua/neotest-java/core/result_builder.lua:142: in function 'results'
...cal/nvim-data/lazy/neotest/lua/neotest/client/runner.lua:132: in function '_run_spec'
...cal/nvim-data/lazy/neotest/lua/neotest/client/runner.lua:89: in function <...cal/nvim-data/lazy/neotest/lua/neotest/client/runner.lua:88>
Am I missing something in how should I configure or use this plugin?
If it can help, the project on which I am trying to use this neotest-java is this
and this is my neovim configuration
EDIT: The problem seems to occur only on Windows, while it works fine on linux. Can it be related to the os file path separator?
With the latest plugin version, running tests in my multi-project gradle build fails.
The project consists of a number gradle sub-projects like com.company.app.web.server.<component>
for about 10 components. Each of these then has src/test/java
.
cat: build/neotest-java/classpath.txt: No such file or directory
error: --class-path requires an argument
Usage: javac <options> <source files>
use --help for a list of possible options
The statusline briefly shows src/test/java is not accessible by the current user!
, then Error reading file: /tmp/neotest-java/<some kind of id>/TEST-junit-jupiter.xml
This is my Lazy config for neotest:
return {
{
'rcasia/neotest-java',
ft = 'java',
dependencies = {
'nvim-neotest/neotest',
dependencies = {
'nvim-neotest/nvim-nio',
'nvim-lua/plenary.nvim',
'antoinemadec/FixCursorHold.nvim',
'nvim-treesitter/nvim-treesitter',
},
},
config = function()
require('neotest').setup {
adapters = {
require 'neotest-java' {
ignore_wrapper = false, -- whether to ignore maven/gradle wrapper
},
},
}
vim.keymap.set('n', '<leader>tp', function()
require('neotest').run.run(vim.uv.cwd())
end, { desc = '[T]est [P]project', noremap = true })
vim.keymap.set('n', '<leader>tf', function()
require('neotest').run.run(vim.fn.expand '%')
end, { desc = '[T]est [F]ile', noremap = true })
vim.keymap.set('n', '<leader>tr', function()
require('neotest').run.run()
end, { desc = '[T]est [R]un', noremap = true })
vim.keymap.set('n', '<leader>ts', function()
require('neotest').run.stop()
end, { desc = '[T]est [S]top', noremap = true })
vim.keymap.set('n', '<leader>ta', function()
require('neotest').run.attach()
end, { desc = '[T]est [A]ttach', noremap = true })
vim.keymap.set('n', '<leader>to', function()
require('neotest').output.open()
end, { desc = '[T]est output [O]pen', noremap = true })
end,
},
}
build/neotest-java/classpath.txt
does exist in the working directory, but is empty.
Version v.1.10.0
still works as before.
Using mvn and gradle CLIs as build tools works, but it is slow especially for big projects.
I tried a different strategy that could be implemented instead:
#!/bin/bash
MVN_CLASSPATH=$(mvn -q dependency:build-classpath -Dmdep.outputFile=/dev/stdout)
CLASSPATH="./target/classes/:./target/test-classes/:$MVN_CLASSPATH"
STANDALONE_JAR="/home/user/Downloads/junit-platform-console-standalone-1.10.1.jar"
FILEPATH="./src/test/java/com/example/ExampleApplicationTests.java"
ARGS="-m=com.example.ExampleApplicationTests#test --reports-dir=tmp"
javac -d target -cp $CLASSPATH:$STANDALONE_JAR $FILEPATH &&
java -jar $STANDALONE_JAR -cp $CLASSPATH $ARGS
When I try to run a test the command fails to execute. This is because fish doesn't support {}
blocks (used here).
I've gotten it to work by wrapping the command in a call to bash. (I need to enable globstar
otherwise it fails to find my files)
diff --git a/lua/neotest-java/core/spec_builder.lua b/lua/neotest-java/core/spec_builder.lua
index 6fd8222..639ee47 100644
--- a/lua/neotest-java/core/spec_builder.lua
+++ b/lua/neotest-java/core/spec_builder.lua
@@ -26,7 +26,7 @@ function SpecBuilder.build_spec(args, project_type, ignore_wrapper, config)
end
return {
- command = command:build(),
+ command = { "bash", "-O", "globstar", "-c", command:build() },
cwd = root,
symbol = position.name,
context = { report_file = reports_dir .. "/TEST-junit-jupiter.xml" },
@@ -42,7 +42,7 @@ function SpecBuilder.build_spec(args, project_type, ignore_wrapper, config)
command:test_reference(resolve_qualfied_name(absolute_path), position.name, "file")
return {
- command = command:build(),
+ command = { "bash", "-O", "globstar", "-c", command:build() },
cwd = root,
symbol = position.name,
context = { report_file = reports_dir .. "/TEST-junit-jupiter.xml" },
I was thinking of making a PR, but I'm not sure of what the best way of writing the bash
wrapper is
Hello,
my project setup is:
<!-- JUnit 5 -->
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<version>5.10.1</version>
<!-- can be omitted when using the BOM -->
<scope>test</scope>
</dependency>
This is my neotest config:
require("neotest").setup(
{
adapters = {
require("neotest-java")(
{
ignore_wrapper = false, -- whether to ignore maven/gradle wrapper
junit_jar = "/Users/davidschluter/.local/share/nvim/neotest-java/junit-platform-console-standalone-1.10.1.jar"
-- default:
}
)
}
}
)
Im also running the command:
require("neotest").run.run()
My error is the following:
Error reading file: /tmp/neotest-java/240424215135/TEST-junit-jupiter.xml
Also when I try to look at the file, there is no neotest-java
file in my /tmp/
dir.
Can someone help me with this error? If something is missing which you need to know, let me know!
Although neotest-java supports @ParameterizedTests, it has not been exhaustively tested with all annotation combinations.
This is a list of annotations to add:
It needs to be implement both for:
Maven builds fail due to mvn by default using the javahome env variable. However, different projects can be configured to use different runtimes. Furthermore, i myself have 5 jdks installed, my default my javahome points to jdk20. However, my projects do not use java 20. They use a range of versions from 11 to 17, which are explicitly configured in jdtls runtimes. Where jdtls is made aware of which runtime it must use. (or the user can provide all available runtimes on the system, and jdtls can deduce the default one to use, when it scans the gradle or pom files)
Before starting the mvn jobstart, one must export the correct javahome variable pointing to the projects default jdk. That can be obtained by either querying jdtls or as a fallback scanning the pom.
The runtime locations available on the system could be user configureable in the plugin config in case the fallback route is taken.
The primary idea, however, is to go with a jdtls query, which will return the currently configured default runtime and whrere on the system it is located at. That will then be used to set the javahome in jobstart / termopen.
As the title says... Use the mvn or gradle wrapper by default.
Also allow users to not use the wrapper changing the configuration.
When tying to execute the test below it fails stating thatapp.SomeTest.app.SomeNestedTest.*
doesn't exist. That's because it should try and run app.SomeTest$SomeNestedTest.*
instead.
package app;
public class SomeTest {
public static class SomeNestedTest {
@Test
public void someTest() {
assertEquals(1 + 1, 2);
}
}
}
Hi.
This is probably just a config error, but I haven't been able to figure it out.
I'm using the LazyVim distribution, and have tried to follow the setup for Neotest-java. All the setup works fine, :TSInstall java
and :NeoTestJava setup
both run without issues. However, when I try to run a test using <leader>tt
I get a "Neotest: No tests found" notification, despite my cursor literally being on the test. The LazyVim java extra, ["<leader>tt"] = { require("jdtls.dap").test_class, "Run All Test" },
version does work and runs the test correctly, so it's specifically the require("neotest")...
version that is unable to find and run the test.
I've tried this in as simple a scenario as I could think of, a basic Maven project with a Main.java file printing "HelloWorld!", and a test verifying that output. I've also checked to ensure TreeSitter is being correctly loaded, and it is indeed being loaded as a dependency of neotest, as seen here:
My config is a straight up copy-paste from the README.md, placed in lua/plugins/neotest.lua. I also tried placing the config in the suggested location, but it didn't fix the issue and I probably want the default configuration anyway so I removed it again.
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
},
},
},
}
Apparently it has an issue that tests with @DisplayName
are marked as skipped, no matter if passed or not:
I was able to fix this issue on my fork, the thing is i think i've broke the paramiterized tests xD
Idk if is something you can reuse, i refactored a bunch of stuff
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.