rcasia / neotest-java

Neotest adapter for Java.
MIT License
42 stars 23 forks source link

Error while running Test #98

Closed Maduki-tech closed 6 months ago

Maduki-tech commented 6 months ago

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!

rcasia commented 6 months ago

First thing I see is the version of your junit_jar is 1.10.1 in contrast with your project dependency 5.10.1.

It is failing to generate the test report file because something went wrong in the test execution.

Can you share the output after a test run?

require("neotest").output_panel.open()
JonaLoeffler commented 6 months ago

I have the same issue.

Lazy config for neotest-java ```lua 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', 'tr', require('neotest').run.run, { desc = '[T]est [R]un', noremap = true }) vim.keymap.set('n', 'ts', require('neotest').run.stop, { desc = '[T]est [S]top', noremap = true }) vim.keymap.set('n', 'ta', require('neotest').run.attach, { desc = '[T]est [A]ttach', noremap = true }) vim.keymap.set('n', 'to', require('neotest').output.open, { desc = '[T]est output [O]pen', noremap = true }) end, }, } ```
Output of require('neotest').output_panel.open() ``` src/main/java/plusone/models/Response.java:3: error: package lombok does not exist import lombok.AllArgsConstructor; ^ src/main/java/plusone/models/Response.java:4: error: package lombok does not exist import lombok.Builder; ^ src/main/java/plusone/models/Response.java:5: error: package lombok does not exist import lombok.Data; ^ src/main/java/plusone/models/Response.java:6: error: package lombok does not exist import lombok.NoArgsConstructor; ^ src/main/java/plusone/models/Response.java:8: error: cannot find symbol @Data ^ symbol: class Data src/main/java/plusone/models/Response.java:9: error: cannot find symbol @Builder ^ symbol: class Builder src/main/java/plusone/models/Response.java:10: error: cannot find symbol @NoArgsConstructor ^ symbol: class NoArgsConstructor src/main/java/plusone/models/Response.java:11: error: cannot find symbol @AllArgsConstructor ^ symbol: class AllArgsConstructor src/main/java/plusone/models/Todo.java:8: error: package lombok does not exist import lombok.AllArgsConstructor; ^ src/main/java/plusone/models/Todo.java:9: error: package lombok does not exist import lombok.Builder; ^ src/main/java/plusone/models/Todo.java:10: error: package lombok does not exist import lombok.Data; ^ src/main/java/plusone/models/Todo.java:11: error: package lombok does not exist import lombok.NoArgsConstructor; ^ src/main/java/plusone/models/Todo.java:13: error: cannot find symbol @Data ^ symbol: class Data src/main/java/plusone/models/Todo.java:14: error: cannot find symbol @Builder ^ symbol: class Builder src/main/java/plusone/models/Todo.java:15: error: cannot find symbol @NoArgsConstructor ^ symbol: class NoArgsConstructor src/main/java/plusone/models/Todo.java:16: error: cannot find symbol @AllArgsConstructor ^ symbol: class AllArgsConstructor src/main/java/plusone/TodoController.java:6: error: package lombok.extern.slf4j does not exist import lombok.extern.slf4j.Slf4j; ^ src/main/java/plusone/TodoController.java:19: error: cannot find symbol @Slf4j ^ symbol: class Slf4j src/main/java/plusone/TodoController.java:33: error: cannot find symbol return Response.>builder().data(todos).build(); ^ symbol: method >builder() location: class Response src/main/java/plusone/TodoController.java:40: error: cannot find symbol return Response.builder().data(todo).build(); ^ symbol: method builder() location: class Response src/main/java/plusone/TodoController.java:46: error: cannot find symbol todo.setCreatedAt(new Date()); ^ symbol: method setCreatedAt(Date) location: variable todo of type @jakarta.validation.Valid Todo src/main/java/plusone/TodoController.java:50: error: cannot find symbol return Response.builder().data(saved).build(); ^ symbol: method builder() location: class Response 22 errors ```
Maduki-tech commented 6 months ago

First thing I see is the version of your junit_jar is 1.10.1 in contrast with your project dependency 5.10.1.

well, this is the latest version for everything. Do you mean I need to downgrade from 5.10.1 to 1.10.1 in my project?

when I run require("neotest").output_panel.open() this is my error

bash: line 0: globstar: invalid shell option name

rcasia commented 6 months ago

well, this is the latest version for everything. Do you mean I need to downgrade from 5.10.1 to 1.10.1 in my project?

@Maduki-tech I apologize for the oversight. Your versions were correct.

It seems that the problem was that your bash version does not support globstar option (versions before 4).

To avoid that I removed all the globs from the command.

rcasia commented 6 months ago

@JonaLoeffler you seem to have a different issue.

Have you tried to run gradle build or mvn compile and run the tests again?

Maduki-tech commented 6 months ago

@rcasia amazing, this fixed my error. THX

JonaLoeffler commented 6 months ago

@JonaLoeffler you seem to have a different issue.

Have you tried to run gradle build or mvn compile and run the tests again?

@rcasia I did and it's all green, now with the latest plugin updates I get

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',
      },
      opts = {
        adapters = {
          ['neotest-java'] = {
            ignore_wrapper = false, -- whether to ignore maven/gradle wrapper
          },
        },
      },
    },
    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.

JonaLoeffler commented 6 months ago

Version v.1.10.0 is still working for me though.

rcasia commented 6 months ago

how is your project structure? does src/test/java exist?

JonaLoeffler commented 6 months ago

No, it 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.

rcasia commented 6 months ago

I see... It is a problem running tests in multimodule projects. Can you open a different issue, pls? I will be on it as soon as posible.

JonaLoeffler commented 6 months ago

Done, #100.

No worries, everything is still working flawlessly when I pin the plugin version to v1.10.0.

Thanks for the great work!