rcasia / neotest-java

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

"This test was not executed" when using `org.junit.Test` import #133

Closed stefanwatt closed 2 months ago

stefanwatt commented 2 months ago

The test is correctly displayed in the summary panel and the Icon also updates. However when running nearest test I get this message in the output-panel: "This test was not executed."

The test runs fine via mvn test and I can debug the test perfectly fine with:

require("neotest").run.run({ vim.fn.expand("%"), strategy = "dap" })

Since the output is not particularly helpful I would appreciate any help I can get debugging this.

rcasia commented 2 months ago

Hi @stefanwatt,

Could you share a minimal example of the test?

stefanwatt commented 2 months ago

Sure. Should've done that from the start... sorry. Here you go: https://github.com/stefanwatt/drools-test

RuleTest.java is the only test in there.

rcasia commented 2 months ago

I could reproduce the issue and found the following:

The solution is to read all three report files and process them. You can patch the following lines: https://github.com/rcasia/neotest-java/blob/d82f3a4aa797c1c62746511a169baf346b49db63/lua/neotest-java/core/result_builder.lua#L81-L96

Are you interested in filing a PR?

stefanwatt commented 2 months ago

Sure. I can give it a shot 👍

rcasia commented 2 months ago

Nice! Keep also in mind that spec.context.report_file is the one that actually is being read, and is set from https://github.com/rcasia/neotest-java/blob/d82f3a4aa797c1c62746511a169baf346b49db63/lua/neotest-java/core/spec_builder.lua#L81 and https://github.com/rcasia/neotest-java/blob/d82f3a4aa797c1c62746511a169baf346b49db63/lua/neotest-java/core/spec_builder.lua#L93

stefanwatt commented 2 months ago

Ok yup. Can confirm that it works when I change the filename in the spec_builder.lua or switch to junit 5 👍

Is it really necessary to process all three files? Would it not be sufficient to check which package is used and then decide based on that which report file to read?

Admittedly I don't know much about these report files. I read up a bit and it seems that generally you will only care about either TEST-junit-jupiter.xml or TEST-junit-vintage.xml but probably not both. Not sure how relevant TEST-junit-platform-suite.xml is.

rcasia commented 2 months ago

It is necessary because I have encountered codebases that use both Jupiter and Vintage engines. This issue may recur when different test classes utilize different engines.

Although the files differ, they share the same format, so this should be transparent to neotest-java.

In this case, it might be more useful if spec.context.report_file were spec.context.report_dir instead.

stefanwatt commented 2 months ago

Alright. I'll see what I can come up with.

stefanwatt commented 2 months ago

I pushed something that seems to work. I tested it with junit version 4 and 5. Just wanted to get some feedback before I write/adapt tests.