Running test with PaxExam 3.x - TestNg - maven

Edited to simplify the example...
I'm migrating the system to Maven. I want to use PaxExam to run the test with TestNg.
I'm trying to run a simple test using PaxExam:
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>MyTest</groupId>
<artifactId>PaxExam</artifactId>
<version>0.0.2</version>
<packaging>jar</packaging>
<name>Prove PaxExam</name>
<properties>
<exam.version>3.3.0</exam.version>
<url.version>1.6.0</url.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>6.3.1</version>
</dependency>
<dependency>
<groupId>org.ops4j.pax.exam</groupId>
<artifactId>pax-exam-container-native</artifactId>
<version>${exam.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.ops4j.pax.exam</groupId>
<artifactId>pax-exam-testng</artifactId>
<version>${exam.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.ops4j.pax.exam</groupId>
<artifactId>pax-exam-link-mvn</artifactId>
<version>${exam.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.ops4j.pax.url</groupId>
<artifactId>pax-url-aether</artifactId>
<version>${url.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.felix</groupId>
<artifactId>org.apache.felix.framework</artifactId>
<version>4.0.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-core</artifactId>
<version>0.9.29</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>0.9.29</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.ow2.spec.ee</groupId>
<artifactId>ow2-jta-1.1-spec</artifactId>
<version>1.0.12</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
Java program:
package MyTest.PaxExam;
import static org.ops4j.pax.exam.CoreOptions.*;
import static org.testng.Assert.*;
import javax.inject.Inject;
import org.ops4j.pax.exam.Option;
import org.ops4j.pax.exam.Configuration;
import org.ops4j.pax.exam.ConfigurationFactory;
import org.ops4j.pax.exam.spi.reactors.PerClass;
import org.ops4j.pax.exam.testng.listener.PaxExam;
import org.ops4j.pax.exam.spi.reactors.ExamReactorStrategy;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleContext;
import org.testng.annotations.Listeners;
import org.testng.annotations.Test;
import ch.qos.logback.classic.*;
import org.slf4j.LoggerFactory;
#Listeners(PaxExam.class)
#ExamReactorStrategy(PerClass.class)
public class Prove {
#Inject
BundleContext bc;
#Configuration
public Option[] config() {
System.out.println("config() called");
return options(mavenBundle("org.testng","testng","6.3.1"));
}
#org.testng.annotations.Test
public void checkInject() {
System.out.println("checkInject() called");
assertNotNull(bc);
}
}
The results that I have, when I verify the test, are:
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building Prove PaxExam 0.0.2
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-resources-plugin:2.5:resources (default-resources) # PaxExam ---
[debug] execute contextualize
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory C:\users\dan\desktop\acf\MyTest2\src\main\resources
[INFO]
[INFO] --- maven-compiler-plugin:2.3.2:compile (default-compile) # PaxExam ---
[INFO] No sources to compile
[INFO]
[INFO] --- maven-resources-plugin:2.5:testResources (default-testResources) # PaxExam ---
[debug] execute contextualize
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 1 resource
[INFO]
[INFO] --- maven-compiler-plugin:2.3.2:testCompile (default-testCompile) # PaxExam ---
[INFO] Compiling 1 source file to C:\users\dan\desktop\acf\MyTest2\target\test-classes
[INFO]
[INFO] --- maven-surefire-plugin:2.10:test (default-test) # PaxExam ---
[INFO] Surefire report directory: C:\users\dan\desktop\acf\MyTest2\target\surefire-reports
-------------------------------------------------------
T E S T S
-------------------------------------------------------
Results :
Tests run: 0, Failures: 0, Errors: 0, Skipped: 0
[INFO]
[INFO] --- maven-jar-plugin:2.3.2:jar (default-jar) # PaxExam ---
[INFO] Building jar: C:\users\dan\desktop\acf\MyTest2\target\PaxExam-0.0.2.jar
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 2.246s
[INFO] Finished at: Fri Dec 06 16:33:14 CET 2013
[INFO] Final Memory: 15M/226M
[INFO] ------------------------------------------------------------------------
The container is not started, no test is run.

Not sure what you're trying to do. If you're trying to run OSGi tests with an embedded OSGi framework, don't use the exam-maven-plugin.
If you're trying to run plain old unit/integration tests communicating with an external OSGi application, you can use the exam-maven-plugin to launch that application in Pax Exam server mode, but then there's no need to use Pax Exam in your tests.

Finally!
According to the surefire plugin documention :
http://maven.apache.org/surefire/maven-surefire-plugin/examples/testng.html
As long as they are named using the defaults such as *Test.java they
will be run by Surefire as TestNG tests.
If you'd like to use a different naming scheme, you can change the
includes parameter, as discussed in the Inclusions and Exclusions of
Tests example.
My test class name did not start with Test nor end with Test. Changing the class name to TestProve.java solves the problem.
Thanks to hwellmann for his time.

Related

Maven project cucumber test builded but result is 0

When i use this command in terminal mvn test -Dcucumberoptions="--tags #Smoke my test result is 0 all the time. Here is my pom, test runner and feature classes;
pom.xml
<properties>
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
<aspectj.version>1.8.10</aspectj.version>
</properties>
<dependencies>
<!-- https://mvnrepository.com/artifact/io.rest-assured/rest-assured -->
<dependency>
<groupId>io.rest-assured</groupId>
<artifactId>rest-assured</artifactId>
<version>4.4.0</version>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-chrome-driver</artifactId>
<version>4.3.0</version>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>4.0.0-rc-2</version>
</dependency>
<!-- https://mvnrepository.com/artifact/junit/junit -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13.2</version>
</dependency>
<!-- https://mvnrepository.com/artifact/io.cucumber/cucumber-java -->
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-java</artifactId>
<version>7.5.0</version>
</dependency>
<!-- https://mvnrepository.com/artifact/info.cukes/cucumber-junit -->
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-junit</artifactId>
<version>7.5.0</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.hamcrest/hamcrest -->
<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest</artifactId>
<version>2.2</version>
</dependency>
<!-- https://mvnrepository.com/artifact/io.qameta.allure/allure-junit5 -->
<dependency>
<groupId>io.qameta.allure</groupId>
<artifactId>allure-junit5</artifactId>
<version>2.13.6</version>
</dependency>
<dependency>
<groupId>org.json</groupId>
<artifactId>json</artifactId>
<version>20160212</version>
</dependency>
<!-- https://mvnrepository.com/artifact/io.rest-assured/json-schema-validator -->
<dependency>
<groupId>io.rest-assured</groupId>
<artifactId>json-schema-validator</artifactId>
<version>4.3.0</version>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>5.9.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>5.9.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<version>5.9.0</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.2</version>
<configuration>
<includes>
**/TestRunner*.java
</includes>
</configuration>
</plugin>
</plugins>
</build>
</project>
TestRunner class for cucumber options
package cucumberOptions;
import io.cucumber.junit.Cucumber;
import io.cucumber.junit.CucumberOptions;
import org.junit.runner.RunWith;
#RunWith(Cucumber.class)
#CucumberOptions(
features = "src/test/java/features",
glue = {"Steps"}
)
public class TestRunner {
}
.feature file
#Smoke
Scenario: 5SH Share Privately
When I send share privately api
Then response share status code should be 201
And last my result
[INFO] Scanning for projects...
[INFO]
[INFO] ----------------< Automation:Automation >-----------------
[INFO] Building LifeboxAutomation 1.0-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) # Automation ---
[WARNING] Using platform encoding (Cp1252 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] Copying 7 resources
[INFO] Finished at: 2022-09-15T13:08:38+03:00
[INFO] ------------------------------------------------------------------------
mtc BackendApi mvn test -Dcucumberoptions="--tags #Smoke" in pwsh at 13:08:38
[INFO] Scanning for projects...
[INFO]
[INFO] ----------------< Automation:LifeboxAutomation >-----------------
[INFO] Building Automation 1.0-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) # Automation ---
[WARNING] Using platform encoding (Cp1252 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] Copying 7 resources
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) # Automation ---
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) # Automation ---
[WARNING] Using platform encoding (Cp1252 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] Copying 5 resources
[INFO]
[INFO] --- maven-compiler-plugin:3.1:testCompile (default-testCompile) # Automation ---
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] --- maven-surefire-plugin:2.22.2:test (default-test) # Automation ---
[INFO]
[INFO] -------------------------------------------------------
[INFO] T E S T S
[INFO]
[INFO] Results:
[INFO]
[INFO] Tests run: 0, Failures: 0, Errors: 0, Skipped: 0
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 3.056 s
[INFO] Finished at: 2022-09-15T13:20:17+03:00
[INFO] ------------------------------------------------------------------------
Thank you for your advice for now
Surefire normally automatically selects which test-framework provider to use based on the version of TestNG/JUnit present in your project's classpath.
You have both JUnit 5 and JUnit 4 on your classpath, so Surefire will pick JUnit 5 to run all tests. However you didn't include the JUnit Vintage engine so JUnit 5 will not execute JUnit 4 tests.
You're probably better of switching to JUnit 5 entirely though. Have a look at the cucumber-java-skeleton for that.

