IQSS / dataverse

Open source research data repository software
http://dataverse.org
Other
878 stars 489 forks source link

Can't run a unit test from Netbeans #10728

Open pdurbin opened 2 months ago

pdurbin commented 2 months ago

For over a decade I've been able to run unit tests from within Netbeans. This broke within the past year or so, perhaps with a JUnit upgrade? I'm not sure.

These days, when I click "Run -> Test File" like this...

Screenshot 2024-07-26 at 10 36 05 AM

... I get errors like this:

cd /Users/PDurbin/github/iqss/dataverse; JAVA_HOME=/Users/PDurbin/.sdkman/candidates/java/17.0.11-tem "/Applications/Apache NetBeans.app/Contents/Resources/netbeans/java/maven/bin/mvn" -Dtest=edu.harvard.iq.dataverse.util.json.JsonUtilTest --no-transfer-progress surefire:test
Running NetBeans Compile On Save execution. Phase execution is skipped and output directories of dependency projects (with Compile on Save turned on) will be used instead of their jar artifacts.
Scanning for projects...

----------------------< edu.harvard.iq:dataverse >----------------------
Building dataverse 6.3
  from pom.xml
--------------------------------[ war ]---------------------------------

--- surefire:3.2.5:test (default-cli) @ dataverse ---
Using auto detected provider org.apache.maven.surefire.junitplatform.JUnitPlatformProvider

-------------------------------------------------------
 T E S T S
-------------------------------------------------------
Error: Could not find or load main class ${surefire.jacoco.args}
Caused by: java.lang.ClassNotFoundException: ${surefire.jacoco.args}

Results:

Tests run: 0, Failures: 0, Errors: 0, Skipped: 0

------------------------------------------------------------------------
BUILD FAILURE
------------------------------------------------------------------------
Total time:  0.950 s
Finished at: 2024-07-26T10:36:30-04:00
------------------------------------------------------------------------
Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:3.2.5:test (default-cli) on project dataverse: 

Please refer to /Users/PDurbin/github/iqss/dataverse/target/surefire-reports for the individual test results.
Please refer to dump files (if any exist) [date].dump, [date]-jvmRun[N].dump and [date].dumpstream.
The forked VM terminated without properly saying goodbye. VM crash or System.exit called?
Command was /bin/sh -c cd '/Users/PDurbin/github/iqss/dataverse' && '/Users/PDurbin/.sdkman/candidates/java/17.0.11-tem/bin/java' '${surefire.jacoco.args}' '-Duser.timezone=UTC' '-Dfile.encoding=UTF-8' '-Duser.language=en' '-Duser.region=US' '-jar' '/Users/PDurbin/github/iqss/dataverse/target/surefire/surefirebooter-20240726103630388_3.jar' '/Users/PDurbin/github/iqss/dataverse/target/surefire' '2024-07-26T10-36-30_347-jvmRun1' 'surefire-20240726103630388_1tmp' 'surefire_0-20240726103630388_2tmp'
Error occurred in starting fork, check output in log
Process Exit Code: 1
org.apache.maven.surefire.booter.SurefireBooterForkException: The forked VM terminated without properly saying goodbye. VM crash or System.exit called?
Command was /bin/sh -c cd '/Users/PDurbin/github/iqss/dataverse' && '/Users/PDurbin/.sdkman/candidates/java/17.0.11-tem/bin/java' '${surefire.jacoco.args}' '-Duser.timezone=UTC' '-Dfile.encoding=UTF-8' '-Duser.language=en' '-Duser.region=US' '-jar' '/Users/PDurbin/github/iqss/dataverse/target/surefire/surefirebooter-20240726103630388_3.jar' '/Users/PDurbin/github/iqss/dataverse/target/surefire' '2024-07-26T10-36-30_347-jvmRun1' 'surefire-20240726103630388_1tmp' 'surefire_0-20240726103630388_2tmp'
Error occurred in starting fork, check output in log
Process Exit Code: 1
    at org.apache.maven.plugin.surefire.booterclient.ForkStarter.fork(ForkStarter.java:643)
    at org.apache.maven.plugin.surefire.booterclient.ForkStarter.run(ForkStarter.java:285)
    at org.apache.maven.plugin.surefire.booterclient.ForkStarter.run(ForkStarter.java:250)
    at org.apache.maven.plugin.surefire.AbstractSurefireMojo.executeProvider(AbstractSurefireMojo.java:1241)
    at org.apache.maven.plugin.surefire.AbstractSurefireMojo.executeAfterPreconditionsChecked(AbstractSurefireMojo.java:1090)
    at org.apache.maven.plugin.surefire.AbstractSurefireMojo.execute(AbstractSurefireMojo.java:910)
    at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:126)
    at org.apache.maven.lifecycle.internal.MojoExecutor.doExecute2(MojoExecutor.java:328)
    at org.apache.maven.lifecycle.internal.MojoExecutor.doExecute(MojoExecutor.java:316)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:212)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:174)
    at org.apache.maven.lifecycle.internal.MojoExecutor.access$000(MojoExecutor.java:75)
    at org.apache.maven.lifecycle.internal.MojoExecutor$1.run(MojoExecutor.java:162)
    at org.apache.maven.plugin.DefaultMojosExecutionStrategy.execute(DefaultMojosExecutionStrategy.java:39)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:159)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:105)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:73)
    at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build(SingleThreadedBuilder.java:53)
    at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:118)
    at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:261)
    at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:173)
    at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:101)
    at org.apache.maven.cli.MavenCli.execute(MavenCli.java:906)
    at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:283)
    at org.apache.maven.cli.MavenCli.main(MavenCli.java:206)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.base/java.lang.reflect.Method.invoke(Method.java:568)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:283)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:226)
    at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:407)
    at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:348)

