How to run specific test class in subfolder with maven command? - java

I have a question in regards to running a single test class through maven. More specifically, I have a project structure which looks like this:
And I would like to run the integration test inside the StatusSocketIT class through a maven command. I tried therefore the following maven command:
mvn test -Dtest=todolist.websocket.src.it.java.org.smart.todolist.websocket.StatusSocketIT
but it fails with the following error:
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.12.4:test (default-test) on project backend: No tests were executed! (Set -DfailIfNoTests=false to ignore this error.) -> [Help 1]
which tells that the tests cant be executed. I have also tried other path names like for instance org.smart.todolist.websocket.StatusSocketIT but this also throws the same error. Would anyone maybe know what the issue is? Thanks in advance

Change the command to:
mvn test -Dtest=org.smart.todolist.websocket.StatusSocketIT
Only the "path" inside src/it/java is part of the class name (its package).
In addition, make sure you have the src/it/java directory configured as a test directory in your pom file:
<build>
<testSourceDirectory>src/it/java</testSourceDirectory>
</build>

Related

quarkus dev build failes with customized outputDirectory in pom.xml of dependend module

I started with a quarkus multi maven-module project and encountered the following problem when starting quarkus in the dev mode (mvn quarkus:dev) to support hot reload for depended modules' classes:
A module "my-app" configures its' build output path via the
<project><build><outputDirectory>build</outputDirectory> in the pom.xml. The module is build successfully, and the output exists in path my-app/build instead of the default target/classes.
Then the build of another module "momsServerQuarkus", which depends on the "my-app", and which uses quarkus-maven-plugin, fails with error:
[ERROR] Failed to execute goal io.quarkus:quarkus-maven-plugin:2.11.0.Final:dev (default-cli) on project momsServerQuarkus: Failed to run: Hot reloadable dependency de.kwsoft.moms:my-app:6.14.0-SNAPSHOT has not been compiled yet (the classes directory S:\trunk\moms\my-app\target\build does not exist)
As visible in the error message, the <outputDirectory>build</outputDirectory>is read correctly from the my-apps' pom.xml, but is appended to the default output path "target" instead of the projects root folder. I played also variables, e.g. <outputDirectory>${basedir}/build</outputDirectory>, but the variable is not resolved by the quarkus-maven-plugin.
Does anyone know how this could be solved, or whether this could be a bug?
Thank you in advance.

Sonar error : Wrong source path use by the analyser

I run the command below with GitLab CI / CD:
mvn -s /etc/gitlab-runner/maven/settings-maven.xml --batch-mode test sonar:sonar
-Dsonar.java.source=1.8
-Dsonar.host.url=${SONARHOST}
-Dsonar.projectKey=${SONARKEY}
-Dsonar.projectName=${SONARNAME}
-Dsonar.projectVersion=${SONARVERSION}
-Dsonar.sources=myproject_core/src/main/java,myproject_service/src/main/java,myproject_persistance/src/main/java
-Dsonar.language=java
-Dsonar.java.binaries=myproject_core/target/classes,myproject_service/target/classes,myproject_persistance/target/classes
-Dsonar.java.libraries=**/*.jar
-Dsonar.java.coveragePlugin=jacoco
-Dsonar.surefire.reportPaths=myproject_core/target/surefire-reports,myproject_service/target/surefire-reports,myproject_persistance/target/surefire-reports
-Dsonar.junit.reportPaths=myproject_core/target/surefire-reports,myproject_persistance/target/surefire-reports,myproject_service/target/surefire-reports
-Dsonar.verbose=true
-Dsonar.binaries=myproject_core/target/classes,myproject_service/target/classes,myproject_persistance/target/classes
-Dsonar.jacoco.reportPaths=myproject_core/target/jacoco.exec,myproject_service/target/jacoco.exec,myproject_persistance/target/jacoco.exec
-Dsonar.exclusions=**/*Test*/**
-Dsonar.tests=myproject_core/src/test,myproject_service/src/test,myproject_persistance/src/test
So, I want to analyse 3 project core, service and persistance (I have 7 modules in my project)
myproject-parent
myproject-core
myproject-persistance
myproject-service
myproject- ...
But, I have this error :
[ERROR] Failed to execute goal org.sonarsource.scanner.maven:sonar-maven-plugin:3.7.0.1746:sonar (default-cli) on project myproject-parent: The directory '/builds/git-myproject/myproject-parent/**myproject_persistance/myproject_core**/src/main/java' does not exist for Maven module fr.xxx.xxx.myproject:myproject_persistance:jar:1.1. Please check the property sonar.sources -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.sonarsource.scanner.maven:sonar-maven-plugin:3.7.0.1746:sonar (default-cli) on project myproject-parent: The directory '/builds/git-myproject/myproject-parent/myproject_persistance/myproject_core/src/main/java' does not exist for Maven module fr.xxx.xxx.myproject:myproject_persistance:jar:1.1. Please check the property sonar.sources
On this sonarqube error, i can see that in the path, module persistance is include on module core, but this is not the case
I'm looking for why but I can't find. Have you ever had this problem ?