Spring Boot jar not works

I created simple telegram bot on Spring Boot and I am trying to deploy it to the server. So, to do this I need to create executable jar file. I built jar using mvn clean package, but it does not work. I can't run this jar from anywhere, except project root folder. When I run it from root folder everything works fine, otherwise I get an exception. I suspect that this strange behaviour is due to errors in dependencies. I've tried a lot of things, like change spring boot maven plugin's target, change jar to war, but nothing works. Is there any ideas how I can fix it and build jar correctly? Thanks for any help.
Project 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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.6.4</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<packaging>jar</packaging>
<groupId>com.example</groupId>
<artifactId>rf3dBot</artifactId>
<version>1.0</version>
<name>rf3dBot</name>
<description>rf3dBot</description>
<properties>
<java.version>17</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.telegram</groupId>
<artifactId>telegrambots-spring-boot-starter</artifactId>
<version>5.7.1</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-log4j</artifactId>
<version>1.3.8.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-configuration-processor</artifactId>
<version>2.6.4</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
build logs:
$ mvn clean package
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------< com.example:rf3dBot >-------------------------
[INFO] Building rf3dBot 1.0
[INFO] --------------------------------[ jar ]---------------------------------
[WARNING] The artifact org.slf4j:slf4j-log4j12:jar:1.7.36 has been relocated to org.slf4j:slf4j-reload4j:jar:1.7.36
[INFO]
[INFO] --- maven-clean-plugin:3.1.0:clean (default-clean) # rf3dBot ---
[INFO] Deleting C:\Users\Sergey\Desktop\rf3dBot\target
[INFO]
[INFO] --- maven-resources-plugin:3.2.0:resources (default-resources) # rf3dBot ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Using 'UTF-8' encoding to copy filtered properties files.
[INFO] Copying 1 resource
[INFO] Copying 755 resources
[INFO]
[INFO] --- maven-compiler-plugin:3.8.1:compile (default-compile) # rf3dBot ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 10 source files to C:\Users\Sergey\Desktop\rf3dBot\target\classes
[INFO]
[INFO] --- maven-resources-plugin:3.2.0:testResources (default-testResources) # rf3dBot ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Using 'UTF-8' encoding to copy filtered properties files.
[INFO] skip non existing resourceDirectory C:\Users\Sergey\Desktop\rf3dBot\src\test\resources
[INFO]
[INFO] --- maven-compiler-plugin:3.8.1:testCompile (default-testCompile) # rf3dBot ---
[INFO] No sources to compile
[INFO]
[INFO] --- maven-surefire-plugin:2.22.2:test (default-test) # rf3dBot ---
[INFO] No tests to run.
[INFO]
[INFO] --- maven-jar-plugin:3.2.2:jar (default-jar) # rf3dBot ---
[INFO] Building jar: C:\Users\Sergey\Desktop\rf3dBot\target\rf3dBot-1.0.jar
[INFO]
[INFO] --- spring-boot-maven-plugin:2.6.4:repackage (repackage) # rf3dBot ---
[INFO] Replacing main artifact with repackaged archive
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 28.204 s
[INFO] Finished at: 2022-03-26T00:22:44+03:00
[INFO] ------------------------------------------------------------------------
exception (it's not so important, because in the intellij idea application works completely fine)
try
starting your app with a specified profile.
error in image shows it gives null pointer exception in RandomMemeBuilder.
U should look this class and check what is causing null pointer execption. or post more code for this class.

"mvn test" runs testng instead of Junit

When I run "mvn test" no tests are run and in the report I see that testng was somehow invoked - how is this possible ?
Ultimately mvn does not run any test.
Could someone help ? I dont have any testng library in the code. Maybe pom is incorrect or something is missing ?
Ultimately mvn does not run any test.
Could someone help ? I dont have any testng library in the code. Maybe pom is incorrect or something is missing ?
After running "mvn test" it invokes test ng:
Running cucumber.Options.TestRunner
Configuring TestNG with: org.apache.maven.surefire.testng.conf"
My pom looks like this:
pom.xml
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<properties>
</properties>
</properties>
<dependencies>
<!-- https://mvnrepository.com/artifact/junit/junit -->
<!-- https://mvnrepository.com/artifact/io.cucumber/cucumber-java -->
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-java</artifactId>
<version>6.9.1</version>
</dependency>
<!-- https://mvnrepository.com/artifact/io.cucumber/cucumber-junit -->
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-junit</artifactId>
<version>6.9.1</version>
<scope>test</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/io.rest-assured/rest-assured -->
<dependency>
<groupId>io.rest-assured</groupId>
<artifactId>rest-assured</artifactId>
<version>4.3.3</version>
<scope>test</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/com.fasterxml.jackson.core/jackson-databind -->
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.12.3</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache.maven.plugins/maven-surefire-plugin -->
<dependency>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.2</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.testng/testng -->
</dependencies>
</project>
When I run mvn test command I get
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building APIframwork 0.0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) # APIframwork ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory C:\Users\Test\eclipse-workspace\APIframwork\src\main\resources
[INFO]
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) # APIframwork ---
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) # APIframwork ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory C:\Users\Test\eclipse-workspace\APIframwork\src\test\resources
[INFO]
[INFO] --- maven-compiler-plugin:3.1:testCompile (default-testCompile) # APIframwork ---
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] --- maven-surefire-plugin:2.12.4:test (default-test) # APIframwork ---
[INFO] Surefire report directory: C:\Users\Test\eclipse-workspace\APIframwork\target\surefire-reports
-------------------------------------------------------
T E S T S
-------------------------------------------------------
Running cucumber.Options.TestRunner
Configuring TestNG with: org.apache.maven.surefire.testng.conf.TestNG652Configurator#7006c658
Tests run: 0, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 1.506 sec
Results :
Tests run: 0, Failures: 0, Errors: 0, Skipped: 0
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 11.381 s
[INFO] Finished at: 2021-10-13T15:12:56+02:00
[INFO] Final Memory: 15M/180M
[INFO] ------------------------------------------------------------------------```

How to test methods in a java project using a maven junit5 framework project in eclipse

I created a new maven junit5 framework project to test existing java projects. I added the java project in build path of the newly created maven junit5 framework project. I right clicked the method I wanted to add junit test case for and selected new junit test case and changed the source folder to the new maven junit5 framework project src directory and left the rest of the options as default. Created the junit test and ran the test as a unit test without any issues(screenshot below). Running the same test using maven getting the error below. I added the surefire plugin in pom(below) but still getting the error below. Using eclipse.
-------------------------------------------------------------------------------
Test set: com.build.VersionInfoTest
-------------------------------------------------------------------------------
Tests run: 1, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 0.003 s <<< FAILURE! - in com.build.VersionInfoTest
com.build.VersionInfoTest Time elapsed: 0.002 s <<< ERROR!
java.lang.NoClassDefFoundError: Lcom/build/VersionInfo;
Caused by: java.lang.ClassNotFoundException: com.build.VersionInfo
<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>UnitTesting</groupId>
<artifactId>com.unit.testing</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>com.unit.testing</name>
<description>Junit Tests</description>
<packaging>jar</packaging>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<junit.jupiter.version>5.5.2</junit.jupiter.version>
<junit.platform.version>1.5.2</junit.platform.version>
</properties>
<dependencies>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>${junit.jupiter.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-runner</artifactId>
<version>${junit.platform.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>${junit.jupiter.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.2</version>
</plugin>
</plugins>
</build>
</project>
Update : I cleaned up the pom(below) but now no tests discovered? when I run the project with junit the test is discovered?
[INFO] Scanning for projects...
[INFO]
[INFO] --------------< UnitTesting:com.unit.testing >---------------
[INFO] Building com.unit.testing 1.0-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------- -----------
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) # com.unit.testing ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 0 resource
[INFO]
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) # com.unit.testing ---
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] --- maven-resources-plugin:2.6:testResources (default- testResources) # com.unit.testing ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 0 resource
[INFO]
[INFO] --- maven-compiler-plugin:3.1:testCompile (default-testCompile) # com.unit.testing ---
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] --- maven-surefire-plugin:3.0.0-M4:test (default-test) # com.unit.testing ---
[INFO]
[INFO] -------------------------------------------------------
[INFO] T E S T S
[INFO] -------------------------------------------------------
[INFO] Running com.build.VersionInfoTest
[INFO] Tests run: 0, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.002 s - in com.build.VersionInfoTest
[INFO]
[INFO] Results:
[INFO]
[INFO] Tests run: 0, Failures: 0, Errors: 0, Skipped: 0
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1.955 s
[INFO] Finished at: 2020-03-09T10:00:22-04:00
[INFO] ------------------------------------------------------------------------
<packaging>jar</packaging>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>${maven.compiler.source}</maven.compiler.target>
<junit.jupiter.version>5.6.0</junit.jupiter.version>
</properties>
<dependencies>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<version>${junit.jupiter.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M4</version>
</plugin>
</plugins>
</build>
package com.dbb.build
import static org.junit.jupiter.api.Assertions.*;
import org.junit.jupiter.api.Test;
import com.dbb.build.VersionInfo;
class VersionInfoTest {
VersionInfo versionInfo = VersionInfo.getInstance();
#Test
void getVersion() {
String version = versionInfo.getVersion();
System.out.println(version);
assertNotNull(versionInfo.getVersion(), "expected a return value of"+version+"but was null");
}
}
UPDATE:
[INFO] --- maven-resources-plugin:2.6:testResources (default- testResources) # DBB-Unit-Testing ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 0 resource
[INFO]
[INFO] --- maven-compiler-plugin:3.8.1:testCompile (default-testCompile) # DBB-Unit-Testing ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 1 source file to /Unit-Testing/target/test-classes
[INFO] -------------------------------------------------------------
[ERROR] COMPILATION ERROR :
[INFO] -------------------------------------------------------------
[ERROR] /Unit-Testing/src/test/java/com/VersionInfoTest.java:[7,25] cannot find symbol
symbol: class VersionInfo
location: package com.build
[ERROR] /Unit-Testing/src/test/java/com/build/VersionInfoTest.java: [11,9] cannot find symbol
symbol: class VersionInfo
location: class com.build.TestVersionInfo
[ERROR] /Unit-Testing/src/test/java/com/ /build/VersionInfoTest.java: [11,35] cannot find symbol
symbol: variable VersionInfo
location: class com.build.TestVersionInfo
[INFO] 3 errors
Solution: Using junit-platform-console-standalone-1.5.2.jar and run units via command line. Looks like if we have a non maven project junit-platform-console-standalone seems to be a better option.
Here is a sample of some of my pom I use with Maven 3.x and tests executed as expected with JUnit 5 in Eclipse but also from command line:
Don't add too many Juniper artifacts, some will create some side effect if present.
Note also the updated version of the surefire plugin with had some issue in the past with JUnit5
<properties>
<!-- ensure proper encoding of source and resource files in the project -->
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<junit-5.version>5.6.0</junit-5.version>
</properties>
<dependencies>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<version>${junit-5.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M4</version>
</plugin>
</plugins>
</build>
UPDATE:
You can find a small example here: https://gist.github.com/asa-git/8e34bbc51b5fcb09b7fab3efdaaa73c9
Note that I am using maven version 3.6.3 and a JDK 8.
Furthermore, when running from the command line on windows (but likewise on other systems), you need to make sure your JDK is on your path before any other JSE installed on your system.

[Cucumber][JVM][Maven]Tests dosen't run from command line through maven

I am running tests using java, cucumber with Maven.
I am using Eclipse IDE. Also the pom.xml has cucumber dependencies.
I am running tests in two ways.
From Eclipse IDE: I run tests as Junit tests and the test results are successful.
2: From command promt: My test failed and below is the result.
Here is the Pom.xml:
http://maven.apache.org/xsd/maven-4.0.0.xsd">
4.0.0
<groupId>CCIRA_Test_Auto</groupId>
<artifactId>CCIRA_Test_Auto</artifactId>
<version>0.0.1</version>
<packaging>jar</packaging>
<name>CCIRA_Test_Auto</name>
<properties>
<cucumber.version>1.2.0</cucumber.version>
<picocontainer.version>2.15</picocontainer.version>
</properties>
<dependencies>
<dependency>
<groupId>info.cukes</groupId>
<artifactId>cucumber-java</artifactId>
<version>${cucumber.version}</version>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>4.3.5</version>
</dependency>
<dependency>
<groupId>info.cukes</groupId>
<artifactId>cucumber-testng</artifactId>
<version>${cucumber.version}</version>
</dependency>
<dependency>
<groupId>info.cukes</groupId>
<artifactId>cucumber-junit</artifactId>
<version>${cucumber.version}</version>
</dependency>
<dependency>
<groupId>com.codeborne</groupId>
<artifactId>phantomjsdriver</artifactId>
<version>1.2.1</version>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>2.44.0</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.17</version>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
<version>3.9</version>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi</artifactId>
<version>3.11-beta3</version>
</dependency>
<dependency>
<groupId>xml-apis</groupId>
<artifactId>xml-apis</artifactId>
<version>2.0.2</version>
</dependency>
<dependency>
<groupId>xerces</groupId>
<artifactId>xercesImpl</artifactId>
<version>2.8.0</version>
</dependency>
</dependencies>
<build>
<pluginManagement>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
My Runner Test:
package ccira.helpers;
import org.junit.runner.RunWith;
import org.testng.annotations.Test;
import cucumber.api.CucumberOptions;
import cucumber.api.junit.Cucumber;
#RunWith(Cucumber.class)
#CucumberOptions(
features = "C:/Users/rah/Documents/workspace/CCIRA_auto/src/ressouces/features",
tags = {"#Personne"},
glue={"ccira.stepDefinitions"},
plugin ={
"pretty",
"html:results/cucumber",
"json:results/cucumber.json",
"junit:results/cucumber.xml",
}
)
public class RunnerTest {
}
My output console :
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building CCIRA_Test_Auto 0.0.1
[INFO] ------------------------------------------------------------------------
[WARNING] The artifact xml-apis:xml-apis:jar:2.0.2 has been relocated to xml-apis:xml-apis:jar:1.0.b2
[INFO]
[INFO] --- maven-resources-plugin:2.5:resources (default-resources) # CCIRA_Test_Auto ---
[debug] execute contextualize
[WARNING] Using platform encoding (Cp1252 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] skip non existing resourceDirectory C:\Users\rah\Documents\workspace\CCIRA_Test_Auto\src\main\resources
[INFO]
[INFO] --- maven-compiler-plugin:2.3.2:compile (default-compile) # CCIRA_Test_Auto ---
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] --- maven-resources-plugin:2.5:testResources (default-testResources) # CCIRA_Test_Auto ---
[debug] execute contextualize
[WARNING] Using platform encoding (Cp1252 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] skip non existing resourceDirectory C:\Users\rah\Documents\workspace\CCIRA_Test_Auto\src\test\resources
[INFO]
[INFO] --- maven-compiler-plugin:2.3.2:testCompile (default-testCompile) # CCIRA_Test_Auto ---
[INFO] No sources to compile
[INFO]
[INFO] --- maven-surefire-plugin:2.10:test (default-test) # CCIRA_Test_Auto ---
[INFO] Surefire report directory: C:\Users\rah\Documents\workspace\CCIRA_Test_Auto\target\surefire-reports
-------------------------------------------------------
T E S T S
-------------------------------------------------------
Results :
Tests run: 0, Failures: 0, Errors: 0, Skipped: 0
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 10.051s
[INFO] Finished at: Mon Dec 05 09:30:10 GMT 2016
[INFO] Final Memory: 7M/62M
[INFO] ------------------------------------------------------------------------
The dependency
org.slf4j.impl.StaticLoggerBinder
is not defined in your pom.xml file. However it is defined on your build path in your Eclipse project. Placing one (and only one) of slf4j-nop.jar, slf4j-simple.jar, slf4j-log4j12.jar, slf4j-jdk14.jar or logback-classic.jar on the class path should solve the problem.
I would add a dependency in your pom.xml, perhaps something like this:
<!-- https://mvnrepository.com/artifact/org.slf4j/slf4j-simple -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<version>1.7.21</version>
</dependency>
EDIT
A less good but viable alternative is to utilize the Surefire plugin's additionalClasspathElements element "to add custom resources/JARs to your classpath. This will be treated as an absolute file system path, so you may want use ${basedir} or another property combined with a relative path. Note that additional classpath elements are added to the end of the classpath, so you cannot use these to override project dependencies or resources."
I said less good because it is better to track as dependencies in your pom.xml where if you update one dependency to a later version you can see the other dependencies that also have to be updated. You might overlook jars specified down in the surefire plugin.
Try to run using the below command from command prompt
mvn clean test -Dcucumber.options="src/resources/features --tags ##Personne"

Resources