Maven can't find any test - maven

I copy pom.xml with a similar project were all ok. Add need dependencies. Also, I add Jupiter with scope "compile" otherwise project doesn't compile. I try to find a solution in similar problems but nothing found.
Env: ubuntu 18, idea 2018.3, openjdk8, maven last version.
I try to change more new or old version junit, surefire plugin and junit-platform-surefire-provider but don't find need combination.
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<java.version>1.8</java.version>
<junit.api.version>5.4.0</junit.api.version>
<junit.jupiter.version>5.4.0</junit.jupiter.version>
<junit.platform.version>1.3.1</junit.platform.version>
<aspectj.version>1.9.4</aspectj.version>
<allure.version>2.12.1</allure.version>
</properties>
<dependencies>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>${junit.jupiter.version}</version>
</dependency>
<dependency>
<groupId>io.qameta.allure</groupId>
<groupId>io.qameta.allure</groupId>
<artifactId>allure-junit5</artifactId>
<version>${allure.version}</version>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>5.4.0</version>
<scope>compile</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.2</version>
<configuration>
<testFailureIgnore>false</testFailureIgnore>
<argLine>
-javaagent:"${settings.localRepository}/org/aspectj/aspectjweaver/${aspectj.version}/aspectjweaver-${aspectj.version}.jar"
</argLine>
<systemProperties>
<property>
<name>junit.jupiter.extensions.autodetection.enabled</name>
<value>true</value>
</property>
</systemProperties>
</configuration>
<dependencies>
<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-surefire-provider</artifactId>
<version>1.3.2</version>
</dependency>
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjweaver</artifactId>
<version>${aspectj.version}</version>
</dependency>
</dependencies>
</plugin>
<plugin>
<groupId>io.qameta.allure</groupId>
<artifactId>allure-maven</artifactId>
<version>LATEST_VERSION</version>
<configuration>
<reportVersion>2.4.1</reportVersion>
</configuration>
</plugin>
</plugins>
</build>

