Maven Surefire not running JUnit 5 tests - java

I've been trying to run JUnit 5 tests with Maven Surefire. However, it doesn't seem like Surefire is running any tests at all, even though I do have some, and in the default directory, too.
This is the console output I'm getting: https://prnt.sc/ugo1xt
Here are the relevant parts of the pom.xml:
<dependencies>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<version>5.7.0-M1</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>${maven-surefire-plugin.version}</version>
</plugin>
</plugins>
</build>
The surefire version is 3.0.0-M4.
I've tried pretty much any fix I could find on Google, although most of them seemed to be outdated. Any help would be greatly appreciated.
Cheers!
EDIT: Here's an example of my tests:
package bankprojekt;
import bankprojekt.verarbeitung.*;
import org.junit.jupiter.api.*;
import static org.junit.jupiter.api.Assertions.*;
public class GirokontoTest {
Girokonto gk;
#BeforeEach
void setup(){
gk = new Girokonto();
gk.einzahlen(500);
}
#AfterEach
void teardown(){
gk = null;
}
#Test
void abhebenMitWaehrungswechsel(){
try{
gk.abheben(195.583, Waehrung.BGN);
}
catch (Exception e) {
System.out.println(e);
}
assertEquals(400, gk.getKontostand());
}
#Test
void einzahlenMitWaehrungswechsel(){
gk.einzahlen(195.583, Waehrung.BGN);
assertEquals(600, gk.getKontostand());
}
}

There are two things. First you should upgrade jacoco dependency to 0.8.5 otherwise it fails based on the JDK14 requirement. (Created an pull request to your repository). If those things are configured appropriately the result is this:
I would also recommend to upgrade maven-compiler-plugin to most recent version and also all other plugins.
As you can see you have WARNING's in your build which should be fixed and failing tests.
This build has been run on plain command line also with JUnit-Jupiter 5.7.0 which works perfectly.
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) # prog3-sose2020 ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 9 source files to /Users/khmarbaise/ws-git-so/prog3-sose2020/target/classes
[WARNING] /Users/khmarbaise/ws-git-so/prog3-sose2020/src/main/java/bankprojekt/verarbeitung/Kunde.java: /Users/khmarbaise/ws-git-so/prog3-sose2020/src/main/java/bankprojekt/verarbeitung/Kunde.java uses or overrides a deprecated API.
[WARNING] /Users/khmarbaise/ws-git-so/prog3-sose2020/src/main/java/bankprojekt/verarbeitung/Kunde.java: Recompile with -Xlint:deprecation for details.
[INFO]
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) # prog3-sose2020 ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory /Users/khmarbaise/ws-git-so/prog3-sose2020/src/test/resources
[INFO]
[INFO] --- maven-compiler-plugin:3.1:testCompile (default-testCompile) # prog3-sose2020 ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 3 source files to /Users/khmarbaise/ws-git-so/prog3-sose2020/target/test-classes
[INFO]
[INFO] --- maven-surefire-plugin:3.0.0-M4:test (default-test) # prog3-sose2020 ---
[INFO]
[INFO] -------------------------------------------------------
[INFO] T E S T S
[INFO] -------------------------------------------------------
[INFO] Running bankprojekt.GirokontoTest
[ERROR] Tests run: 2, Failures: 1, Errors: 0, Skipped: 0, Time elapsed: 0.087 s <<< FAILURE! - in bankprojekt.GirokontoTest
[ERROR] bankprojekt.GirokontoTest.abhebenMitWaehrungswechsel Time elapsed: 0.052 s <<< FAILURE!
org.opentest4j.AssertionFailedError: expected: <448.87081188037814> but was: <400.0>
at bankprojekt.GirokontoTest.abhebenMitWaehrungswechsel(GirokontoTest.java:31)
[INFO] Running bankprojekt.WaehrungTest
[INFO] Tests run: 3, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.005 s - in bankprojekt.WaehrungTest
Kunde Mustermann, Max zerst�rt
[INFO]
[INFO] Results:
[INFO]
[ERROR] Failures:
[ERROR] GirokontoTest.abhebenMitWaehrungswechsel:31 expected: <448.87081188037814> but was: <400.0>
[INFO]
[ERROR] Tests run: 5, Failures: 1, Errors: 0, Skipped: 0
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 3.792 s
[INFO] Finished at: 2020-09-14T17:50:43+02:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:3.0.0-M4:test (default-test) on project prog3-sose2020: There are test failures.
[ERROR]
[ERROR] Please refer to /Users/khmarbaise/ws-git-so/prog3-sose2020/target/surefire-reports for the individual test results.
[ERROR] Please refer to dump files (if any exist) [date].dump, [date]-jvmRun[N].dump and [date].dumpstream.
[ERROR] -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.