Getting coverage from .war-dependency in multi-module-project

I have setup a Jacoco-subproject to allow Jacoco to handle multi-module-projects in my maven-project as described here. The Jacoco project depends on all .jar-modules in my project as described in the tutuorial. But this setup only seems to work for .jar-files. Instead of understanding that my .war-project produces a .war-file Jacoco is looking for a .jar.
What do I have to do to make the .war-file to get coverage?
maybe this issue will help.
Just add <type>war</type> to the dependency in the dedicated module.
but after doing that, I got another error:
Execution default of goal org.springframework.boot:spring-boot-maven-plugin:1.5.4.RELEASE:repackage failed: Unable to find main class -> [Help 1]
after add <packaging>pom</packaging> to the dedicated module for collecting all test result, jacoco works as usual.

Sonar error in multi language project: File can't be indexed twice

I'm trying to setup sonar to analyze both java and javascript sources.
I have a standard structure maven project.
Following THIS example I've added the line
<properties>
<sonar.sources>src</sonar.sources>
</properties>
But when I run
mvn clean install sonar:sonar
I get the following error
[ERROR] Failed to execute goal
org.codehaus.mojo:sonar-maven-plugin:2.5:sonar (default-cli) on
project myproject: File [moduleKey=myproject:myproject,
relative=src/test/java/com/myproject/api/v1/ControllerTest.java,
basedir=C:\sources\project] can't be indexed twice. Please check that
inclusion/exclusion patterns produce disjoint sets for main and test
files -> [Help 1]
"ControllerTest.java" is the first file in the /src/test/java/../.. folder
project structure:
Any hints? Thanks in advance for any help!
UPDATE
1#
Tried Akash Rajbanshi suggestion: error disappeared but js code is not analyzed and also sonar doesn't analyze the test folder
2# tried to put <sonar.language>js</sonar.language> and the js code is actually analyzed but java code is not (that was just a test)
I'm kind of stuck
In order to make SonarQube analyse your tests as well, you should also set the "sonar.tests" property:
<properties>
<sonar.sources>src/main</sonar.sources>
<sonar.tests>src/test</sonar.tests>
</properties>
You can use this instead:
<properties>
<sonar.sources>src/main</sonar.sources>
</properties>

maven command line - plugin configuration

I'm in the need to run integration tests one by one with the failsafe plugin (please, don't ask why... They just have to run in individual jvms, one good reason for avoiding singletons).
So I'd like to create a script with one maven call per line where each maven call runs tests on a single test file. Something like this:
mvn failsafe:integration-test -D<???>=**/ITest1.java
mvn failsafe:integration-test -D<???>=**/ITest2.java
mvn failsafe:integration-test -D<???>=**/ITest3.java
...
In a pom.xml I'd add something like
<includes>
<include>**/ITest1.java</include>
</includes>
to the plugins configuration. Is there a way to achieve the same with the command line? Is it possible to specify list-like configuration options?
The syntax is:
mvn -Dit.test=TestName verify
Source: Failsafe Plugin Examples: Running a Single Test
The it.test parameter does that. You can read about it here.
From the docs:
[...] so you can just type "-Dit.test=MyTest" to run a single test called "foo/MyTest.java".

Categories

Resources