Maven Surefire plugin not starting tests defined in TestNG suite XML file - java

I am developing a test automation project that uses:
Maven, TestNG, Cucumber and Selenium WebDriver. My OS is Windows 10 and I'm using IntelliJ as my IDE.
I have a pom.xml file that looks like this (project name is changed for showcase purposes):
<?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>org.example</groupId>
<artifactId>project-name</artifactId>
<version>1.0-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>7.3.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-java</artifactId>
<version>6.9.0</version>
</dependency>
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-testng</artifactId>
<version>6.9.0</version>
</dependency>
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-picocontainer</artifactId>
<version>6.9.0</version>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>3.141.59</version>
</dependency>
<dependency>
<groupId>io.github.bonigarcia</groupId>
<artifactId>webdrivermanager</artifactId>
<version>4.2.2</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.11</version>
</dependency>
<dependency>
<groupId>org.iban4j</groupId>
<artifactId>iban4j</artifactId>
<version>3.2.1</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<source>11</source>
<target>11</target>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.12.4</version>
<configuration>
<suiteXmlFiles>
<suiteXmlFile>src/test/resources/TestSuites/suite.xml</suiteXmlFile>
</suiteXmlFiles>
<testFailureIgnore>true</testFailureIgnore>
</configuration>
</plugin>
</plugins>
</build>
As you can see, path to "suite.xml" is defined in POM and is correct:
TestNG suite "suite.xml" file looks like this:
<!DOCTYPE suite SYSTEM "https://testng.org/testng-1.0.dtd">
<suite name="All Tests Suite" verbose="1">
<test name="Test">
<classes>
<class name="Runners.RunnerAllFeatures"/>
</classes>
</test>
</suite>
Suite file has "RunnerAllFeatures" as it's test class. When I manually start that suite file (right click and "Run") it works well - cucumber scenarios defined in the "RunnerAllFeatures" are being executed.
Runner class "RunnerAllFeatures" looks like this:
package Runners;
import io.cucumber.testng.AbstractTestNGCucumberTests;
import io.cucumber.testng.CucumberOptions;
#CucumberOptions(
features = {"src/test/resources/Features/completed"},
glue = {"StepDefinitions"},
monochrome = true,
plugin = {"pretty", "html:target/cucumber.html"}
)
public class RunnerAllFeatures extends AbstractTestNGCucumberTests{}
Problem occurs when I am trying to run "suite.xml" via Maven in terminal. I use "mvn clean test" to do this. The build summary states "BUILD SUCCESS" but no tests were ran. Log line "T E S T S" is not even present. There are no warnings that would be (imo) significant to the problem.
Here is one of the log snippets:
C:\Users\username\IdeaProjects\project-name>mvn clean test
[INFO] Scanning for projects...
[INFO]
[INFO] -------------< org.example:project-name >--------------
[INFO] Building project-name 1.0-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
[INFO]
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) # project-name ---
[INFO] Deleting C:\Users\username\IdeaProjects\project-name\target
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) # project-name ---
[WARNING] Using platform encoding (Cp1250 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] Copying 4 resources
[INFO]
[INFO] --- maven-compiler-plugin:3.8.1:compile (default-compile) # project-name ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 39 source files to C:\Users\username\IdeaProjects\project-name\target\classes
[INFO] /C:/Users/username/IdeaProjects/project-name/src/main/java/baseMethods/BaseMethods.java: C:\Users\username\IdeaProjects\project-name\src\main\java\baseMethods\BaseMethods.java uses un
checked or unsafe operations.
[INFO] /C:/Users/username/IdeaProjects/project-name/src/main/java/baseMethods/BaseMethods.java: Recompile with -Xlint:unchecked for details.
[INFO]
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) # project-name ---
[WARNING] Using platform encoding (Cp1250 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] Copying 17 resources
[INFO]
[INFO] --- maven-compiler-plugin:3.8.1:testCompile (default-testCompile) # project-name ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 17 source files to C:\Users\username\IdeaProjects\project-name\target\test-classes
[INFO]
[INFO] --- maven-surefire-plugin:2.12.4:test (default-test) # project-name ---
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 6.108 s
[INFO] Finished at: 2021-12-29T13:46:30+01:00
[INFO] ------------------------------------------------------------------------
I tried changing backslashes to forward slashes in POM's path to "suite.xml" but it did not change anything.
I tried to parameterize that path but the result was the same. I have another test automation project where the only difference in technology stack is the lack of Cucumber. TestNG suite file points to a "#Test" annotated class. Starting that suite file through Maven Surefire works well there.
If there is a need for some more information I will try to provide it.