Related

Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.0:compile (default-compile) on project Eclipse

--- maven-clean-plugin:3.1.0:clean (default-clean) # Homework5 ---
[INFO]
[INFO] --- maven-resources-plugin:3.0.2:resources (default-resources) # Homework5 ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory /Users/vintage/eclipse-workspace/Homework5/src/main/resources
[INFO]
[INFO] --- maven-compiler-plugin:3.8.0:compile (default-compile) # Homework5 ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 3 source files to /Users/vintage/eclipse-workspace/Homework5/target/classes
[INFO] -------------------------------------------------------------
[ERROR] COMPILATION ERROR :
[INFO] -------------------------------------------------------------
[ERROR] No compiler is provided in this environment. Perhaps you are running on a JRE rather than a JDK?
[INFO] 1 error
[INFO] -------------------------------------------------------------
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 2.281 s
[INFO] Finished at: 2022-03-19T00:14:48-04:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.0:compile (default-compile) on project Homework5: Compilation failure
[ERROR] No compiler is provided in this environment. Perhaps you are running on a JRE rather than a JDK?
[ERROR] -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException
Unable to run my code for a homework assignment. It says that " No compiler is provided in this environment. Perhaps you are running on a JRE rather than a JDK" but I'm unsure on how to fix that issue.
Running Mac OSX Monterey 12.2
Eclipse IDE 2022-03
Tomcat Apache 9

Deploy to sonatype nexus repo failing with missing resources