By default the maven Surefire Plugin expects your tests filenames to match the following conditions:
**/Test*.java - includes all of its subdirectories and all Java
filenames that start with "Test".
**/*Test.java - includes all of
its subdirectories and all Java filenames that end with "Test".
**/*Tests.java - includes all of its subdirectories and all Java
filenames that end with "Tests".
**/*TestCase.java - includes all
of its subdirectories and all Java filenames that end with
"TestCase".
If you test file names don't match the above criteria you have two options. First of all modify your test filenames so that they do match the above criteria. Secondly you can modify the inclusion criteria by configuring the maven-surefire-plugin
<project>
[...]
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M3</version>
<configuration>
<includes>
<include>%regex[.*(Cat|Dog).*Test.*]</include>
</includes>
</configuration>
</plugin>
</plugins>
</build>
[...]
</project>
For more information have a look at the maven-surefire-plugin documentation.

Related

Using Provided Artifact As Maven Plugin Dependency

This seems like it should be a simple question, but I can't seem to find any information about it. When a maven plugin has a required dependency, is it possible to tell it to use an artifact defined elsewhere in the section of the pom?
As an example, I'm trying to add the 'maven-processor-plugin' to my build. That plugin has a dependency on 'hibernate-jpamodelgen'. I'm working with wildfly, so I already have that jar as a dependency of the project. I want to ensure I am using the same version for both. Is what I'm trying to do even possible?
Some code snippets:
<dependencies>
<dependency>
<groupId>org.wildfly</groupId>
<artifactId>wildfly-ejb3</artifactId>
<version>${version.server.bom}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-jpamodelgen</artifactId>
<scope>provided</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<compilerArguments>
<processor>-proc:none</processor>
</compilerArguments>
</configuration>
</plugin>
<plugin>
<groupId>org.bsc.maven</groupId>
<artifactId>maven-processor-plugin</artifactId>
<version>4.5</version>
<executions>
<execution>
<id>process</id>
<goals>
<goal>process</goal>
</goals>
<phase>generate-sources</phase>
<configuration>
<outputDirectory>${project.build.directory}/generated-sources/java/jpametamodel</outputDirectory>
<processors>
<processor>org.hibernate.jpamodelgen.JPAMetaModelEntityProcessor</processor>
</processors>
<overwrite>true</overwrite>
</configuration>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-jpamodelgen</artifactId>
<!-- How do I handle this without hard coding the version? -->
<!-- <version>???</version> -->
</dependency>
</dependencies>
</plugin>
</build>
Define a property like <hibernate-jpamodelgen.version> in the <properties> section of the POM.
Then use that property for the version like ${hibernate-jpamodelgen.version}.

Can we execute multiple profiles in the same pom.xml file

I have created a Maven project in Eclipse and have 2 xml files in it. I have created 2 profiles "TestNG.xml" and "TestNG2.xml" in the pom.xml file for my Maven project.
I ran the following command from command prompt
- mvn test
Expected behavior : TCs under both the TestNG.xml and TestNG2.xml files should get executed.
Actual behavior : Only TCs under TestNG2.xml file is getting executed.
NOTE :- When i am executing the .xml files individually using the below command it works fine{TestNG.xml file has been profiled as Regression in the pom.xml file}
- mvn test -PRegression
Below is the snapshot of my code from pom.xml file
<groupId>Rohit</groupId>
<artifactId>MavenProject05202020</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>MavenProject05202020</name>
<url>http://maven.apache.org</url>
<profiles>
<profile>
<id>Regression</id>
<!-- Below is MAVEN SURE FIRE PLUGIN. This will help to execute all your TCs present in your test folder{i.e.:-src/test/java}-->
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M4</version>
<configuration>
<suiteXmlFiles>
<suiteXmlFile>testng.xml</suiteXmlFile>
</suiteXmlFiles>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
</profile>
<!-- Below is MAVEN SURE FIRE PLUGIN.
<profile>
<id>Smoke</id>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M4</version>
<configuration>
<suiteXmlFiles>
<suiteXmlFile>testng2.xml</suiteXmlFile>
</suiteXmlFiles>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
</profile>
</profiles>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<!-- below is the dependency for Selenium project -->
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>3.8.1</version>
</dependency>
<!-- Below is the dependency for TESTNG. -->
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>7.1.0</version>
<scope>test</scope>
</dependency>
<!-- Below is the dependency for RestAPITest project -->
<dependency>
<groupId>io.rest-assured</groupId>
<artifactId>rest-assured</artifactId>
<version>4.3.0</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
If you just define the surefire-plugin twice, these definitions will override each other.
Instead, you need to define an <execution> in the plugin declaration and bind it to a phase. Plugins can have more than one execution in the <executions> block.

How to convert a maven plugin into a gradle plugin (maven-surefire-puglin )?

I am trying to use this plugin but with gradle:
<properties>
<aspectj.version>1.8.10</aspectj.version>
</properties>
<dependencies>
<dependency>
<groupId>io.qameta.allure</groupId>
<artifactId>allure-junit4</artifactId>
<version>LATEST_VERSION</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.20</version>
<configuration>
<testFailureIgnore>false</testFailureIgnore>
<argLine>
-javaagent:"${settings.localRepository}/org/aspectj/aspectjweaver/${aspectj.version}/aspectjweaver-${aspectj.version}.jar"
</argLine>
<properties>
<property>
<name>listener</name>
<value>io.qameta.allure.junit4.AllureJunit4</value>
</property>
</properties>
</configuration>
<dependencies>
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjweaver</artifactId>
<version>${aspectj.version}</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>
Instead, if it is not really necessary (because there is any easier way on gradle to proceed) can someone give a clue on how to do it?
Have a look at the documentation on testing Java & JVM projects in Gradle.
It should answer the basic questions around setting up testing in a Gradle project.
However if you are using specific features of the maven-surefire-plugin that you fail to replicate, please amend your question with more specific elements.

Maven - differences between dependencies inside plugin and outside?

I've come across some sample code which specifies dependencies inside the plugin tag like this :
<build>
<plugins>
<plugin>
<dependencies>
<dependency>
<groupId>org.hsqldb</groupId>
<artifactId>hsqldb</artifactId>
<version>2.2.8</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>
It look strange to me because mostly I see people put the dependencies tag outside the build tag.
When you add <dependency> to project it is available to that project depending on its scope (compile, test, runtime, etc)
But when you add <dependency> inside plugin's execution you are making that artifact available to that plugin in classpath at runtime
For example:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<version>2.1</version>
<executions>
<execution>
<id>check my sources</id>
<goals>
<goal>check</goal>
</goals>
<phase>compile</phase>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>checkstyle</groupId>
<artifactId>checkstyle</artifactId>
<version>4.4</version>
</dependency>
</dependencies>
</plugin>
in this snippet checkstyle:checkstyle:4.4 is being available to maven-checkstyle-plugin at runtime
Read More
How to override a plugin's dependency in Maven

For Selenium WebDriver - Maven and initial pom.xml configuration

I am new for Selenium Webdriver. When I start with the tool I came to know there are two things necessary to start with: Maven and pom.xml. But I didn't find the details on these things. Could anyone let know what is the meaning of these files and how do I create them.
Also I would be thankful, if someone could share some knowledge on the Selenium WebDriver like how do I start with the tool, and how to write a scripts - I have Java knowledge, so I can prefer to that language.
Thanks in advance :) awaiting to learn about the tools :)
Maven and it's pom.xml are not a must (but a recommended solution).
Their role in the process is just to add the selenium jar to your project.
You can manually add the Selenium jar file to your project by downloading the jar from http://docs.seleniumhq.org/download/ and adding it to your classpath.
OR,
https://code.google.com/p/selenium/downloads/list?can=1&q=&colspec=Filename+Summary+Uploaded+ReleaseDate+Size+DownloadCount
Selenium site has also the relevant documentation to get you started - http://docs.seleniumhq.org/docs/03_webdriver.jsp
Maven: http://maven.apache.org/
I would recommend starting with a pom.xml that looks like this. You will have to manually create the directories src/main/java, src/test/java, and src/test/resources, but after do so, if you run "mvn clean build", it will refresh and give you the proper perspective in Eclipse IDE. Maven can be confusing on a new project because it doesn't auto generate those directories. :
<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>SeleniumMavenExample</groupId>
<artifactId>SeleniumMavenExample</artifactId>
<version>0.0.1-SNAPSHOT</version>
<properties>
<selenium.version>2.39.0</selenium.version>
<maven.surefire.plugin.version>2.16</maven.surefire.plugin.version>
<testng.version>6.8.7</testng.version>
</properties>
<build>
<directory>target</directory>
<outputDirectory>target/classes</outputDirectory>
<finalName>${project.artifactId}-${project.version}</finalName>
<testOutputDirectory>target/test-classes</testOutputDirectory>
<sourceDirectory>src/main/java</sourceDirectory>
<testSourceDirectory>src/test/java</testSourceDirectory>
<resources>
<resource>
<directory>src/main/resources</directory>
</resource>
</resources>
<testResources>
<testResource>
<directory>src/test/resources</directory>
</testResource>
</testResources>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>${maven.surefire.plugin.version}</version>
<configuration>
<showSuccess>true</showSuccess>
<suiteXmlFiles>
<suiteXmlFile>src/test/resources/testng.xml</suiteXmlFile>
</suiteXmlFiles>
<configuration>
<systemPropertyVariables>
<build-name>${surefire.testng.build}</build-name>
</systemPropertyVariables>
<groups>${surefire.testng.groups}</groups>
<testFailureIgnore>true</testFailureIgnore>
</configuration>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>org.apache.metamodel</groupId>
<artifactId>MetaModel-full</artifactId>
<version>4.0.0-incubating</version>
</dependency>
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>${testng.version}</version>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>16.0.1</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<version>1.7.6</version>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>${selenium.version}</version>
</dependency>
<dependency>
<groupId>net.lightbody.bmp</groupId>
<artifactId>browsermob-proxy</artifactId>
<version>2.0-beta-9</version>
</dependency>
</dependencies>
</project>

Resources