Groovy script is not executing in the Camel (Project) - intellij-idea

Scenario: Just wanted to transfer the files from one location to another
location using camel and groovy script
Problem: I am not seeing any errors in the console, but how can we make
sure script is executing.
Sample MainApp Program :
class MainApp {
static void main(String... args) {
def camelContext = new DefaultCamelContext()
println("printing something in the console MainApp")
camelContext.addRoutes( new RouteBuilder() {
#Override
void configure() {
println("Printing some thing before queue")
from("Test").to("Test")
println("printing something after queue")
}
})
//camelContext.start()
// Thread.sleep(10000)
// camelContext.stop()
}
}
Output :
sampling ...
include patterns:
org\.apache\.camel\..*
exclude patterns:
printing something in the console MainApp
Printing some thing before queue
printing something after queue
Process finished with exit code 0
Pom.xml file: If you could observe, below file contains all the jar files which are related to groovy and camel.. (I am thinking there are problems with pom file.. please let me know if you are finding out the same)
<?xml version="1.0" encoding="UTF-8"?>
<!--
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to You under the Apache License, Version 2.0
(the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<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>SampleCamelProject</groupId>
<artifactId>camel-example-groovy</artifactId>
<packaging>jar</packaging>
<version>0.0.0</version>
<name>SampleCamelProject</name>
<properties>
<maven-compiler-plugin-version>3.8.0</maven-compiler-plugin-version>
<maven-resources-plugin-version>3.1.0</maven-resources-plugin-version>
<maven-eclipse-plugin-version>2.10</maven-eclipse-plugin-version>
<exec-maven-plugin-version>1.6.0</exec-maven-plugin-version>
<camel-core-version>2.13.3</camel-core-version>
<camel-groovy-dsl-version>2.19.5</camel-groovy-dsl-version>
<camel-jetty-version>1.6.0</camel-jetty-version>
<log4j-api-version>2.11.1</log4j-api-version>
<log4j-core-version>2.11.1</log4j-core-version>
<log4j-slf4j-version>2.11.1</log4j-slf4j-version>
</properties>
<description>A Camel route using Groovy DSL</description>
<dependencies>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-core</artifactId>
<version>${camel-core-version}</version>
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-groovy-dsl</artifactId>
<version>${camel-groovy-dsl-version}</version>
</dependency>
<!-- used for jetty -->
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-jetty</artifactId>
<version>${camel-jetty-version}</version>
</dependency>
<!-- logging -->
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
<version>${log4j-api-version}</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>${log4j-core-version}</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-slf4j-impl</artifactId>
<version>${log4j-slf4j-version}</version>
</dependency>
</dependencies>
<build>
<defaultGoal>install</defaultGoal>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>${maven-resources-plugin-version}</version>
<configuration>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>${maven-compiler-plugin-version}</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
<compilerId>groovy-eclipse-compiler</compilerId>
<!-- set verbose to be true if you want lots of uninteresting messages -->
<!-- <verbose>true</verbose> -->
</configuration>
<dependencies>
<dependency>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy-eclipse-compiler</artifactId>
<version>2.9.2-01</version>
<exclusions>
<exclusion>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy-eclipse-batch</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy-eclipse-batch</artifactId>
<version>2.4.3-01</version>
</dependency>
</dependencies>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-eclipse-plugin</artifactId>
<version>${maven-eclipse-plugin-version}</version>
<configuration>
<additionalProjectnatures>
<projectnature>org.eclipse.jdt.groovy.core.groovyNature</projectnature>
</additionalProjectnatures>
<classpathContainers>
<classpathContainer>org.eclipse.jdt.launching.JRE_CONTAINER</classpathContainer>
<classpathContainer>GROOVY_DSL_SUPPORT</classpathContainer>
</classpathContainers>
</configuration>
</plugin>
<!-- Allows the example to be run via 'mvn compile exec:java' -->
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>${exec-maven-plugin-version}</version>
<configuration>
<mainClass>org.apache.camel.MainAppTest</mainClass>
<includePluginDependencies>false</includePluginDependencies>
</configuration>
</plugin>
</plugins>
</build>
<profiles>
<profile>
<id>jdk9-build</id>
<activation>
<jdk>9</jdk>
</activation>
<build>
<plugins>
<plugin>
<!--Skip compile on Java 9 https://issues.apache.org/jira/browse/CAMEL-10905 -->
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<executions>
<execution>
<id>default-compile</id>
<phase>none</phase>
</execution>
<execution>
<id>default-testCompile</id>
<phase>none</phase>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>
</project>
Above same app I executed in java: I am getting an error(As expected)
Caused by: org.apache.camel.FailedToCreateRouteException: Failed to
create route route1: Route(route1)[[From[Test]] -> [To[Test]]] because
of No endpoint could be found for: Test, please check your classpath
contains the needed Camel component jar.
The same thing I am expecting from groovy script .. please suggest me if
I am missing anything.

I am giving myself an answer to the above question. I haven't thought of executing a simple way of writing Groovy script. I have tried below code and it is working.
package org.apache.camel
import org.apache.camel.impl.*
import org.apache.camel.builder.*
def camelContext = new DefaultCamelContext()
camelContext.addRoutes(new RouteBuilder() {
def void configure() {
from("Test")
.to("Test")
}
})
camelContext.start()
addShutdownHook{ camelContext.stop() }
synchronized(this){ this.wait() }
Maybe we can make execute above-posted question with the groovy script .. but I am not seeing any console logs when an error occurs. Please suggest me on this .. I really would like to know how the process executes .. thanks a lot advance.

Related

How do I run the Google Cloud Functions example project KotlinHelloWorld.kt in IntelliJ on Windows 11?

I am developing a Kotlin backend that is going to run in Google Cloud Functions. I am unsing the example code that Google has given, however I do not know how I can run the code on my local Windows 11 machine with IntelliJ.
There is no option to run the file. Even when I go to "Run/Debug Configurations" I cannot select the KotlinHelloWorld.kt file as my main class to run.
Below is the sample code given from https://cloud.google.com/functions/docs/concepts/jvm-langs.
src/main/kotlin/functions/KotlinHelloWorld.kt
/*
* Copyright 2020 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package functions
// [START functions_helloworld_get]
import com.google.cloud.functions.HttpFunction
import com.google.cloud.functions.HttpRequest
import com.google.cloud.functions.HttpResponse
import java.io.IOException
import java.util.logging.Logger
class HelloWorld : HttpFunction {
// Simple function to return "Hello World"
#Throws(IOException::class)
override fun service(request: HttpRequest, response: HttpResponse) {
response.writer.write("Hello World!")
}
}
// [END functions_helloworld_get]
pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright 2020 Google LLC
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<!-- [START functions_kotlin_pom] -->
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.example.cloud.functions</groupId>
<artifactId>functions-kotlin-hello-world</artifactId>
<!-- [END functions_kotlin_pom] -->
<parent>
<groupId>com.google.cloud.samples</groupId>
<artifactId>shared-configuration</artifactId>
<version>1.2.0</version>
</parent>
<!-- [START functions_kotlin_pom] -->
<properties>
<maven.compiler.target>11</maven.compiler.target>
<maven.compiler.source>11</maven.compiler.source>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<kotlin.version>1.6.21</kotlin.version>
</properties>
<dependencies>
<!-- Required for Function primitives -->
<dependency>
<groupId>com.google.cloud.functions</groupId>
<artifactId>functions-framework-api</artifactId>
<version>1.0.4</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-stdlib-jdk8</artifactId>
<version>${kotlin.version}</version>
</dependency>
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-test</artifactId>
<version>${kotlin.version}</version>
<scope>test</scope>
</dependency>
<!-- [END functions_kotlin_pom] -->
<!-- The following dependencies are only required for testing -->
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<version>4.5.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.google.truth</groupId>
<artifactId>truth</artifactId>
<version>1.1.3</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava-testlib</artifactId>
<version>31.1-jre</version>
<scope>test</scope>
</dependency>
<!-- [START functions_kotlin_pom] -->
</dependencies>
<build>
<plugins>
<plugin>
<!--
Google Cloud Functions Framework Maven plugin
This plugin allows you to run Cloud Functions Java code
locally. Use the following terminal command to run a
given function locally:
mvn function:run -Drun.functionTarget=your.package.yourFunction
-->
<groupId>com.google.cloud.functions</groupId>
<artifactId>function-maven-plugin</artifactId>
<version>0.10.1</version>
<configuration>
<functionTarget>functions.HelloWorld</functionTarget>
</configuration>
</plugin>
<plugin>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-maven-plugin</artifactId>
<version>${kotlin.version}</version>
<executions>
<execution>
<id>compile</id>
<phase>compile</phase>
<goals>
<goal>compile</goal>
</goals>
<configuration>
<sourceDirs>
<source>src/main/kotlin</source>
</sourceDirs>
</configuration>
</execution>
<execution>
<id>test-compile</id>
<phase>test-compile</phase>
<goals>
<goal>test-compile</goal>
</goals>
</execution>
</executions>
<configuration>
<jvmTarget>1.8</jvmTarget>
</configuration>
</plugin>
<!-- [END functions_kotlin_pom] -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M7</version>
<configuration>
<skipTests>${skipTests}</skipTests>
<reportNameSuffix>sponge_log</reportNameSuffix>
<trimStackTrace>false</trimStackTrace>
</configuration>
</plugin>
<!-- [START functions_kotlin_pom] -->
</plugins>
</build>
</project>
<!-- [END functions_kotlin_pom] -->

Cucumber runner file is not running any Tests

I have checked the related questions, but couldn't find any answer for my problem.
I am trying to set up cucumber framework from scratch.
I set up the POM, test runner, a feature file and related step definitions.
But when I run the test, there is no error but none of the test runs. I tried giving glue also in my runner file. Its not running from intellij as well as from command line.
Giving all the files for reference. Please see if anybody is able to point the error I am making?
POM
<?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.demo</groupId>
<artifactId>TestCucumber</artifactId>
<version>1.0-SNAPSHOT</version>
<name>TestCucumber</name>
<!-- FIXME change it to the project's website -->
<url>http://www.example.com</url>
<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>
<cucumber.version>7.2.3</cucumber.version>
<maven-cucumber-reporting.version>5.6.1</maven-cucumber-reporting.version>
<project.name>TestCucumber</project.name>
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>net.masterthought</groupId>
<artifactId>cucumber-reporting</artifactId>
<version>${maven-cucumber-reporting.version}</version>
</dependency>
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-core</artifactId>
<version>${cucumber.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-junit</artifactId>
<version>${cucumber.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-java</artifactId>
<version>${cucumber.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>5.4.0</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>net.masterthought</groupId>
<artifactId>maven-cucumber-reporting</artifactId>
<version>${maven-cucumber-reporting.version}</version>
<executions>
<execution>
<id>execution-dwp-employment-income-api</id>
<goals>
<goal>generate</goal>
</goals>
<!-- report generation is happening at this phase, so please dont change-->
<phase>integration-test</phase>
<configuration>
<projectName>${project.name}</projectName>
<skip>false</skip>
<!-- output directory for the generated report -->
<outputDirectory>${project.build.directory}/jsonReports/reports</outputDirectory>
<!-- optional, defaults to outputDirectory if not specified -->
<inputDirectory>${project.build.directory}/jsonReports</inputDirectory>
<jsonFiles>
<!-- supports wildcard or name pattern -->
<param>**/*.json</param>
</jsonFiles>
<mergeFeaturesById>false</mergeFeaturesById>
<!-- optional, set true to get a final report with latest results of the same test from different test runs -->
<mergeFeaturesWithRetest>false</mergeFeaturesWithRetest>
<!-- optional, set true to fail build on test failures -->
<checkBuildResult>false</checkBuildResult>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
Runner File
import io.cucumber.junit.Cucumber;
import io.cucumber.junit.CucumberOptions;
import org.junit.runner.RunWith;
#RunWith(Cucumber.class)
#CucumberOptions(
features = "src/test/resources/features",
tags = "#Test",
monochrome = true,
plugin = {"json:target/cucumber.json"}
)
public class CucumberTestDebugger {
}
Feature file
#Test
Feature: As user I want to Validate the feature
Scenario : Scenario 1 for the Feature
Given A sample record is present
Step definition
import io.cucumber.java.en.Given;
public class Feature1Step {
#Given("A sample record is present")
public void aSampleScenario() {
System.out.println("RECORD IS PRESENT");
}
}
Even if I just run the feature file for which step definition is not defined, that scenario also doesn't run. Usually it should give error for undefined steps in feature. It just shows -
C:\Users\myname\Java\jdk8\bin\java.exe -C:/Users/myname/IdeaProjects/TestCucumber/src/test/resources/features/Validate.feature
Testing started at 16:34 ...
0 Scenarios
0 Steps
0m0.324s
Thanks in advance!!!
Aggghhhhh..... I had an extra space after Scenario.
Silly mistake !!! Took hours
**Before**
Scenario : Scenario 1 for the Feature
**After**
Scenario: Scenario 1 for the Feature