-> [Help 1]

To see the full stack trace of the errors, re-run Maven with the -e switch.
Re-run Maven using the -X switch to enable full debug logging.

For more information about the errors and possible solutions, please read the following articles:
[Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException

As a workaround I've been running tests from the command line like this...

pdurbin@beamish dataverse % mvn test -Dtest=JsonUtilTest                                           
[INFO] Scanning for projects...
[INFO] 
[INFO] ----------------------< edu.harvard.iq:dataverse >----------------------
[INFO] Building dataverse 6.3
[INFO]   from pom.xml
[INFO] --------------------------------[ war ]---------------------------------
[INFO] 
[INFO] --- enforcer:3.3.0:enforce (general-reqs) @ dataverse ---
[INFO] Rule 0: org.apache.maven.enforcer.rules.BanDuplicatePomDependencyVersions passed
[INFO] Rule 1: org.apache.maven.enforcer.rules.version.RequireJavaVersion passed
[INFO] 
[INFO] --- jacoco:0.8.11:prepare-agent (jacoco-initialize) @ dataverse ---
[INFO] surefire.jacoco.args set to -javaagent:/Users/PDurbin/.m2/repository/org/jacoco/org.jacoco.agent/0.8.11/org.jacoco.agent-0.8.11-runtime.jar=destfile=/Users/PDurbin/github/iqss/dataverse/target/coverage-reports/jacoco-unit.exec,includes=edu/harvard/iq/dataverse/*:io/gdcc/*:org/dataverse/*
[INFO] 
[INFO] --- resources:3.3.1:resources (default-resources) @ dataverse ---
[INFO] Copying 35 resources from src/main/java to target/classes
[INFO] Copying 85 resources from src/main/resources to target/classes
[INFO] Copying 2 resources from src/main/resources to target/classes
[INFO] The encoding used to copy filtered properties files have not been set. This means that the same encoding will be used to copy filtered properties files as when copying other filtered resources. This might not be what you want! Run your build with --debug to see which files might be affected. Read more at https://maven.apache.org/plugins/maven-resources-plugin/examples/filtering-properties-files.html
[INFO] 
[INFO] --- compiler:3.11.0:compile (default-compile) @ dataverse ---
[INFO] Nothing to compile - all classes are up to date
[INFO] 
[INFO] --- smallrye-open-api:3.10.0:generate-schema (default) @ dataverse ---
[INFO] Wrote the schema files to /Users/PDurbin/github/iqss/dataverse/target/classes/META-INF
[INFO] 
[INFO] --- enforcer:3.3.0:enforce (no-junit4) @ dataverse ---
[INFO] Rule 0: org.apache.maven.enforcer.rules.dependency.BannedDependencies passed
[INFO] 
[INFO] --- resources:3.3.1:testResources (default-testResources) @ dataverse ---
[INFO] Copying 87 resources from src/test/resources to target/test-classes
[INFO] Copying 5 resources from conf/keycloak to target/test-classes/keycloak
[INFO] 
[INFO] --- compiler:3.11.0:testCompile (default-testCompile) @ dataverse ---
[INFO] Nothing to compile - all classes are up to date
[INFO] 
[INFO] --- surefire:3.2.5:test (default-test) @ dataverse ---
[INFO] Using auto detected provider org.apache.maven.surefire.junitplatform.JUnitPlatformProvider
[INFO] 
[INFO] -------------------------------------------------------
[INFO]  T E S T S
[INFO] -------------------------------------------------------
[INFO] Running edu.harvard.iq.dataverse.util.json.JsonUtilTest
Jul 26, 2024 2:32:39 PM edu.harvard.iq.dataverse.util.json.JsonUtil prettyPrint
INFO: Returning original string due to exception: java.lang.NullPointerException: Cannot invoke "String.trim()" because "jsonString" is null
Jul 26, 2024 2:32:39 PM edu.harvard.iq.dataverse.util.json.JsonUtil prettyPrint
INFO: Returning original string due to exception: jakarta.json.stream.JsonParsingException: Invalid token=EOF at (line no=1, column no=0, offset=-1). Expected tokens are: [CURLYOPEN, SQUAREOPEN, STRING, NUMBER, TRUE, FALSE, NULL]
Jul 26, 2024 2:32:39 PM edu.harvard.iq.dataverse.util.json.JsonUtil prettyPrint
INFO: Returning original string due to exception: jakarta.json.stream.JsonParsingException: Unexpected char 106 at (line no=1, column no=1, offset=0)
[INFO] Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.044 s -- in edu.harvard.iq.dataverse.util.json.JsonUtilTest
[INFO] 
[INFO] Results:
[INFO] 
[INFO] Tests run: 1, Failures: 0, Errors: 0, Skipped: 0
[INFO] 
[INFO] 
[INFO] --- jacoco:0.8.11:report (jacoco-after-unit) @ dataverse ---
[INFO] Loading execution data file /Users/PDurbin/github/iqss/dataverse/target/coverage-reports/jacoco-unit.exec
[INFO] Analyzed bundle 'dataverse' with 1047 classes
[WARNING] Classes in bundle 'dataverse' do not match with execution data. For report generation the same class files must be used as at runtime.
[WARNING] Execution data for class edu/harvard/iq/dataverse/api/Dataverses does not match.
[WARNING] Execution data for class edu/harvard/iq/dataverse/util/json/JsonParser does not match.
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  4.183 s
[INFO] Finished at: 2024-07-26T10:32:40-04:00
[INFO] ------------------------------------------------------------------------
pdurbin@beamish dataverse % 

... but it would be much more convenient to be able to run test from Netbeans again, as discussed in Slack.

pdurbin commented 2 months ago

This broke within the past year or so, perhaps with a JUnit upgrade?

In mid October 2023, I wrote this in Slack:

"Ever since we merged Migrate all tests to JUnit5 #9796, I haven’t been able to run API tests from Netbeans. Instead I’m running them like this: mvn test -Dtest=S3AccessIT. Can anyone confirm that you’re seeing the same thing?"

Other Netbeans users confirmed they are seeing the same thing.

poikilotherm commented 2 months ago

I cannot reproduce this problem with a fresh install of Netbeans 22 on Linux. I can select a single test file or even a test package and just run them. :shrug: Sorry!

This is what I get for the Netbeans shipped Maven, maybe there is something going on with an older Maven?

❯ /usr/lib/apache-netbeans/java/maven/bin/mvn -version
Apache Maven 3.9.6 (bc0240f3c744dd6b6ec2920b3cd08dcc295161ae)
Maven home: /usr/lib/apache-netbeans/java/maven
Java version: 17.0.9, vendor: Eclipse Adoptium, runtime: /home/obertuch/.sdkman/candidates/java/17.0.9-tem
Default locale: de_DE, platform encoding: UTF-8
OS name: "linux", version: "6.9.9-200.fc40.x86_64", arch: "amd64", family: "unix"
pdurbin commented 2 months ago

@poikilotherm thanks for testing!

I'm on a Mac, and I'm also using Netbeans 22.

There seems to be something amiss with the Dataverse repo. When I open this test from the Croissant repo, I can easily run it from Netbeans (with Run -> Test File or Cmd-F6): https://github.com/gdcc/exporter-croissant/blob/croissant-0.1.2/src/test/java/io/gdcc/spi/export/croissant/CroissantExporterTest.java

Here's the output:

cd /Users/PDurbin/github/gdcc/exporter-croissant; JAVA_HOME=/Users/PDurbin/.sdkman/candidates/java/17.0.11-tem "/Applications/Apache NetBeans.app/Contents/Resources/netbeans/java/maven/bin/mvn" -Dtest=io.gdcc.spi.export.croissant.CroissantExporterTest --no-transfer-progress process-test-classes surefire:test
Scanning for projects...

Some problems were encountered while building the effective model for io.gdcc.export:croissant:jar:0.1.3-SNAPSHOT
'build.plugins.plugin.version' for org.apache.maven.plugins:maven-compiler-plugin is missing. @ line 98, column 15

It is highly recommended to fix these problems because they threaten the stability of your build.

For this reason, future Maven versions might no longer support building such malformed projects.

Inspecting build with total of 1 modules...
Installing Nexus Staging features:
  ... total of 1 executions of maven-deploy-plugin replaced with nexus-staging-maven-plugin

----------------------< io.gdcc.export:croissant >----------------------
Building Croissant Exporter for Dataverse 0.1.3-SNAPSHOT
  from pom.xml
--------------------------------[ jar ]---------------------------------

--- resources:3.3.1:resources (default-resources) @ croissant ---
skip non existing resourceDirectory /Users/PDurbin/github/gdcc/exporter-croissant/src/main/resources

--- compiler:3.11.0:compile (default-compile) @ croissant ---
Nothing to compile - all classes are up to date

--- resources:3.3.1:testResources (default-testResources) @ croissant ---
Copying 21 resources from src/test/resources to target/test-classes

--- compiler:3.11.0:testCompile (default-testCompile) @ croissant ---
Nothing to compile - all classes are up to date

--- surefire:3.2.2:test (default-cli) @ croissant ---
Using auto detected provider org.apache.maven.surefire.junitplatform.JUnitPlatformProvider

-------------------------------------------------------
 T E S T S
-------------------------------------------------------
Running io.gdcc.spi.export.croissant.CroissantExporterTest
Tests run: 8, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.058 s -- in io.gdcc.spi.export.croissant.CroissantExporterTest

Results:

Tests run: 8, Failures: 0, Errors: 0, Skipped: 0

------------------------------------------------------------------------
BUILD SUCCESS
------------------------------------------------------------------------
Total time:  0.890 s
Finished at: 2024-08-06T16:42:13-04:00
------------------------------------------------------------------------
pdurbin commented 2 months ago

Oh, one more thing I should mention is that I sat down with @jp-tosca the other day to install VS Code. Test run fine there: Screenshot 2024-08-06 at 4 56 52 PM

mbien commented 2 months ago
Running NetBeans Compile On Save execution. Phase execution is skipped and output directories of dependency projects (with Compile on Save turned on) will be used instead of their jar artifacts.
Scanning for projects...

@pdurbin can you try to disable compile-on-save in the project settings and see if this helps?

pdurbin commented 2 months ago

@mbien interesting! Thanks! Did you see my email to the Netbeans mailing list? I keep checking the archive but I don't see it so I assumed it didn't go through.

I tried unchecking "Compile on Save" and it worked! Like in the old days (well, last year and before), I was able to hit Cmd-F6 and run tests. I'll put the output below in case it's useful or helpful.

I will say that in our docs on speeding up development by using hotswapping, we tell people to make sure "Compile on Save" is checked:

Screenshot 2024-08-07 at 10 25 11 AM

I just tried unchecking it and "Apply Code Changes" still works, though it takes an extra moment to compile.

In short, I'm going to try to code for a while with "Compile on Save" unchecked and see how the overal experience is. I'm definitely going to be glad to not have to switch to the command line to run tests!

I'm assuming I'll end up making a pull request to update the docs above to remove the recommendation to enable "Compile on Save". We'll see.

Thanks again!

Output from running a unit test with "Compile on Save" unchecked:

cd /Users/PDurbin/github/iqss/dataverse; JAVA_HOME=/Users/PDurbin/.sdkman/candidates/java/17.0.11-tem "/Applications/Apache NetBeans.app/Contents/Resources/netbeans/java/maven/bin/mvn" -Dtest=edu.harvard.iq.dataverse.util.json.JsonUtilTest --no-transfer-progress process-test-classes surefire:test
Scanning for projects...

----------------------< edu.harvard.iq:dataverse >----------------------
Building dataverse 6.3
  from pom.xml
--------------------------------[ war ]---------------------------------

--- enforcer:3.3.0:enforce (general-reqs) @ dataverse ---
Rule 0: org.apache.maven.enforcer.rules.BanDuplicatePomDependencyVersions passed
Rule 1: org.apache.maven.enforcer.rules.version.RequireJavaVersion passed

--- jacoco:0.8.11:prepare-agent (jacoco-initialize) @ dataverse ---
surefire.jacoco.args set to -javaagent:/Users/PDurbin/.m2/repository/org/jacoco/org.jacoco.agent/0.8.11/org.jacoco.agent-0.8.11-runtime.jar=destfile=/Users/PDurbin/github/iqss/dataverse/target/coverage-reports/jacoco-unit.exec,includes=edu/harvard/iq/dataverse/*:io/gdcc/*:org/dataverse/*

--- resources:3.3.1:resources (default-resources) @ dataverse ---
Copying 35 resources from src/main/java to target/classes
Copying 86 resources from src/main/resources to target/classes
Copying 2 resources from src/main/resources to target/classes
The encoding used to copy filtered properties files have not been set. This means that the same encoding will be used to copy filtered properties files as when copying other filtered resources. This might not be what you want! Run your build with --debug to see which files might be affected. Read more at https://maven.apache.org/plugins/maven-resources-plugin/examples/filtering-properties-files.html

--- compiler:3.11.0:compile (default-compile) @ dataverse ---
Nothing to compile - all classes are up to date

--- smallrye-open-api:3.10.0:generate-schema (default) @ dataverse ---
Wrote the schema files to /Users/PDurbin/github/iqss/dataverse/target/classes/META-INF

--- enforcer:3.3.0:enforce (no-junit4) @ dataverse ---
Rule 0: org.apache.maven.enforcer.rules.dependency.BannedDependencies passed

--- resources:3.3.1:testResources (default-testResources) @ dataverse ---
Copying 88 resources from src/test/resources to target/test-classes
Copying 5 resources from conf/keycloak to target/test-classes/keycloak

--- compiler:3.11.0:testCompile (default-testCompile) @ dataverse ---
Nothing to compile - all classes are up to date

--- surefire:3.2.5:test (default-cli) @ dataverse ---
Using auto detected provider org.apache.maven.surefire.junitplatform.JUnitPlatformProvider

-------------------------------------------------------
 T E S T S
-------------------------------------------------------
Running edu.harvard.iq.dataverse.util.json.JsonUtilTest
Aug 07, 2024 2:30:20 PM edu.harvard.iq.dataverse.util.json.JsonUtil prettyPrint
INFO: Returning original string due to exception: java.lang.NullPointerException: Cannot invoke "String.trim()" because "jsonString" is null
Aug 07, 2024 2:30:20 PM edu.harvard.iq.dataverse.util.json.JsonUtil prettyPrint
INFO: Returning original string due to exception: jakarta.json.stream.JsonParsingException: Invalid token=EOF at (line no=1, column no=0, offset=-1). Expected tokens are: [CURLYOPEN, SQUAREOPEN, STRING, NUMBER, TRUE, FALSE, NULL]
Aug 07, 2024 2:30:20 PM edu.harvard.iq.dataverse.util.json.JsonUtil prettyPrint
INFO: Returning original string due to exception: jakarta.json.stream.JsonParsingException: Unexpected char 106 at (line no=1, column no=1, offset=0)
Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.043 s -- in edu.harvard.iq.dataverse.util.json.JsonUtilTest

Results:

Tests run: 1, Failures: 0, Errors: 0, Skipped: 0

------------------------------------------------------------------------
BUILD SUCCESS
------------------------------------------------------------------------
Total time:  3.302 s
Finished at: 2024-08-07T10:30:20-04:00
------------------------------------------------------------------------
mbien commented 2 months ago

@mbien interesting! Thanks! Did you see my email to the Netbeans mailing list?

yep, thats why I am here :)

I tried unchecking "Compile on Save" and it worked!

good to know!

So, "CoS" is off by default these days, and if you switch it on you should see a scary looking warning dialog which points out some problems it can cause. It is a legacy feature from times when essentially everything was slow and it was thought that IDEs messing with the build output directly was an acceptable risk to take to speed up things (e.g for incremental compilations or during debugging).

But today, there are things like mvnd and everything uses NVMes instead of spinning disks etc - it doesn't really make sense anymore. If anything, a feature like this should be implemented in the build system (e.g maven) instead of IDEs.

There is also a communication issue here, since NB has on-save hooks for arbitrary actions. Those could in future automatically swap out changes during debug sessions for example without having to press a button - but many don't know that this doesn't require the fairly invasive CoS feature.

We are probably going to end up phasing it out at some point. (cc @neilcsmith-net).

I'm assuming I'll end up making a pull request to update the docs above to remove the recommendation to enable "Compile on Save". We'll see.

that would be great. A lot of the doc needs updates. Its an old IDE with a lot of text written about it. Anything what recommends CoS should be removed IMO.