Tests in a maven project do not run with Netbeans but run fine with Eclipse. maven-surefire-plugin - eclipse

so essentially I have a big maven project. When I open it in netbeans, strangely if I add any new junit test class or even if I rename existing test classes I cannot run any of them using "Test File", but old test classes run fine. I receive a message:
Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.14.1:test (default-cli) on project sga: No tests were executed! (Set -DfailIfNoTests=false to ignore this error.) -> [Help 1]
Strangely, if I open the same project with Eclipse, all new and renamed classes run fine without errors with "Run As JUnit".
Could help me to make the new tests run in netbeans? Thank you

Related

Maven dependencies are downloaded but eclipse won't resolve them

A multi-module maven project will be buit successfully from the command line using mvn clean install and is loaded successfully in vscode without any compilation errors.
When the same project is opened in Eclipse (version Version: 2022-09 (4.25.0), Build id: 20220908-1902), I see compilation errors for dependencies not resolved for example:
The import com.ibm cannot be resolved
I tried everything to resolve this error, nothing worked, for example:
Update maven project
Project / Clean
Remove maven feature, delete the project, reimport, and convert back to maven
The strange thing is that if I delete the repository folder from <user-home>\m2.\repository and make a simple change to any pom.xml file, the entire repository folder is downloaded. Also, I located the JAR file using VSCode (ctrl-click) and I can see the related JAR logEnglish-1.0.jar in the local .m2 repository folder <user-home>\.m2\repository\logEnglish\logEnglish\1.0\logEnglish-1.0.jar.
The problem is that only Eclipse is reporting compilation errors and a lot or maybe all of the maven dependencies are not resolved. This is also affecting the debugging option and it breaks due to such compilation errors.
Another thing I noticed is that the Maven Dependencies folder is not showing on the Project Explorer no in Package Explorer, but I can see Maven Dependencies entry in Project Properties -> Configure Build Path -> Libraries.
Please help resolve this issue so that I can clear the compilation errors in Eclipse.
Update 1:
I created a simple parent/child pom with one inner module. I was able to reproduce the problem right away.
See attached snapshots for details.
The compile errors will show only when you open the parent project. If you open the inner module directly as a separate project, no compile errors will show and I can run and debug the project. However, if I try to debug the parent project, I will get a warning due to compile errors, and I can run the project only and only after I added the jar of the inner module to the classpath of the debug configuration. If I don't add the jar file, I will get this error Error: Could not find or load main class training.FirstProjectClass. The project is being built successfully using mvn clean install and that's why I can run the project. If I run mvn clean then I cannot run the parent project.
Also, notice how the maven dependencies folder will show if you open the inner project directly, but, it won't show if you open the parent project.
In addition, I noticed if I add the inner project to the classpath of the debug config then it works also without building the project and without generating the jar file using mvn clean install.
Based on the above, the problem boils down to:
How we can resolve the dependencies of the inner modules when you open the project using the parent maven project?
If we can resolve the errors, then we can run without seeing the warning, and we have the assurance that the project is clear before running the mvn clean install command.

Cannot "Run as JUnit Plug-in test" on test plugin/package (JUnit5)

I'm trying to add JUnit5 support in my Eclipse RCP application. It almost works, because for now I can:
Use Maven to build whole application and run tests with Tycho
Run single JUnit5 tests (creating run configuration on specific class) in
Eclipse
Run single JUnit5 tests in Run as JUnit Plug-in test mode in Eclipse
Run multiple JUnit5 tests in Run as JUnit test mode in Eclipse
What I'm trying to achieve now is to be able to run whole sets of test classes in plug-in test mode. For JUnit4-based plug-ins I could simply right-click on whole package or even whole plug-in and invoke Run As -> JUnit Plug-in test.
When I do the same operation on JUnit5 tests I get an error: No tests found with test runner 'JUnit 5'.
My current configuration for such plug-ins looks as follows:
According to official instructions in MANIFEST.FM I have Import-Package dependencies:
org.junit.jupiter.api,
org.junit.jupiter.params,
org.junit.jupiter.params.provider
and org.junit as Require-Bundle dependency
In order to run tests in Eclipse IDE I've also added JUnit 5 library to Java Build Path of the plugin. I coudn't add JUnit 5 runner dependencies to MANIFEST.FM instead, because of conflict with Tycho.

How to run all scalatest of a multi-modules sbt with intellij?

I can run:
a specific scala test
either by right clicking on the test and choose run
or if I have run it once previously, by selecting the test in run menu > run...
I can run all junit tests by making a new run/debug configuration > + > junit > test kind = all in package > search for tests = in whole project
I can run all scalatest (or junit) of one sub-project: right click on the project > run > scalatest in [module name]
But if I do the same as (2) with a scala test (+ > scala test > test kind...) the first test fails very strangely (it seems an object is not instantiated) while the same test pass if I run it using (1) or (3)
Config:
sbt with multiple subproject
intellij CE 15.0.2
scala plugin 2.1.0
scala 2.10
Bonus question: how to run all tests (junit and scalatest)?
You should be able to right click on the root directory of the project and click Run "All Tests". This recursively searches for tests in your project, and will run the tests in each module.

Eclipse NoClassDefFoundError when running Elasticsearch JUnit tests

I am trying to run some Unit Tests written for a Mavenized project in Eclipse. The tests run perfectly fine from the command line. They also run perfectly fine if I open up Eclipse and run the tests directly off the POM file (i.e. right click on pom.xml and say run maven tests or whatever).
However, I get the following error when I run the tests as JUnit tests in Eclipse:
java.lang.NoClassDefFoundError: Could not initialize class org.elasticsearch.test.ESIntegTestCase
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:340)
at com.carrotsearch.randomizedtesting.RandomizedRunner$1.run(RandomizedRunner.java:562)
I am using Elasticsearch version 2.1.0. The elasticsearch-2.1.0-tests.jar that contains org.elasticsearch.test.ESIntegTestCase is listed as a dependency in pom.xml and all Maven Dependencies show up in my Eclipse project's build path. I even tried specifically adding the jar to my buildpath and to the run configuration's classpath in Eclipse. Both do not work. Cleaning my project via Project -> Clean... also does not work.

m2eclipse: Like "mvn test" but with GUI?

We have a multi-module Maven setup with a master pom.xml that includes all the others. So mvn test from the root directory runs all our unit tests, with textual output.
I can do Run / Run As / JUnit Test to run a single test class with a graphical test runner.
Question: How do I combine the two, so that I can run all the tests that mvn test runs but with a graphical runner, like the one from Run / Run As / JUnit Test?
Create an eclipse project with all your modules as Maven Dependecies and then create a JUnit Suite which incorporates all tests. Eclipse's JUnit Runner then will execute all declared Tests if you run this suite.
In Eclipse Juno, assuming your project is a Maven Project, you can just right click the project name in the Project Explorer and select Run As ... jUnit test. Alternatively you can produce the same text output you get from mvn test by selecting Run As ... Maven test