I've just dusted off an old project I was working on a year ago and am trying to deploy a fix to the Sonatpye Nexus repo but keep hitting rule failures I don't understand. This is a Maven project developed in IntelliJ IDE.
My errors are:
[ERROR] Nexus Staging Rules Failure Report
[ERROR] ==================================
[ERROR]
[ERROR] Repository "comgithubmuseadmin-1055" failures
[ERROR] Rule "sources-staging" failures
[ERROR] * Missing: no sources jar found in folder '/com/github/museadmin/infinite-state-machine/1.1.9'
[ERROR] Rule "javadoc-staging" failures
[ERROR] * Missing: no javadoc jar found in folder '/com/github/museadmin/infinite-state-machine/1.1.9'
[ERROR] Rule "signature-staging" failures
[ERROR] * Missing Signature: '/com/github/museadmin/infinite-state-machine/1.1.9/infinite-state-machine-1.1.9.jar.asc' does not exist for 'infinite-state-machine-1.1.9.jar'.
[ERROR] * Missing Signature: '/com/github/museadmin/infinite-state-machine/1.1.9/infinite-state-machine-1.1.9.pom.asc' does not exist for 'infinite-state-machine-1.1.9.pom'.
I'm assuming the /com/xxx path it's referring to is under my .m2 directory, as it doesn't exist in the project. But the contents of that directory under /Users/atkinsb/.m2/repository/com/github/museadmin/infinite-state-machine/1.1.9 are:
Bradleys-MacBook-Pro:1.1.9 atkinsb$ ll
total 624
-rw-r--r-- 1 atkinsb staff 461 3 Apr 16:31 _remote.repositories
-rw-r--r-- 1 atkinsb staff 40624 3 Apr 13:53 infinite-state-machine-1.1.9-javadoc.jar
-rw-r--r-- 1 atkinsb staff 473 3 Apr 13:54 infinite-state-machine-1.1.9-javadoc.jar.asc
-rw-r--r-- 1 atkinsb staff 121951 3 Apr 13:53 infinite-state-machine-1.1.9-sources.jar
-rw-r--r-- 1 atkinsb staff 473 3 Apr 13:54 infinite-state-machine-1.1.9-sources.jar.asc
-rw-r--r-- 1 atkinsb staff 123349 3 Apr 16:29 infinite-state-machine-1.1.9.jar
-rw-r--r-- 1 atkinsb staff 473 3 Apr 13:53 infinite-state-machine-1.1.9.jar.asc
-rw-r--r-- 1 atkinsb staff 3360 3 Apr 13:35 infinite-state-machine-1.1.9.pom
-rw-r--r-- 1 atkinsb staff 473 3 Apr 13:53 infinite-state-machine-1.1.9.pom.asc
Before I go on to look at the signature errors, I'd like to understand why it is complaining about no sources or java docs jars when it looks like they are there.
Any Java wizards able to enlighten me as to what I'm doing wrong?
Cheers
Brad
PS My settings.xml:
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd">
<profiles>
<profile>
<id>ossrh</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<properties>
<gpg.executable>gpg</gpg.executable>
<gpg.passphrase>xxxxxxxxxx</gpg.passphrase>
</properties>
</profile>
</profiles>
<servers>
<server>
<id>ossrh</id>
<username>steadyonabix</username>
<password>xxxxxxx</password>
</server>
</servers>
</settings>
This is the full log output:
Bradleys-MacBook-Pro:infinite-state-machine atkinsb$ mvn deploy
[INFO] Scanning for projects...
[INFO] Inspecting build with total of 1 modules...
[INFO] Installing Nexus Staging features:
[INFO] ... total of 1 executions of maven-deploy-plugin replaced with nexus-staging-maven-plugin
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building com.github.museadmin:infinite-state-machine 1.1.9
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) # infinite-state-machine ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 7 resources
[INFO]
[INFO] --- maven-compiler-plugin:3.7.0:compile (default-compile) # infinite-state-machine ---
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) # infinite-state-machine ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory /Users/atkinsb/GitRepos/infinite-state-machine/src/test/resources
[INFO]
[INFO] --- maven-compiler-plugin:3.7.0:testCompile (default-testCompile) # infinite-state-machine ---
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] --- maven-surefire-plugin:2.12.4:test (default-test) # infinite-state-machine ---
[INFO] Surefire report directory: /Users/atkinsb/GitRepos/infinite-state-machine/target/surefire-reports
-------------------------------------------------------
T E S T S
-------------------------------------------------------
Running com.github.museadmin.infinite_state_machine.unit.tests.core.TestMessagingFramework
SLF4J: No SLF4J providers were found.
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#noProviders for further details.
SLF4J: Class path contains SLF4J bindings targeting slf4j-api versions prior to 1.8.
SLF4J: Ignoring binding found at [jar:file:/Users/atkinsb/.m2/repository/ch/qos/logback/logback-classic/1.1.2/logback-classic-1.1.2.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: See http://www.slf4j.org/codes.html#ignoredBindings for an explanation.
Tests run: 2, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 7.173 sec
Running com.github.museadmin.infinite_state_machine.unit.tests.core.TestInfiniteStateMachine
NO ACTIONS IMPORTED
Tests run: 3, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 2.073 sec
Running com.github.museadmin.infinite_state_machine.unit.tests.core.TestPropertyCache
Tests run: 3, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0 sec
Results :
Tests run: 8, Failures: 0, Errors: 0, Skipped: 0
[INFO]
[INFO] --- maven-jar-plugin:2.4:jar (default-jar) # infinite-state-machine ---
[INFO]
[INFO] --- maven-install-plugin:2.4:install (default-install) # infinite-state-machine ---
[INFO] Installing /Users/atkinsb/GitRepos/infinite-state-machine/target/infinite-state-machine-1.1.9.jar to /Users/atkinsb/.m2/repository/com/github/museadmin/infinite-state-machine/1.1.9/infinite-state-machine-1.1.9.jar
[INFO] Installing /Users/atkinsb/GitRepos/infinite-state-machine/pom.xml to /Users/atkinsb/.m2/repository/com/github/museadmin/infinite-state-machine/1.1.9/infinite-state-machine-1.1.9.pom
[INFO]
[INFO] --- nexus-staging-maven-plugin:1.6.8:deploy (injected-nexus-deploy) # infinite-state-machine ---
[INFO] Performing local staging (local stagingDirectory="/Users/atkinsb/GitRepos/infinite-state-machine/target/nexus-staging/staging")...
[INFO] + Using server credentials "ossrh" from Maven settings.
[INFO] * Connected to Nexus at https://oss.sonatype.org:443/, is version 2.14.16-01 and edition "Professional"
[INFO] * Using staging profile ID "5958335c79f727" (matched by Nexus).
[INFO] Installing /Users/atkinsb/GitRepos/infinite-state-machine/target/infinite-state-machine-1.1.9.jar to /Users/atkinsb/GitRepos/infinite-state-machine/target/nexus-staging/staging/5958335c79f727/com/github/museadmin/infinite-state-machine/1.1.9/infinite-state-machine-1.1.9.jar
[INFO] Installing /Users/atkinsb/GitRepos/infinite-state-machine/pom.xml to /Users/atkinsb/GitRepos/infinite-state-machine/target/nexus-staging/staging/5958335c79f727/com/github/museadmin/infinite-state-machine/1.1.9/infinite-state-machine-1.1.9.pom
[INFO] Performing remote staging...
[INFO]
[INFO] * Remote staging into staging profile ID "5958335c79f727"
[INFO] * Created staging repository with ID "comgithubmuseadmin-1058".
[INFO] * Staging repository at https://oss.sonatype.org:443/service/local/staging/deployByRepositoryId/comgithubmuseadmin-1058
[INFO] * Uploading locally staged artifacts to profile com.github.museadmin
Uploading: https://oss.sonatype.org:443/service/local/staging/deployByRepositoryId/comgithubmuseadmin-1058/com/github/museadmin/infinite-state-machine/1.1.9/infinite-state-machine-1.1.9.jar
Uploaded: https://oss.sonatype.org:443/service/local/staging/deployByRepositoryId/comgithubmuseadmin-1058/com/github/museadmin/infinite-state-machine/1.1.9/infinite-state-machine-1.1.9.jar (121 KB at 94.4 KB/sec)
Uploading: https://oss.sonatype.org:443/service/local/staging/deployByRepositoryId/comgithubmuseadmin-1058/com/github/museadmin/infinite-state-machine/1.1.9/infinite-state-machine-1.1.9.pom
Uploaded: https://oss.sonatype.org:443/service/local/staging/deployByRepositoryId/comgithubmuseadmin-1058/com/github/museadmin/infinite-state-machine/1.1.9/infinite-state-machine-1.1.9.pom (4 KB at 8.3 KB/sec)
Downloading: https://oss.sonatype.org:443/service/local/staging/deployByRepositoryId/comgithubmuseadmin-1058/com/github/museadmin/infinite-state-machine/maven-metadata.xml
Uploading: https://oss.sonatype.org:443/service/local/staging/deployByRepositoryId/comgithubmuseadmin-1058/com/github/museadmin/infinite-state-machine/maven-metadata.xml
Uploaded: https://oss.sonatype.org:443/service/local/staging/deployByRepositoryId/comgithubmuseadmin-1058/com/github/museadmin/infinite-state-machine/maven-metadata.xml (322 B at 0.5 KB/sec)
[INFO] * Upload of locally staged artifacts finished.
[INFO] * Closing staging repository with ID "comgithubmuseadmin-1058".
Waiting for operation to complete...
......
[ERROR] Rule failure while trying to close staging repository with ID "comgithubmuseadmin-1058".
[ERROR]
[ERROR] Nexus Staging Rules Failure Report
[ERROR] ==================================
[ERROR]
[ERROR] Repository "comgithubmuseadmin-1058" failures
[ERROR] Rule "javadoc-staging" failures
[ERROR] * Missing: no javadoc jar found in folder '/com/github/museadmin/infinite-state-machine/1.1.9'
[ERROR] Rule "sources-staging" failures
[ERROR] * Missing: no sources jar found in folder '/com/github/museadmin/infinite-state-machine/1.1.9'
[ERROR] Rule "signature-staging" failures
[ERROR] * Missing Signature: '/com/github/museadmin/infinite-state-machine/1.1.9/infinite-state-machine-1.1.9.jar.asc' does not exist for 'infinite-state-machine-1.1.9.jar'.
[ERROR] * Missing Signature: '/com/github/museadmin/infinite-state-machine/1.1.9/infinite-state-machine-1.1.9.pom.asc' does not exist for 'infinite-state-machine-1.1.9.pom'.
[ERROR]
[ERROR]
[ERROR] Cleaning up local stage directory after a Rule failure during close of staging repositories: [comgithubmuseadmin-1058]
[ERROR] * Deleting context 5958335c79f727.properties
[ERROR] Cleaning up remote stage repositories after a Rule failure during close of staging repositories: [comgithubmuseadmin-1058]
[ERROR] * Dropping failed staging repository with ID "comgithubmuseadmin-1058" (Rule failure during close of staging repositories: [comgithubmuseadmin-1058]).
Waiting for operation to complete...
...
[ERROR] Remote staging finished with a failure: Staging rules failure!
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 55.331 s
[INFO] Finished at: 2020-04-03T19:12:13+01:00
[INFO] Final Memory: 31M/340M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.sonatype.plugins:nexus-staging-maven-plugin:1.6.8:deploy (injected-nexus-deploy) on project infinite-state-machine: Remote staging failed: Staging rules failure! -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException
By the way, I've just deleted the project under my .m2 directory ad done another man install and man javadoc:jar but the javadoc jar hasn't been replaced there.
Finally! What a frustrating day.
I discovered some old notes I had set aside and found that adding this profile to the command line worked. Still not sure why ...
mvn clean deploy -Pdeploy
Thanks for the help folks.

Jenkins Non-readable POM

This error is posted in different forums even here. I have tried the different alternatives. I tried changing the POM permissions. I am using the default maven settings. JDK is 8, Maven 3.5.3.
I just want to try a very simple junit application. From the command line I have no problems running "mvn test"
junitexample amh$ mvn test
[INFO] Scanning for projects...
[INFO]
[INFO] ----------------------< com.junit:junit-example >-----------------------
[INFO] Building junit-example 1.0-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) # junit-example ---
[WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] Copying 0 resource
[INFO]
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) # junit-example ---
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) # junit-example ---
[WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] skip non existing resourceDirectory /Users/amhg/Documents/dev/intellik2/junitexample/src/test/resources
[INFO]
[INFO] --- maven-compiler-plugin:3.1:testCompile (default-testCompile) # junit-example ---
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] --- maven-surefire-plugin:2.12.4:test (default-test) # junit-example ---
[INFO] Surefire report directory: /Users/amhg/Documents/dev/intellik2/junitexample/target/surefire-reports
-------------------------------------------------------
T E S T S
-------------------------------------------------------
Running CalculatorTest
Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.045 sec
Results :
Tests run: 1, Failures: 0, Errors: 0, Skipped: 0
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1.178 s
[INFO] Finished at: 2018-04-08T01:39:52+02:00
[INFO] ------------------------------------------------------------------------
But from Jenkins, from the Console Output I have this error:
Console Output
Started by user Andrea
Building in workspace /Users/Shared/Jenkins/Home/workspace/calc
[calc] $ /Users/amhg/apache-maven-3.5.3/bin/mvn -f /Users/amhg/Documents/dev/intellik2/junitexample test
POM file /Users/amhg/Documents/dev/intellik2/junitexample specified with the -f/--file command line argument does not exist
[INFO] Scanning for projects...
[ERROR] [ERROR] Some problems were encountered while processing the POMs:
[FATAL] Non-readable POM /Users/amhg/Documents/dev/intellik2/junitexample: /Users/amhg/Documents/dev/intellik2/junitexample (Permission denied) #
#
[ERROR] The build could not read 1 project -> [Help 1]
[ERROR]
[ERROR] The project (/Users/amhg/Documents/dev/intellik2/junitexample) has 1 error
[ERROR] Non-readable POM /Users/amhg/Documents/dev/intellik2/junitexample: /Users/amhg/Documents/dev/intellik2/junitexample (Permission denied)
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/ProjectBuildingException
Build step 'Invoke top-level Maven targets' marked build as failure
Finished: FAILURE
This is my POM file
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.junit</groupId>
<artifactId>junit-example</artifactId>
<packaging>jar</packaging>
<version>1.0-SNAPSHOT</version>
<name>junit-example</name>
<url>http://maven.apache.org</url>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
And I just have a simple test:
import org.junit.BeforeClass;
import org.junit.Test;
import static junit.framework.TestCase.assertEquals;
public class CalculatorTest {
private static ICalculator calculator;
#BeforeClass
public static void initCalculator() {
calculator = new Calculator();
}
#Test
public void testSum() {
int result = calculator.sum(3, 4);
assertEquals(7, result);
}
}
I don´t know what else I could try. I opened all the topics related to the problem.
Any other suggestion?
I had exact same problem - local maven build works and Jenkins fails with the same error as yours.
Once Jenkins job is started, it will import source code to /your-jenkins/workspace/your-job-name folder and then start building. In your DSL, you have to mention the path to your pom in the workspace.
Take a look at the Jenkins workspace view to see where your pom is located once the source code is downloaded. This will aid in resolving the problem.
in the -f option you have provided. the maven is unable to identify the pom to read
-f /Users/amhg/Documents/dev/intellik2/junitexample test
try giving in the complete name of the pom including .xml
-f /Users/amhg/Documents/dev/intellik2/junitexample nameofpom.xml
Please check what you have in your Jenkins Build -> Goals and in your Build -> POM.
You probably switched those two.