Found the solution. Runner class name was wrong - it has to include the word "Test".
See: https://maven.apache.org/surefire/maven-surefire-plugin/examples/inclusion-exclusion.html
I was aware of this Maven naming convention but I did not suspect that it might be an issue here since "RunnerAllFeatures" is a runner class and not a test class.

Related

Why doesn't Maven recognize file modifications? ("Nothing to compile - all classes are up to date" error)

I have a project in Java + Maven. I can compile and run the code with IntelliJ just fine: each modification I do in the code gets compiled in the program. However, when I try compiling from the command line (using mvn compile), Maven doesn't recognize the changes in the code, and simply says "Nothing to compile - all classes are up to date". I can force rebuilding using mvn clean, but that invalidates the purpose of having a build system. Why is it so, and how can it detect changes in the code?
For example, say I have a working code.
I do mvn compile. It works fine and I can run the program.
I change the code and introduce a syntax error. I save the file and do mvn compile. The output is Nothing to compile, together with a BUILD SUCCESS. However, when I try to run the program, I get a Exception in thread "main" java.lang.Error: Unresolved compilation problems, along with a series of error (due to the erroneous parsing)
If I change the code to a different code, but syntactically valid, I get the same behavior.
In fact, after this, even returning to my original code compiles, but then throws a java.lang.Error exception!
Why does it work like this, and why does it work in IntelliJ, but not in terminal?
EDIT:
IntelliJ is not open. However, Emacs does start the language server (jdtls).
My pom.xml:
<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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>it.polimi.middlewareB</groupId>
<artifactId>akka_actors</artifactId>
<packaging>jar</packaging>
<version>0.1 </version>
<properties>
<akka.version>2.6.19</akka.version>
<scala.binary.version>2.13</scala.binary.version>
</properties>
<name>akka_actors</name>
<url>http://maven.apache.org</url>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>com.typesafe.akka</groupId>
<artifactId>akka-bom_${scala.binary.version}</artifactId>
<version>2.6.19</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>com.typesafe.akka</groupId>
<artifactId>akka-actor-typed_2.13</artifactId>
<version>${akka.version}</version>
</dependency>
<dependency>
<groupId>com.typesafe.akka</groupId>
<artifactId>akka-actor_${scala.binary.version}</artifactId>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>1.2.3</version>
</dependency>
<dependency>
<groupId>com.typesafe.akka</groupId>
<artifactId>akka-actor-testkit-typed_2.13</artifactId>
<version>${akka.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.kafka</groupId>
<artifactId>kafka-clients</artifactId>
<version>3.2.0</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
<version>2.17.2</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>2.17.2</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-slf4j-impl</artifactId>
<version>2.17.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.12.6.1</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.5.1</version>
<configuration>
<source>11</source>
<target>11</target>
</configuration>
</plugin>
<!-- <plugin> -->
<!-- <groupId>org.codehaus.mojo</groupId> -->
<!-- <artifactId>exec-maven-plugin</artifactId> -->
<!-- <version>1.6.0</version> -->
<!-- <configuration> -->
<!-- <executable>java</executable> -->
<!-- <arguments> -->
<!-- <argument>-classpath</argument> -->
<!-- <classpath /> -->
<!-- <argument>com.example.AkkaQuickstart</argument> -->
<!-- </arguments> -->
<!-- </configuration> -->
<!-- </plugin> -->
<!-- <plugin> -->
<!-- <groupId>org.codehaus.mojo</groupId> -->
<!-- <artifactId>exec-maven-plugin</artifactId> -->
<!-- <version>1.6.0</version> -->
<!-- <executions> -->
<!-- <execution> -->
<!-- <id>default-cli</id> -->
<!-- <configuration> -->
<!-- <mainClass>com.example.AkkaQuickstart</mainClass> -->
<!-- </configuration> -->
<!-- </execution> -->
<!-- </executions> -->
<!-- </plugin> -->
</plugins>
</build>
</project>
After mvn clean, this is the output of mvn compile:
[INFO] Scanning for projects...
[INFO]
[INFO] -----------------< it.polimi.middlewareB:akka_actors >------------------
[INFO] Building akka_actors 0.1
[INFO] --------------------------------[ jar ]---------------------------------
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) # akka_actors ---
[WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] Copying 3 resources
[INFO]
[INFO] --- maven-compiler-plugin:3.5.1:compile (default-compile) # akka_actors ---
[INFO] Changes detected - recompiling the module!
[WARNING] File encoding has not been set, using platform encoding UTF-8, i.e. build is platform dependent!
[INFO] Compiling 15 source files to /home/alessandro/middleware/middleware_projectB/akka_actors/target/classes
[INFO] /home/alessandro/middleware/middleware_projectB/akka_actors/src/main/java/it/polimi/middlewareB/AlwaysSeekToBeginningListener.java: /home/alessandro/middleware/middleware_projectB/akka_actors/src/main/java/it/polimi/middlewareB/AlwaysSeekToBeginningListener.java uses unchecked or unsafe operations.
[INFO] /home/alessandro/middleware/middleware_projectB/akka_actors/src/main/java/it/polimi/middlewareB/AlwaysSeekToBeginningListener.java: Recompile with -Xlint:unchecked for details.
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 2.471 s
[INFO] Finished at: 2022-07-13T10:36:08+02:00
[INFO] ------------------------------------------------------------------------
Adding in the main .java file a line like this
public class ClusterStarter {
private static final String kafkaDefaultArgument = "localhost:9092";
private static final int actorPoolDefaultDimension = 3;
apinaosncla aifasi; //NOTE HERE
public static void main(String[] args) {
/* ... */
}
}
launching mvn compile gives:
[INFO] Scanning for projects...
[INFO]
[INFO] -----------------< it.polimi.middlewareB:akka_actors >------------------
[INFO] Building akka_actors 0.1
[INFO] --------------------------------[ jar ]---------------------------------
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) # akka_actors ---
[WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] Copying 3 resources
[INFO]
[INFO] --- maven-compiler-plugin:3.5.1:compile (default-compile) # akka_actors ---
[INFO] Nothing to compile - all classes are up to date
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 0.970 s
[INFO] Finished at: 2022-07-13T10:43:07+02:00
[INFO] ------------------------------------------------------------------------
However, giving first mvn clean and then mvn compile:
[INFO] Scanning for projects...
[INFO]
[INFO] -----------------< it.polimi.middlewareB:akka_actors >------------------
[INFO] Building akka_actors 0.1
[INFO] --------------------------------[ jar ]---------------------------------
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) # akka_actors ---
[WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] Copying 3 resources
[INFO]
[INFO] --- maven-compiler-plugin:3.5.1:compile (default-compile) # akka_actors ---
[INFO] Changes detected - recompiling the module!
[WARNING] File encoding has not been set, using platform encoding UTF-8, i.e. build is platform dependent!
[INFO] Compiling 15 source files to /home/alessandro/middleware/middleware_projectB/akka_actors/target/classes
[INFO] -------------------------------------------------------------
[ERROR] COMPILATION ERROR :
[INFO] -------------------------------------------------------------
[ERROR] /home/alessandro/middleware/middleware_projectB/akka_actors/src/main/java/it/polimi/middlewareB/ClusterStarter.java:[36,5] cannot find symbol
symbol: class apinaosncla
location: class it.polimi.middlewareB.ClusterStarter
[INFO] 1 error
[INFO] -------------------------------------------------------------
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1.966 s
[INFO] Finished at: 2022-07-13T10:43:46+02:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.5.1:compile (default-compile) on project akka_actors: Compilation failure
[ERROR] /home/alessandro/middleware/middleware_projectB/akka_actors/src/main/java/it/polimi/middlewareB/ClusterStarter.java:[36,5] cannot find symbol
[ERROR] symbol: class apinaosncla
[ERROR] location: class it.polimi.middlewareB.ClusterStarter
[ERROR]
[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
Now, returning to a working code, mvn compile still gives Nothing to compile, and launching the program gives:
/path/to/project $ /usr/lib/jvm/java-11-openjdk/bin/java -Dfile.encoding=UTF-8 -classpath /home/alessandro/middleware/middleware_projectB/akka_actors/target/classes:/home/alessandro/.m2/repository/com/typesafe/akka/akka-actor-typed_2.13/2.6.19/akka-actor-typed_2.13-2.6.19.jar:/home/alessandro/.m2/repository/org/scala-lang/scala-library/2.13.8/scala-library-2.13.8.jar:/home/alessandro/.m2/repository/com/typesafe/akka/akka-slf4j_2.13/2.6.19/akka-slf4j_2.13-2.6.19.jar:/home/alessandro/.m2/repository/org/slf4j/slf4j-api/1.7.36/slf4j-api-1.7.36.jar:/home/alessandro/.m2/repository/com/typesafe/akka/akka-actor_2.13/2.6.19/akka-actor_2.13-2.6.19.jar:/home/alessandro/.m2/repository/com/typesafe/config/1.4.2/config-1.4.2.jar:/home/alessandro/.m2/repository/org/scala-lang/modules/scala-java8-compat_2.13/1.0.0/scala-java8-compat_2.13-1.0.0.jar:/home/alessandro/.m2/repository/ch/qos/logback/logback-classic/1.2.3/logback-classic-1.2.3.jar:/home/alessandro/.m2/repository/ch/qos/logback/logback-core/1.2.3/logback-core-1.2.3.jar:/home/alessandro/.m2/repository/com/typesafe/akka/akka-actor-testkit-typed_2.13/2.6.19/akka-actor-testkit-typed_2.13-2.6.19.jar:/home/alessandro/.m2/repository/com/typesafe/akka/akka-testkit_2.13/2.6.19/akka-testkit_2.13-2.6.19.jar:/home/alessandro/.m2/repository/org/apache/kafka/kafka-clients/3.2.0/kafka-clients-3.2.0.jar:/home/alessandro/.m2/repository/com/github/luben/zstd-jni/1.5.2-1/zstd-jni-1.5.2-1.jar:/home/alessandro/.m2/repository/org/lz4/lz4-java/1.8.0/lz4-java-1.8.0.jar:/home/alessandro/.m2/repository/org/xerial/snappy/snappy-java/1.1.8.4/snappy-java-1.1.8.4.jar:/home/alessandro/.m2/repository/org/apache/logging/log4j/log4j-api/2.17.2/log4j-api-2.17.2.jar:/home/alessandro/.m2/repository/org/apache/logging/log4j/log4j-core/2.17.2/log4j-core-2.17.2.jar:/home/alessandro/.m2/repository/org/apache/logging/log4j/log4j-slf4j-impl/2.17.2/log4j-slf4j-impl-2.17.2.jar:/home/alessandro/.m2/repository/junit/junit/3.8.1/junit-3.8.1.jar:/home/alessandro/.m2/repository/com/fasterxml/jackson/core/jackson-databind/2.12.6.1/jackson-databind-2.12.6.1.jar:/home/alessandro/.m2/repository/com/fasterxml/jackson/core/jackson-annotations/2.12.6/jackson-annotations-2.12.6.jar:/home/alessandro/.m2/repository/com/fasterxml/jackson/core/jackson-core/2.12.6/jackson-core-2.12.6.jar it.polimi.middlewareB.ClusterStarter
Exception in thread "main" java.lang.Error: Unresolved compilation problems:
RetriesAnalysisActor cannot be resolved
JobSupervisorActor cannot be resolved
CompletedAnalysisThread cannot be resolved to a type
PendingAnalysisThread cannot be resolved to a type
at it.polimi.middlewareB.ClusterStarter.main(ClusterStarter.java:55)
(those are classes of my project)

Running Maven Tests

I am learning Java, part of the courseware is Maven.
I have created a simple Maven project. And in the test class I have added the following code:
package maventest2;
import org.junit.Test;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Tag;
public class firstclass {
#Tag("FirstTests")
#DisplayName("This is the first group test I working on")
#Test
public void someTest() {
System.out.println("This in some test running");
}
}
When I run mvn test command I get the following:
Microsoft Windows [Version 10.0.18363.1256]
(c) 2019 Microsoft Corporation. All rights reserved.
C:\Users\pawan\eclipse-workspace\maventest2>mvn test
[INFO] Scanning for projects...
[INFO]
[INFO] -----------------------< com.taskone:maventest2 >-----------------------
[INFO] Building maventest2 0.0.1-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) # maventest2 ---
[WARNING] Using platform encoding (Cp1252 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) # maventest2 ---
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) # maventest2 ---
[WARNING] Using platform encoding (Cp1252 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] Copying 0 resource
[INFO]
[INFO] --- maven-compiler-plugin:3.1:testCompile (default-testCompile) # maventest2 ---
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] --- maven-surefire-plugin:3.0.0-M3:test (default-test) # maventest2 ---
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1.139 s
[INFO] Finished at: 2020-12-19T23:32:34-05:00
[INFO] ------------------------------------------------------------------------
Why is the test not being run? When I use the option to Run As ->JUnit Test. It works fine and I get the passed result.
Please advice.
pom file:
<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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.taskone</groupId>
<artifactId>maventest2</artifactId>
<version>0.0.1-SNAPSHOT</version>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M3</version>
<configuration>
<includes>
<include>%regex[.*Test.*]</include>
</includes>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>junit</groupId> <!-- NOT org.junit here -->
<artifactId>junit-dep</artifactId>
<version>4.8.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>5.7.0</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
Directory structure of project
The test file is in src/test/java
Two reasons:
Your test class name doesn't match the regex you have in your surefire configuration. You have explicitly said that the class name needs to match *Test*
You are importing the #Test annotation from org.junit, not org.junit.jupiter.api.Test