Selenium (Eclipse) - feature file - step is not highlighted if step definition is undefined

I am very new to Selenium and Cucumber.
I am asking for your kind advice.
My problem is: Feature file - step is not highlighted, not showing warning messages if step definition is undefined.
My Feature file:
[![enter image description here][1]][1]
My runner:
[![enter image description here][2]][2]
Maven dependencies:
[![enter image description here][3]][3]
My pom.xml:
<?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>linkedlearning</groupId>
<artifactId>Mycucumbercourse</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>Mycucumbercourse</name>
<!-- FIXME change it to the project's website -->
<url>http://www.example.com</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<java.version>1.8</java.version>
<junit.version>4.11</junit.version>
<cucumber.version>4.2.5</cucumber.version>
<maven.compiler.version>3.3</maven.compiler.version>
<maven.compiler.source>1.7</maven.compiler.source>
<maven.compiler.target>1.7</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-java</artifactId>
<version>${cucumber.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-junit</artifactId>
<version>${cucumber.version}</version>
<scope>test</scope>
</dependency>
<!-- hamcrest dependency required in order to be able to run test using maven (command: mvn test) -->
<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest</artifactId>
<version>2.2</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<pluginManagement><!-- lock down plugins versions to avoid using Maven defaults (may be moved to parent pom) -->
<plugins>
<!-- clean lifecycle, see https://maven.apache.org/ref/current/maven-core/lifecycles.html#clean_Lifecycle -->
<plugin>
<artifactId>maven-clean-plugin</artifactId>
<version>3.1.0</version>
</plugin>
<!-- default lifecycle, jar packaging: see https://maven.apache.org/ref/current/maven-core/default-bindings.html#Plugin_bindings_for_jar_packaging -->
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>3.0.2</version>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.1</version>
</plugin>
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<version>3.0.2</version>
</plugin>
<plugin>
<artifactId>maven-install-plugin</artifactId>
<version>2.5.2</version>
</plugin>
<plugin>
<artifactId>maven-deploy-plugin</artifactId>
<version>2.8.2</version>
</plugin>
<!-- site lifecycle, see https://maven.apache.org/ref/current/maven-core/lifecycles.html#site_Lifecycle -->
<plugin>
<artifactId>maven-site-plugin</artifactId>
<version>3.7.1</version>
</plugin>
<plugin>
<artifactId>maven-project-info-reports-plugin</artifactId>
<version>3.0.0</version>
</plugin>
</plugins>
</pluginManagement>
</build>
</project>
I tried to investigate myself and find that import io.cucumber.junit.CucumberOptions; in combination with stepNotifications = true may help. However when I try to add it I am getting: "The import io.cucumber.junit cannot be resolved". Looking forward for your kind advice.
[1]: https://i.stack.imgur.com/KcrQN.png
[2]: https://i.stack.imgur.com/t2h9a.png
[3]: https://i.stack.imgur.com/n2gFr.png
I found an answer here:
Step Definition detection only works when project is configured as cucumber project.- Virtual Machine
Generally speaking:
If the step definition is not happened and the feature file does not highlight undefined steps with amber color that means that the project is not converted as a cucumber project.
Do the following:
In order to convert the project as a cucumber project do the following: Right-click on your project from the Project Explorer > Configure > Convert as Cucumber Project.
Ensure option Enable Step Definitions Glue Detection is checked in Window > Preferences > Cucumber

Intellij Create Test missing JUnit

I try to create an test class and test it using JUnit, but in my Intellij is missing JUnit library.
What I need to do to have at library option with JUnit?
Add junit-jupiter artifact in Maven
If using Apache Maven to configure your project, and writing JUnit 5 Jupiter to write you tests, add a dependency to your project.
JUnit 5.4 simplified things by providing this new Maven artifact, junit-jupiter. This one aggregate artifact provides all you need to write and run JUnit 5 tests. Previous to 5.4, you had to add multiple artifacts — confusing and messy.
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<version>5.5.0-M1</version>
<scope>test</scope>
</dependency>
Here is an example, an entire POM file. I started an app using the maven-archetype-quickstart artifact. Next I changed all the versions numbers to the latest, as of this week shown here. Lastly, I replaced the old JUnit 4 dependency with the new JUnit 5 dependency.
<?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>work.basil.example</groupId>
<artifactId>method-lister</artifactId>
<version>1.0-SNAPSHOT</version>
<name>method-lister</name>
<!-- FIXME change it to the project's website -->
<url>http://www.example.com</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>12</maven.compiler.source>
<maven.compiler.target>12</maven.compiler.target>
</properties>
<dependencies>
<!--<dependency>-->
<!-- <groupId>junit</groupId>-->
<!-- <artifactId>junit</artifactId>-->
<!-- <version>4.11</version>-->
<!-- <scope>test</scope>-->
<!--</dependency>-->
<!-- https://mvnrepository.com/artifact/org.junit.jupiter/junit-jupiter -->
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<version>5.5.0-M1</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<pluginManagement><!-- lock down plugins versions to avoid using Maven defaults (may be moved to parent pom) -->
<plugins>
<!-- clean lifecycle, see https://maven.apache.org/ref/current/maven-core/lifecycles.html#clean_Lifecycle -->
<plugin>
<artifactId>maven-clean-plugin</artifactId>
<version>3.1.0</version>
</plugin>
<!-- default lifecycle, jar packaging: see https://maven.apache.org/ref/current/maven-core/default-bindings.html#Plugin_bindings_for_jar_packaging -->
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>3.1.0</version>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M3</version>
</plugin>
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<version>3.1.1</version>
</plugin>
<plugin>
<artifactId>maven-install-plugin</artifactId>
<version>3.0.0-M1</version>
</plugin>
<plugin>
<artifactId>maven-deploy-plugin</artifactId>
<version>3.0.0-M1</version>
</plugin>
<!-- site lifecycle, see https://maven.apache.org/ref/current/maven-core/lifecycles.html#site_Lifecycle -->
<plugin>
<artifactId>maven-site-plugin</artifactId>
<version>3.7.1</version>
</plugin>
<plugin>
<artifactId>maven-project-info-reports-plugin</artifactId>
<version>3.0.0</version>
</plugin>
</plugins>
</pluginManagement>
</build>
</project>
JUnit plugins
Be sure the IntelliJ plugin for JUnit is installed and enabled. Verify the checkmark is checked, meaning enabled. (You can disable unneeded plugins to save memory and launch time.)
Generate Test dialog
Your IntelliJ 2019.1 dialog for Generate > Test… should look like this.

running test suite is not working in junit5 through maven

#SelectPackages and #SelectClasses tags are not getting parsed with maven test command.Though it is working fine in IDE. Even I tried with tag inside pom.xml.
Here is the code snippet :
PaymentServiceTest.java
package xyz.howtoprogram.junit5.payment;
import static org.junit.jupiter.api.Assertions.assertEquals;
import org.junit.jupiter.api.Test;
import org.junit.platform.runner.JUnitPlatform;
import org.junit.runner.RunWith;
#RunWith(JUnitPlatform.class)
public class PaymentServiceTest {
#Test
public void doPaymentZeroAmount() {
assertEquals(1, 1);
}
}
UserFeatureSuiteTest.java
#RunWith(JUnitPlatform.class)
#SelectPackages("xyz.howtoprogram.junit5.payment")
public class UserFeatureSuiteTest {
}
It is not running any of the test cases under the package. Though there is one test case underneath it.
xyz.howtoprogram.junit5.payment
-> PaymentServiceTest.java
Running xyz.howtoprogram.junit5.suite.UserFeatureSuiteTest
Tests run: 0, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0 sec - in xyz.howtoprogram.junit5.suite.UserFeatureSuiteTest.
Even I tried with changing the pom.xml like adding the 'include' tag.
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>
<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.0.0-M2</junit.jupiter.version>
<junit.vintage.version>4.12.0-M2</junit.vintage.version>
<junit.platform.version>1.0.0-M2</junit.platform.version>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.19.1</version>
<configuration>
<includes>
<include>**/UserFeatureSuiteTest.java</include>
</includes>
</configuration>
<dependencies>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>${junit.jupiter.version}</version>
</dependency>
<dependency>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
<version>${junit.vintage.version}</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-runner</artifactId>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
</dependency>
<dependency>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
</dependency>
</dependencies>
Sorry for the confusion ... I just took a closer look at your code and realized you're trying to mix two concepts.
Your test code is annotated with the JUnit 5 #Test. Therefore this code must be run with the junit-jupiter-engine. That engine does NOT support declarative suites but does read in the configuration from the maven-surefire-plugin.
#RunWith is a JUnit4 annotation and is completely ignored within the junit-jupiter-engine. I don't think it will cause the test to fail but it also will not enable any JUnit 5 tests. The #SelectPackages annotation you've placed on your suite's class will, in this context, only help decide which JUnit 4 tests are run - but you don't have any.
Below is the final POM,it is working now.
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.howtoprogram</groupId>
<artifactId>junit5-test-suite-example</artifactId>
<version>1.0-SNAPSHOT</version>
<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.0.0-M2</junit.jupiter.version>
<junit.vintage.version>4.12.0-M2</junit.vintage.version>
<junit.platform.version>1.0.0-M2</junit.platform.version>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.19</version>
<configuration>
<includes>
<include>**/*SuiteTest.java</include>
</includes>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<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-engine</artifactId>
<version>${junit.jupiter.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
so the output is :
T E S T S
-------------------------------------------------------
Feb 23, 2017 10:21:06 PM org.junit.platform.launcher.core.ServiceLoaderTestEngineRegistry loadTestEngines
INFO: Discovered TestEngines with IDs: [junit-jupiter]
Running xyz.howtoprogram.junit5.suite.UserFeatureSuiteTest
Feb 23, 2017 10:21:06 PM org.junit.platform.launcher.core.ServiceLoaderTestEngineRegistry loadTestEngines
INFO: Discovered TestEngines with IDs: [junit-jupiter]
Tests run: 2, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.053 sec - in xyz.howtoprogram.junit5.suite.UserFeatureSuiteTest
#RunWith(JUnitPlatform.class) is not supported when running tests via the JUnit Platform. If the new provider would pickup both UserFeatureSuiteTest and PaymentServiceTest your tests would be executed twice.
From the User Guide:
Annotating a class with #RunWith(JUnitPlatform.class) allows it to be run with IDEs and build systems that support JUnit 4 but do not yet support the JUnit Platform directly.
Thus, if you want UserFeatureSuiteTest to be run by Maven Surefire, you can use the "old" JUnit 4 support that is detected by default, i.e. just remove junit-platform-surefire-provider from the plug-in's dependencies.
Alternatively, you can directly execute your tests, e.g. PaymentServiceTest, through the JUnit Platform with your existing configuration.
By default Maven uses the following naming conventions when looking for tests to run:
Test*
*Test
*TestCase
Your test class doesn't follow these conventions. You should rename it or configure Maven Surefire Plugin to use another pattern for test classes.
Another thing that could lead to your Maven to not work is that all the tests are supposed to be in the following folder:
/my_application/src/test/java/MyFirstExampleTest.java
Here you can see a quite good question for a generalization of your problem, from where I took some parts of my answer. You should take a look at it.
EDIT
Here you can see an example that explain how your pom.xml should be:
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>org.codefx.demo</groupId>
<artifactId>junit-5</artifactId>
<version>1.0-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>5.0.0-M3</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
<compilerArgs>
<arg>-parameters</arg>
</compilerArgs>
</configuration>
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.19</version>
<dependencies>
<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-surefire-provider</artifactId>
<version>1.0.0-M3</version>
</dependency>
<dependency>
<!-- contains the engine that actually runs the Jupiter-tests -->
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>5.0.0-M3</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>
</project>
As you can see in this configuration file you specify:
Dependency: you need a test scoped dependency of JUnit in order to run tests
In the build section you will add the surefire plugin that will run your tests along with its dependencies