Maven won't run tests from parent or child projects

I got a multi-module project. Each project has its own unittest same for the parent project. When I use mvn test no tests are run and the target folder does not contain any test classes. Parent project doesn't even create a target folder
Structure looks like this:
|-module1-> pom.xml
|-module2-> pom.xml
|-module3-> pom.xml
|-src/main
|-src/test/java/MyTest.java
|-pom.xml
See poms below ( I omited standard pom boilerplate)
parent pom.xml
<groupId>com.tests</groupId>
<artifactId>unit-tests</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>pom</packaging>
<modules>
<module>module1</module>
<module>module2</module>
<module>module3</module>
</modules>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
<version>RELEASE</version>
</dependency>
<dependencies>
Child pom has:
<parent>
<groupId>com.tests</groupId>
<artifactId>unit-tests</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>
Whenever i run mvn clean test no tests are run and in the console i get something like:
[INFO] ------------------------------------------------------------------------
[INFO] Building unit-tests 1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] ------------------------------------------------------------------------
Btw, parent project does not have any source code, just tests
You're using packaging pom. With that kind of packaging you're only allowed to run a small number of goals bound to phases (like install and deploy). In order to run the tests in the parent you must be explicit about your intentions, like this:
$mvn clean compiler:testCompile surefire:test
[INFO] -------------------------------------------------------
[INFO] T E S T S
[INFO] -------------------------------------------------------
[INFO] Running com.tests.unit_tests.TestModules
Test1!
[ERROR] Tests run: 1, Failures: 1, Errors: 0, Skipped: 0, Time elapsed: 0.016 s <<< FAILURE! - in com.tests.unit_tests.TestModules
[ERROR] test1(com.tests.unit_tests.TestModules) Time elapsed: 0.003 s <<< FAILURE!
java.lang.AssertionError
at com.tests.unit_tests.TestModules.test1(TestModules.java:11)
[INFO]
[INFO] Results:
[INFO]
[ERROR] Failures:
[ERROR] TestModules.test1:11
[INFO]
[ERROR] Tests run: 1, Failures: 1, Errors: 0, Skipped: 0
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Summary:
[INFO]
[INFO] unit-tests ......................................... FAILURE [ 1.262 s]
[INFO] module1 ............................................ SKIPPED
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1.473 s
[INFO] Finished at: 2017-12-02T11:04:50-02:00
[INFO] Final Memory: 16M/207M
[INFO] ------------------------------------------------------------------------
That way you are telling maven that you want to compile (generate your target) and run your tests in the aggregator (which has the parent pom). Otherwise maven will only run the tests in the modules.
$mvn test
[INFO] Scanning for projects...
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Build Order:
[INFO]
[INFO] unit-tests
[INFO] module1
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building unit-tests 1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building module1 1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) # module1 ---
[WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] Copying 0 resource
[INFO]
[INFO] --- maven-compiler-plugin:3.2:compile (default-compile) # module1 ---
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) # module1 ---
[WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] Copying 0 resource
[INFO]
[INFO] --- maven-compiler-plugin:3.2:testCompile (default-testCompile) # module1 ---
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] --- maven-surefire-plugin:2.17:test (default-test) # module1 ---
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Summary:
[INFO]
[INFO] unit-tests ......................................... SUCCESS [ 0.002 s]
[INFO] module1 ............................................ SUCCESS [ 0.424 s]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 0.504 s
[INFO] Finished at: 2017-12-02T11:06:24-02:00
[INFO] Final Memory: 9M/241M
[INFO] ------------------------------------------------------------------------
I know that it is a hard reading, but you should check it out:
http://maven.apache.org/guides/introduction/introduction-to-the-lifecycle.html#Packaging
For example, a project that is purely metadata (packaging value is
pom) only binds goals to the install and deploy phases (for a complete
list of goal-to-build-phase bindings of some of the packaging types,
refer to the Lifecycle Reference).
EDIT
As eis pointed out. Even though it's possible to do it, maven made it hard to do it because you SHOULDN't do it by default. Your unit tests should be in the module they are testing. It's not a good practice to scatter them.
The answer is: you can do it, yes. But you shouldn't! There are somethings in life that you can do, but shouldn't...
If we were talking about integration tests that would be a different story.. That's a different discussion.
Cheers!
The maven surefire plugin runs all JUnit Test where the name of the testclass ends with Test - with a capital 'T'. According to your info your test class is named Mytest. Refactor that class to be named MyTest will make it work.
multimodule parent has the packaging pom, and as such, can by definition only contain the pom, not any source code (not even test source code!). This is the reason your tests won't run and you don't get a target folder: there cannot be anything to run or compile on a project of type pom. A multimodule parent is only meant to group the modules together.