Not able to get dependency check report in Maven

I am trying to get dependency check report for one of my Maven project but every time I am running:
mvn verify
dependency in dependency report shows no vulnerable JARs.
I have added below plugin in my POM to generate dependency check report:
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-email</artifactId>
<version>1.1</version>
</dependency>
<dependency>
<groupId>apache.axis</groupId>
<artifactId>jaxrpc</artifactId>
<version>1.2beta</version>
<scope>provided</scope>
</dependency>
<dependencies>
<dependencyManagement>
<build>
<plugins>
<plugin>
<groupId>org.owasp</groupId>
<artifactId>dependency-check-maven</artifactId>
<version>3.3.2</version>
<executions>
<execution>
<goals>
<goal>check</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
What do I need to correct or is there any other way? commons-email-1.1.jar have some vulnerabilities but still its not getting detected.
These are the Maven logs:
[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] --- maven-clean-plugin:2.6.1:clean (default-clean) # version-mana -
--
[INFO]
[INFO] --- maven-source-plugin:2.4:jar-no-fork (attach-sources) # version-
mana ---
[INFO]
[INFO] --- maven-source-plugin:2.4:test-jar-no-fork (attach-sources) #
version-mana ---
[INFO]
[INFO] --- dependency-check-maven:3.3.2:check (default) # version-mana ---
[INFO] Central analyzer disabled
[INFO] Checking for updates
[INFO] Skipping NVD check since last check was within 4 hours.
[INFO] Skipping RetireJS update since last update was within 24 hours.
[INFO] Check for updates complete (31 ms)
[INFO] Analysis Started
[INFO] Finished File Name Analyzer (0 seconds)
[INFO] Finished Dependency Merging Analyzer (0 seconds)
[INFO] Finished Version Filter Analyzer (0 seconds)
[INFO] Finished Hint Analyzer (0 seconds)
[INFO] Created CPE Index (1 seconds)
[INFO] Skipping CPE Analysis for npm
[INFO] Finished CPE Analyzer (1 seconds)
[INFO] Finished False Positive Analyzer (0 seconds)
[INFO] Finished NVD CVE Analyzer (0 seconds)
[INFO] Finished Vulnerability Suppression Analyzer (0 seconds)
[INFO] Finished Dependency Bundling Analyzer (0 seconds)
[INFO] Analysis Complete (1 seconds)
Provided you have access to the maven repository (at the time of executing this command) and installed mvn/mvnw , from the command-line, you can execute this line.
mvn org.owasp:dependency-check-maven:5.2.2:check
The "dependency-check-report.html" report will be generated in the target folder.
Out of interest i tried it and for me it is working:
<project>
<modelVersion>4.0.0</modelVersion>
<groupId>test</groupId>
<artifactId>test</artifactId>
<version>1.0</version>
<dependencies>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-email</artifactId>
<version>1.1</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.owasp</groupId>
<artifactId>dependency-check-maven</artifactId>
<version>3.3.3</version>
<executions>
<execution>
<goals>
<goal>check</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
dependency-check-maven tells me:
[INFO] Analysis Complete (1 seconds)
[WARNING]
One or more dependencies were identified with known vulnerabilities in test:
commons-email-1.1.jar (org.apache.commons:commons-email:1.1, cpe:/a:apache:commons_email:1.1) : CVE-2017-9801, CVE-2018-1294
See the dependency-check report for more details.
How does your dependencies section look like? For Example if you define the scope test for commons-email no warning is shown.

