Why is Eclipse trying to use JUnit5 when it should use JUnit4? - eclipse

I'm just going through a tutorial which is a Maven project in Eclipse, and it should run some tests using JUnit4, so I have put this dependency in the POM:
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13</version>
<scope>test</scope>
</dependency>
Still, trying to run the tests I get the following:
No tests found with testrunner 'JUnit5'
Why is Eclipse not using JUnit4 when this is the only dependency given in the project?

Because in the run configuration you have chosen JUnit 4 as Test Runner, Eclipse uses JUnit 4 instead of JUnit 5 to run this test.
Please note that even though Eclipse preselects the matching Test Runner for new run configurations, it does not change the Test Runner for existing run configurations.

Related

Scala unit test in a maven project with IntelliJ

I have a scala project with maven as build tool, and I am using IntelliJ IDE.
What is the ideal folder structure for tests in this case? And what testing library should I use?
What is the ideal folder structure for tests in this case?
In this documentation, checkout this section - Explaining this Archetype
It tells you the ideal folder structure for tests.
what testing library should I use?
I think scalatest is a great testing tool for scala. You can add the following dependency in your pom.xml or checkout this link.
<!-- https://mvnrepository.com/artifact/org.scalatest/scalatest -->
<dependency>
<groupId>org.scalatest</groupId>
<artifactId>scalatest_2.13</artifactId>
<version>3.1.1</version>
<scope>test</scope>
</dependency>
Let me know if it helps!!

Maven test finds but not executes tests

I have some test-classes under the folder src/test/java (some of these having name ending by *Test). Each class has some methods annotated with #Test
Running these tests with JUnit (on Eclipse, right click on the class, then run as, the JUnit Test) I have no problems. But I want to run these tests using mvn test.
The problem is that I obtain always this:
It seems that mvn finds the tests, but it doesn't execute them. Why?
Furthermore, it seems that also classes having a name that doesn't end with *Test are considered by Maven.
This is part of my pom.xml:
And this is part of my effective pom:
You are using a very outdated version of JUnit.
In JUnit 3.x, tests did not use annotations; the method names had to start with test*.
In JUnit 4.x, test methods had to be annotated with #Test, which is what you apparently have.
In your pom, you need to upgrade JUnit:
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>

eclipse buildpath error with maven dependency

In my pom.xml i have the following dependency
<dependency>
<groupId>org.codehaus.woodstox</groupId>
<artifactId>wstx-asl</artifactId>
<version>3.2.8</version>
</dependency>
My eclipse download the jar file as expected and my code compiles just fine. But when i execute my JUnit tests i'm gettin a exception wich is the cenario expected for when the dependency is missing.
If i change the dependency to
<dependency>
<groupId>org.codehaus.woodstox</groupId>
<artifactId>wstx-asl</artifactId>
<version>3.2.8</version>
<scope>system</scope>
<systemPath>\path\to\wstx-asl-3.2.8.jar</systemPath>
</dependency>
the issue persists. But when i remove the dependency from the pom.xml and add it to the builpath using the standard eclipse way everything works just fine.
Executing a mvn package the tests are executed just fine. Only when i run them in the eclipse envirionment that the issue occurs.
what am i missing here?
Eclipse has a separate build path. When using maven projects within Eclipse you need to rebuild the build path that Eclipse uses to point to the downloaded Maven artifacts.
You do this by running mvn eclipse:eclipse on your project and then clean and build your project from within eclipse.
This Maven plugin rebuilds your .classpath file within your project, this file stores your build path.
See: http://maven.apache.org/plugins/maven-eclipse-plugin/eclipse-mojo.html

Eclipse m2eclipse not picking up "provided" transitive dependencies

Trying to get Roboguice working in Eclipse which contains 2 Maven projects, Astroboy and Roboguice (let's call them A and B where A depends on B). My problem is that unit tests in A which work fine in Maven give compile errors in Eclipse because it can't find Junit. Junit is declared in A's pom as a provided dependency, as below. I did tell Eclipse that project A depends on B by adding B to A's build path/projects.
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.8.2</version>
<scope>provided</scope>
</dependency>
I got it to work temporarily by changing the scope to test (then doing a mvn install and maven/update project on A), but what must I do to have it find Junit by itself?

NetBeans and the Invisible jUnit Library

I installed jUnit using the normal NetBeans installer but when I try to open a project that uses jUnit, I get a dialog box that says I have to resolve missing references. In addition, when I tried to find the jUnit library, I noticed that it wasn't in the list of libraries.
I have already tried installing the NetBeans jUnit plugin.
What must I do to get jUnit working?
Context:
Windows 7 SP1 64-bit edition
NetBeans 7.2
Depends on the Project type you are using.
Ant:
Right click on on the Libraries folder and select Add Library....
A new window will appear where you can choose a JUnit version to add.
Maven:
Open Project Files/pom.xml.
Declare a JUnit dependency like that:
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.10</version>
<scope>test</scope>
</dependency>
</dependencies>