How to prevent building if integration test was failed?

I've got the following test:
public class AppITCase
{
#Test
public void failTest() {
fail();
}
}
It just fails. But if I run mvn clean test-compile failsafe:integration-test, I will see this:
Results :
Failed tests:
AppITCase.failTest:16
Tests run: 1, Failures: 1, Errors: 0, Skipped: 0
[WARNING] File encoding has not been set, using platform encoding Cp1251, i.e. build is platform dependent! The file encoding for reports output files should be provided by the POM property ${project.reporting.outputEncoding}.
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 7.853 s
[INFO] Finished at: 2017-01-14T01:32:16+04:00
[INFO] Final Memory: 11M/141M
Important lines:
Tests run: 1, Failures: 1, Errors: 0, Skipped: 0
[INFO] BUILD SUCCESS [INFO]
What? Why maven accepted this build, if it had test failures? How to solve this?
UPD
If I run mvn verify
[INFO] Scanning for projects...
[INFO]
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] --- maven-surefire-plugin:2.12.4:test (default-test) # vsjws-samples ---
[INFO]
[INFO] --- maven-jar-plugin:2.4:jar (default-jar) # vsjws-samples ---
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 2.333 s
[INFO] Finished at: 2017-01-14T01:41:23+04:00
[INFO] Final Memory: 15M/200M
[INFO] ------------------------------------------------------------------------

Categories