Maven Plugin/Profile Issue

I am an automation qa engineer and I've been charged with setting up our Jenkins CI framework. The issue that I am having is that Maven is failing in the build phase. In looking at the log there a few things that are concerning to me but I am not sure if they are related or relevant. See the log below
Microsoft Windows [Version 6.1.7601]
Copyright (c) 2009 Microsoft Corporation. All rights reserved.
C:\Users\dmohamed>mvn test -PCustomerFSNRegressionSuite
[INFO] Scanning for projects...
[WARNING]
[WARNING] Some problems were encountered while building the effective model for
Envi_Test:Maven:jar:0.0.1-SNAPSHOT
[WARNING] 'dependencies.dependency.systemPath' for com.qas.qtest.api:qtest-sdk-a
gent:jar should not point at files within the project directory, ${basedir}\src\
Libs\qtest-sdk-java-1.1.0.jar will be unresolvable by dependent projects # line
42, column 17
[WARNING] 'dependencies.dependency.systemPath' for com.qas.qtest.api:qtest-testn
g-agent:jar should not point at files within the project directory, ${basedir}\s
rc\Libs\qtest-testng-agent-1.0.0.jar will be unresolvable by dependent projects
# line 50, column 17
[WARNING]
[WARNING] It is highly recommended to fix these problems because they threaten t
he stability of your build.
[WARNING]
[WARNING] For this reason, future Maven versions might no longer support buildin
g such malformed projects.
[WARNING]
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building Maven 0.0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) # Maven ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory C:\Users\dmohamed\src\main\resources
[INFO]
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) # Maven ---
[INFO] No sources to compile
[INFO]
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) # Ma
ven ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory C:\Users\dmohamed\src\test\resources
[INFO]
[INFO] --- maven-compiler-plugin:3.1:testCompile (default-testCompile) # Maven -
--
[INFO] No sources to compile
[INFO]
[INFO] --- maven-surefire-plugin:2.19.1:test (default-test) # Maven ---
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1.190 s
[INFO] Finished at: 2016-08-02T08:25:01-04:00
[INFO] Final Memory: 11M/307M
[INFO] ------------------------------------------------------------------------
[WARNING] The requested profile "CustomerFSNRegressionSuite" could not be activa
ted because it does not exist.
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.
19.1:test (default-test) on project Maven: Unable to parse configuration of mojo
org.apache.maven.plugins:maven-surefire-plugin:2.19.1:test for parameter proper
ties: Missing name in properties -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e swit
ch.
[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 rea
d the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/PluginConfigur
ationException
C:\Users\dmohamed>
my concerns are specifically these lines
INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory C:\Users\dmohamed\src\main\resources
[INFO]
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) # Maven ---
[INFO] No sources to compile
[INFO]
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) # Ma
ven ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory
C:\Users\dmohamed\src\test\resources
[INFO]
[INFO] --- maven-compiler-plugin:3.1:testCompile (default-testCompile) # Maven -
--
[INFO] No sources to compile
WARNING] The requested profile "CustomerFSNRegressionSuite" could not be activa
ted because it does not exist.
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.
19.1:test (default-test) on project Maven: Unable to parse configuration of mojo
org.apache.maven.plugins:maven-surefire-plugin:2.19.1:test for parameter proper
ties: Missing name in properties -> [Help 1]
It seems as though when I attempt to run the mvn commands it tries to reference srs folders that don't exist (not sure if this does any harm) it doesn't recognize my TestnNG profile specified in my POM file (I am assuming this will impact Jenkins) and there is some property/configuration error in my pom file (Per the ERROR message in my log) that I cannot resolve. See my POM file below
<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>Envi_Test</groupId>
<artifactId>Maven</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>Maven</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<profiles>
<profile>
<id>CustomerFSNRegressionSuite</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.19.1</version>
<configuration>
<suiteXmlFiles>
<suiteXmlFile>testng.xml</suiteXmlFile>
</suiteXmlFiles>
</configuration>
</plugin>
</plugins>
</build>
</profile>
</profiles>
<dependencies>
<!-- https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-java -->
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
</dependency>
<!-- https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-chrome-driver -->
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-chrome-driver</artifactId>
</dependency>
<dependency>
<groupId>info.cukes</groupId>
<artifactId>cucumber-testng</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>2.53.0</version>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-chrome-driver</artifactId>
<version>2.53.0</version>
</dependency>
<dependency>
<groupId>info.cukes</groupId>
<artifactId>cucumber-testng</artifactId>
<version>1.1.5</version>
</dependency>
</dependencies>
</dependencyManagement>
</project>
Any help would be greatly appreciated, I am sorry if this is a repost, I looked but I did not see a question regarding a circumstance like this.

not able to run maven project

I have a maven project, where in src/test/java i have a java file which have #Test method, which basically initiates the entire test suite and when i run through TestNG or jUnit everything works fine.
But when i run this by Maven Test, i am getting below message and nothing executes. Can someone help me in this?
[INFO] Scanning for projects...
[WARNING]
[WARNING] Some problems were encountered while building the effective model for MavenHybridFramework:MavenHybridFramework:jar:0.0.1-SNAPSHOT
[WARNING] 'dependencies.dependency.systemPath' for com.relevantcodes:extentreports:jar should use a variable instead of a hard-coded path D:\UD\jars\extentreports_Updated.jar # line 36, column 18
[WARNING] 'dependencies.dependency.systemPath' for org.monte:media:jar should use a variable instead of a hard-coded path D:\UD\jars\MonteScreenRecorder.jar # line 43, column 18
[WARNING]
[WARNING] It is highly recommended to fix these problems because they threaten the stability of your build.
[WARNING]
[WARNING] For this reason, future Maven versions might no longer support building such malformed projects.
[WARNING]
[INFO]
[INFO] Using the builder org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder with a thread count of 1
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building MavenHybridFramework 0.0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) # MavenHybridFramework ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 0 resource
[INFO]
[INFO] --- maven-compiler-plugin:2.5.1:compile (default-compile) # MavenHybridFramework ---
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) # MavenHybridFramework ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 0 resource
[INFO]
[INFO] --- maven-compiler-plugin:2.5.1:testCompile (default-testCompile) # MavenHybridFramework ---
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] --- maven-surefire-plugin:2.12.4:test (default-test) # MavenHybridFramework ---
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 2.491 s
[INFO] Finished at: 2015-09-23T09:35:28+05:30
[INFO] Final Memory: 7M/17M
[INFO] ------------------------------------------------------------------------
Following is my pom.xml
<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>MavenHybridFramework</groupId>
<artifactId>MavenHybridFramework</artifactId>
<version>0.0.1-SNAPSHOT</version>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>2.47.1</version>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi</artifactId>
<version>3.12</version>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
<version>3.12</version>
</dependency>
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>6.1.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.relevantcodes</groupId>
<artifactId>extentreports</artifactId>
<version>1.41</version>
<scope>system</scope>
<systemPath>D:\UD\jars\extentreports_Updated.jar</systemPath>
</dependency>
<dependency>
<groupId>org.monte</groupId>
<artifactId>media</artifactId>
<version>0.7.7</version>
<scope>system</scope>
<systemPath>D:\UD\jars\MonteScreenRecorder.jar</systemPath>
</dependency>
</dependencies>
</project>
Following is my TestNG test
package TestSuite;
import org.testng.annotations.Test;
import FrameworkLibraries.FunctionLibraries.CommonFunctionLibrary;
import FrameworkLibraries.FunctionLibraries.FrameworkFunctionLibrary;
public class AutomationDriver
{
#Test
public void runTestSuite()
{
FrameworkFunctionLibrary frameworkFuncLib=new FrameworkFunctionLibrary();
//The below method initilizes the framework to make sure required configurations exists
frameworkFuncLib.frameworkInit();
//The below loads the required Test Data configurations and execute test cases
frameworkFuncLib.frameworkExecuteTestCases();
}
}
Try doing a Maven Clean first.
Then try executing the Maven Test.
Also, Eclipse Maven integration doesn't work always.
Try executing mvn clean install from the Command Prompt/Shell.
This should work.
For following error,
Fatal error compiling: tools.jar not found: C:\Program Files\Java\jre1.8.0_45\..\lib\tools.jar ->
Add this:
<dependency>
<groupId>com.sun</groupId>
<artifactId>tools</artifactId>
<version>1.7.0</version>
<scope>system</scope>
<systemPath> add your path/Java/jdk1.7.0_60/lib/tools.jar</systemPath>
</dependency>
Try adding the below to pom.xml. It should enhance the compiler version to JDK 1.8 . For me, it worked.
<project>
[...]
<build>
[...]
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.6.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
[...]
</build>
[...]
</project>

Categories