Maven runs test but it does not display results - java

I've just started working with maven and I can't figure out how to solve the problem I have. It seems to my java file is compiled and test starts but no result shows up.
Demo.java:
package tutorial2;
public class Demo {
public boolean getBool(){
return false;
}
}
TestDemo.java:
package tutorial2;
import static org.junit.Assert.*;
import org.junit.Test;
public class TestDemo {
#Test
public void shouldBe(){
Demo demo = new Demo();
assertTrue(demo.getBool());
}
}
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>lets.develop.withme</groupId>
<artifactId>tutorial2</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>Tutorial 02</name>
<description>My second tutorial</description>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.2</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
</project
I'm getting this on console:
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building Tutorial 02 0.0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) # tutorial2 ---
[WARNING] Using platform encoding (UTF-8 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) # tutorial2 ---
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) # tutorial2 ---
[WARNING] Using platform encoding (UTF-8 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) # tutorial2 ---
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] --- maven-surefire-plugin:2.12.4:test (default-test) # tutorial2 ---
[INFO] Surefire report directory: /home/adam/workspaceJavaEE/tutorial2/target/surefire-reports
-------------------------------------------------------
T E S T S
-------------------------------------------------------
Running tutorial2.TestDemo
Tests run: 0, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.006 sec
Results :
Tests run: 0, Failures: 0, Errors: 0, Skipped: 0
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1.943 s
[INFO] Finished at: 2016-10-14T00:34:25+02:00
[INFO] Final Memory: 10M/212M
[INFO] ------------------------------------------------------------------------
Solved:
I solved problem by myself. Dependency in xml file was not configured properly. Version of junit dependency was wrong so It could't be run by maven.
Advise:
You should always add dependencies by "Insert Dependency" menu. It can be displayed by using shortcut "crtl"+"space" when your cursor is between <dependency> and </dependency> in your xml file. When you in "Select Dependency" menu enter "junit" in "Enter..." textbox and choose your version of junit. After clicking "ok" your dependency will be automatically added. This helps avoid problem with incorrect version typed manually.

By default, Surefire (the plugin that runs during mvn test) looks for classes in target/test-classes (which are compiled from src/test/java and maybe other places) that end in Test. Your class name is TestDemo, which doesn't end in Test, and won't be run. Either rename it to DemoTest (preferable), or manually configure Surefire in <plugins> (the approach when you're using a framework with alternate naming conventions, such as Spock's *Spec).

According to maven documentation avalible on:
By default, the Surefire Plugin will automatically include all test
classes with the following wildcard patterns:
"/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".
"/*TestCase.java" - includes all of its subdirectories and all Java
filenames that end with "TestCase".

Related

quarkus-cucumber does not find step definitions

I'm trying to set up acceptance tests for a Quarkus app, using quarkus-cucumber 0.6.0 (on Quarkus platform version 2.15.2.Final), but it fails to find the step definitions.
My package structure looks as follows:
src
main
api
backend
gui
test
java
com.example.test
AcceptanceTest.java
steps
BlahSteps.java
BlubbSteps.java
specifications
blah.feature
blubb.feature
The AcceptanceTest.java specifies the package for the glue:
package com.example.test
#CucumberOptions(
features = "src/test/specifications",
glue = "com.example.test.steps"
)
public class AcceptanceTest extends CucumberQuarkusTest {
public static void main(String[] args) {
runMain(AcceptanceTest.class, args);
}
}
And the BlahSteps.java in that package contains methods for the steps in blah.feature. (It also ends up correctly in target/test-classes.)
Still, no matter whether I run mvn clean test in the terminal (or ./mvnw quarkus:test after annotating the AcceptanceTest with #QuarkusTest) or run the test in IntelliJ, it runs the blah feature and tells me:
You can implement missing steps with the snippets below:
...
Why is it not finding the glue? Am I missing something?
Configure surefire plugin like below
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>${surefire-plugin.version}</version>
<configuration>
<includes>
<include>**/AcceptanceTest*.java</include>
</includes>
<testFailureIgnore>true</testFailureIgnore>
<systemPropertyVariables>
<java.util.logging.manager>org.jboss.logmanager.LogManager</java.util.logging.manager>
</systemPropertyVariables>
</configuration>
</plugin>
below you can see how cucumber triggered.
mintozzy#laptop:~/tmp/quarkus-cucumber-example$ mvn test
[INFO] Scanning for projects...
[WARNING]
[WARNING] Some problems were encountered while building the effective model for com.example:quarkus-cucumber-example:jar:1.0.0-SNAPSHOT
[WARNING] 'build.plugins.plugin.version' for io.quarkus.platform:quarkus-maven-plugin is missing. # line 56, column 15
[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] ----------------< com.example:quarkus-cucumber-example >----------------
[INFO] Building quarkus-cucumber-example 1.0.0-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) # quarkus-cucumber-example ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory /home/mintozzy/tmp/quarkus-cucumber-example/src/main/resources
[INFO]
[INFO] --- quarkus-maven-plugin:3.0.0.Alpha2:generate-code (default) # quarkus-cucumber-example ---
[INFO]
[INFO] --- maven-compiler-plugin:3.10.1:compile (default-compile) # quarkus-cucumber-example ---
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] --- quarkus-maven-plugin:3.0.0.Alpha2:generate-code-tests (default) # quarkus-cucumber-example ---
[INFO]
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) # quarkus-cucumber-example ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 1 resource
[INFO]
[INFO] --- maven-compiler-plugin:3.10.1:testCompile (default-testCompile) # quarkus-cucumber-example ---
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] --- maven-surefire-plugin:3.0.0-M7:test (default-test) # quarkus-cucumber-example ---
[INFO] Using auto detected provider org.apache.maven.surefire.junitplatform.JUnitPlatformProvider
[INFO]
[INFO] -------------------------------------------------------
[INFO] T E S T S
[INFO] -------------------------------------------------------
[INFO] Running com.example.test.AcceptanceTestRunner
2023-01-16 20:05:56,769 INFO [io.quarkus] (main) quarkus-cucumber-example 1.0.0-SNAPSHOT on JVM (powered by Quarkus 2.15.2.Final) started in 2.091s. Listening on: http://localhost:8081
2023-01-16 20:05:56,771 INFO [io.quarkus] (main) Profile test activated.
2023-01-16 20:05:56,771 INFO [io.quarkus] (main) Installed features: [cdi, cucumber, resteasy, resteasy-jackson, smallrye-context-propagation, vertx]
Scenario: You're still alright # specifications/everything_is_fine.feature:9
Given you are having coffee # com.example.test.steps.EverythingIsFineSteps.you_are_having_coffee()
And there is a fire around you # com.example.test.steps.EverythingIsFineSteps.there_is_a_fire_around_you()
When you are still alright # com.example.test.steps.EverythingIsFineSteps.you_are_still_alright()
Then everything is fine # com.example.test.steps.EverythingIsFineSteps.everything_is_fine()
Scenario: You start to feel it # specifications/everything_is_fine.feature:14
Given you are having coffee # com.example.test.steps.EverythingIsFineSteps.you_are_having_coffee()
And there is a fire around you # com.example.test.steps.EverythingIsFineSteps.there_is_a_fire_around_you()
When you start to feel it # com.example.test.steps.EverythingIsFineSteps.you_start_to_feel_it()
Then panic # com.example.test.steps.EverythingIsFineSteps.panic()
2 Scenarios (2 passed)
8 Steps (8 passed)
0m0.893s
[INFO] Tests run: 5, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 6.11 s - in com.example.test.AcceptanceTestRunner
2023-01-16 20:05:58,732 INFO [io.quarkus] (main) quarkus-cucumber-example stopped in 0.035s
[INFO]
[INFO] Results:
[INFO]
[INFO] Tests run: 5, Failures: 0, Errors: 0, Skipped: 0
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 10.311 s
[INFO] Finished at: 2023-01-16T20:05:58Z
[INFO] ------------------------------------------------------------------------
here is the full code.

How to debug springboot maven application in intellij

I want to start spring-boot maven application in debug mode in intellij Idea, but when I make breakpoints the application doesn't suspend and goes further. I've read a lot of topics but I still don't understand how to do it. Could you help me decide the best course of action.
Edit: I use spring-boot-maven-plugin and Maven Run/Debug configuration with spring-boot:run in command line.
Edit: So when I added Jvm Arguments to pom.xml I recieved such log:
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building shop 0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] >>> spring-boot-maven-plugin:1.5.8.RELEASE:run (default-cli) > test-compile # shop >>>
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) # shop ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 1 resource
[INFO] Copying 0 resource
[INFO]
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) # shop ---
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) # shop ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory C:\Users\Валера\IdeaProjects\shop\src\test\resources
[INFO]
[INFO] --- maven-compiler-plugin:3.1:testCompile (default-testCompile) # shop ---
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] <<< spring-boot-maven-plugin:1.5.8.RELEASE:run (default-cli) < test-compile # shop <<<
[INFO]
[INFO] --- spring-boot-maven-plugin:1.5.8.RELEASE:run (default-cli) # shop ---
[INFO] Attaching agents: []
Listening for transport dt_socket at address: 5005
But when requesting localhost:5005/myPage I recieve Error 101 (net: : ERR_CONNECTION_RESET). Seems like some maven arguments did not specify.
Here my maven plagin in pom.xml:
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<jvmArguments>
-Xdebug - Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=5005
</jvmArguments>
</configuration>
</plugin>
</plugins>
</build>
In your Run/Debug Configurations enter the following into your command line:
spring-boot:run -Dspring.profiles.active=local,<mine> -Dfork=false -f pom.xml
My Maven spring-boot:run configuration debugs just fine with the -D fork=false added.
You may use below command in the CLI:
export MAVEN_OPTS="-Xdebug -Xnoagent -Djava.compiler=NONE -Xrunjdwp:transport=dt_socket,address=5005,server=y,suspend=n
Below is my project settings:
enter image description here

JBehave throwing NullPointerException when running embeddable stories

I am working on a Spring MVC rest service, for which I am also trying to set up JBehave. This is a Maven project with a single module, and the JBehave code is living under the test scope of that module. My problem is that my sample test (which is just an empty test) is failing with an NPE. I was expecting to see the test pass so that I know JBehave is set up properly. Can you take a look at what I've got and see if you can help me spot what is causing the NPE?
First, relevant parts of my maven configuration:
<properties>
<jbehave.version>4.0.4</jbehave.version>
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jbehave</groupId>
<artifactId>jbehave-core</artifactId>
<version>${jbehave.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jbehave</groupId>
<artifactId>jbehave-spring</artifactId>
<version>${jbehave.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jbehave.site</groupId>
<artifactId>jbehave-site-resources</artifactId>
<version>3.1.1</version>
<scope>test</scope>
<type>zip</type>
</dependency>
<dependency>
<groupId>org.jbehave</groupId>
<artifactId>jbehave-core</artifactId>
<version>${jbehave.version}</version>
<classifier>resources</classifier>
<type>zip</type>
<scope>test</scope>
</dependency>
</dependencies>
<build>
...
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<scope>test</scope>
<testSourceDirectory>${basedir}/src/test/java/</testSourceDirectory>
<testClassesDirectory>${project.build.directory}/test-classes/</testClassesDirectory>
<includes>
<include>com/mycompany/myproject/test/behavior/steps/*.java</include>
</includes>
</configuration>
</plugin>
<plugin>
<groupId>org.jbehave</groupId>
<artifactId>jbehave-maven-plugin</artifactId>
<version>${jbehave.version}</version>
<configuration>
<scope>test</scope>
</configuration>
<executions>
<execution>
<id>unpack-view-resources</id>
<phase>generate-resources</phase>
<goals>
<goal>unpack-view-resources</goal>
</goals>
</execution>
<execution>
<id>run-stories-as-embeddables</id>
<phase>integration-test</phase>
<configuration>
<scope>test</scope>
<includes>
<include>com/mycompany/myproject/test/behavior/steps/*.java</include>
</includes>
<systemProperties>
<property>
<name>java.awt.headless</name>
<value>true</value>
</property>
</systemProperties>
</configuration>
<goals>
<goal>run-stories-as-embeddables</goal>
</goals>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.17</version>
<scope>compile</scope>
</dependency>
</dependencies>
</plugin>
</build>
I run my tests via mvn clean integration-test -e and I get this output:
$ mvn clean integration-test -e
[INFO] Error stacktraces are turned on.
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building MyProject 0.1
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) # MyProject ---
[INFO] Deleting C:\Users\mylogin\myproject\target
[INFO]
[INFO] --- jbehave-maven-plugin:4.0.4:unpack-view-resources (unpack-view-resources) # MyProject ---
[INFO] Unpacked C:\Users\mylogin\.m2\repository\org\jbehave\site\jbehave-site-resources\3.1.1\jbehave-site-resources-3.1.1.zip to C:\Users\mylogin\myproject\target\jbehave\view
[INFO] Unpacked C:\Users\mylogin\.m2\repository\org\jbehave\jbehave-core\4.0.4\jbehave-core-4.0.4-resources.zip to C:\Users\mylogin\myproject\target\jbehave\view
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) # MyProject ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 18 resources
[INFO] Copying 6 resources
[INFO]
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) # MyProject ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 62 source files to C:\Users\mylogin\myproject\target\classes
... omitted ...
[INFO]
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) # MyProject ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 6 resources
[INFO]
[INFO] --- maven-compiler-plugin:3.1:testCompile (default-testCompile) # MyProject ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 12 source files to C:\Users\mylogin\myproject\target\test-classes
[INFO]
[INFO] --- maven-surefire-plugin:2.18.1:test (default-test) # MyProject ---
[INFO] Surefire report directory: C:\Users\mylogin\myproject\target\surefire-reports
-------------------------------------------------------
T E S T S
-------------------------------------------------------
Running com.mycompany.myproject.test.behavior.steps.SampleRestCallWithInvalidAccountSteps
Processing system properties {}
Using controls EmbedderControls[batch=false,skip=false,generateViewAfterStories=true,ignoreFailureInStories=true,ignoreFailureInView=false,verboseFailures=true,verboseFiltering=false,storyTimeouts=300,threads=1,failOnStoryTimeout=false]
Running story com/mycompany/myproject/test/behavior/steps/sample_rest_call_with_invalid_account_steps.story
Generating reports view to 'C:\Users\mylogin\myproject\target\jbehave' using formats '[stats, ide_console, txt, html]' and view properties '{navigator=ftl/jbehave-navigator.ftl, views=ftl/jbehave-views.ftl, reports=ftl/jbehave-reports.ftl, nonDecorated=ftl/jbehave-report-non-decorated.ftl, decorated=ftl/jbehave-report-decorated.ftl, maps=ftl/jbehave-maps.ftl}'
Reports view generated with 2 stories (of which 1 pending) containing 1 scenarios (of which 1 pending)
Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 1.326 sec - in com.mycompany.myproject.test.behavior.steps.SampleRestCallWithInvalidAccountSteps
Results :
Tests run: 1, Failures: 0, Errors: 0, Skipped: 0
[INFO]
[INFO] --- maven-war-plugin:3.0.0:war (default-war) # MyProject ---
[INFO] Packaging webapp
[INFO] Assembling webapp [MyProject] in [C:\Users\mylogin\myproject\target\mywarname##0.1]
[INFO] Processing war project
[INFO] Copying webapp resources [C:\Users\mylogin\myproject\src\main\webapp]
[INFO] Webapp assembled in [484 msecs]
[INFO] Building war: C:\Users\mylogin\myproject\target\mywarname##0.1.war
[INFO]
[INFO] --- spring-boot-maven-plugin:1.3.5.RELEASE:repackage (default) # MyProject ---
[INFO]
[INFO] --- jbehave-maven-plugin:4.0.4:run-stories-as-embeddables (run-stories-as-embeddables) # MyProject ---
[INFO] Running stories as embeddables using embedder Embedder[storyMapper=StoryMapper,embedderMonitor=MavenEmbedderMonitor,classLoader=EmbedderClassLoader[urls=[/C:/Users/mylogin/Projects/AQ/aqservices/target/test-classes/, /C:/Users/mylogin/Projects/AQ/aqservices/target/classes/, spring-boot-starter-tomcat-1.3.5.RELEASE.jar, tomcat-embed-core-8.0.33.jar, tomcat-embed-el-8.0.33.jar, tomcat-embed-logging-juli-8.0.33.jar, tomcat-embed-websocket-8.0.33.jar, spring-ws-core-2.3.0.RELEASE.jar, spring-xml-2.3.0.RELEASE.jar, spring-aop-4.2.6.RELEASE.jar, spring-beans-4.2.6.RELEASE.jar, spring-core-4.2.6.RELEASE.jar, spring-oxm-4.2.6.RELEASE.jar, spring-web-4.2.6.RELEASE.jar, spring-webmvc-4.2.6.RELEASE.jar, spring-boot-starter-1.3.5.RELEASE.jar, spring-boot-1.3.5.RELEASE.jar, spring-boot-autoconfigure-1.3.5.RELEASE.jar, snakeyaml-1.16.jar, spring-boot-starter-log4j-1.3.7.RELEASE.jar, jcl-over-slf4j-1.7.21.jar, jul-to-slf4j-1.7.21.jar, slf4j-log4j12-1.7.21.jar, log4j-1.2.17.jar, spring-orm-4.3.2.RELEASE.jar, spring-jdbc-4.2.6.RELEASE.jar, spring-tx-4.2.6.RELEASE.jar, spring-data-commons-1.12.2.RELEASE.jar, spring-context-4.2.6.RELEASE.jar, spring-expression-4.2.6.RELEASE.jar, spring-context-support-4.1.4.RELEASE.jar, spring-test-4.2.6.RELEASE.jar, spring-security-core-4.1.1.RELEASE.jar, aopalliance-1.0.jar, spring-security-web-4.1.1.RELEASE.jar, spring-security-config-4.1.1.RELEASE.jar, jstl-1.2.jar, wsdl4j-1.6.3.jar, aspectjweaver-1.8.9.jar, jasypt-1.9.2.jar, xstream-1.4.9.jar, xmlpull-1.1.3.1.jar, xpp3_min-1.1.4c.jar, bcprov-jdk16-1.46.jar, org.apache.commons.io-2.4.jar, commons-io-2.4.jar, slf4j-api-1.7.21.jar, commons-lang-2.6.jar, mail-1.4.jar, activation-1.1.jar, dozer-5.5.1.jar, commons-beanutils-1.9.2.jar, commons-lang3-3.2.1.jar, jregex-1.2_01.jar, tomcat-embed-jasper-8.0.33.jar, ecj-4.5.jar, ehcache-2.10.2.2.21.jar, HikariCP-2.4.7.jar, emdq-1.0.jar, sqljdbc4-4.0.jar, ghs-verifyaq-client-1.0.3.jar, mockito-all-1.9.5.jar, junit-4.11.jar, hamcrest-core-1.3.jar, jbehave-core-4.0.4.jar, hamcrest-library-1.3.jar, hamcrest-integration-1.3.jar, commons-collections-3.2.2.jar, plexus-utils-3.0.10.jar, freemarker-2.3.23.jar, paranamer-2.4.jar, jbehave-spring-4.0.4.jar],parent=ClassRealm[plugin>org.jbehave:jbehave-maven-plugin:4.0.4, parent: sun.misc.Launcher$AppClassLoader#55f96302]],embedderControls=UnmodifiableEmbedderControls[EmbedderControls[batch=false,skip=false,generateViewAfterStories=true,ignoreFailureInStories=false,ignoreFailureInView=false,verboseFailures=false,verboseFiltering=false,storyTimeouts=300,threads=1,failOnStoryTimeout=false]],embedderFailureStrategy=<null>,configuration=org.jbehave.core.configuration.MostUsefulConfiguration#645b2ac7,candidateSteps=<null>,stepsFactory=<null>,metaFilters=<null>,metaMatchers=<null>,systemProperties={java.awt.headless=true},executorService=<null>,executorServiceCreated=false,performableTree=PerformableTree,storyManager=<null>,timeoutParsers=<null>]
[INFO] Found class names: [com.mycompany.myproject.test.behavior.steps.SampleRestCallWithInvalidAccountSteps]
[INFO] Using controls UnmodifiableEmbedderControls[EmbedderControls[batch=false,skip=false,generateViewAfterStories=true,ignoreFailureInStories=false,ignoreFailureInView=false,verboseFailures=false,verboseFiltering=false,storyTimeouts=300,threads=1,failOnStoryTimeout=false]]
[INFO] Running embeddable com.mycompany.myproject.test.behavior.steps.SampleRestCallWithInvalidAccountSteps
[INFO] Processing system properties {java.awt.headless=true}
[INFO] System property 'java.awt.headless' set to 'true'
[INFO] Using controls UnmodifiableEmbedderControls[EmbedderControls[batch=false,skip=false,generateViewAfterStories=true,ignoreFailureInStories=false,ignoreFailureInView=false,verboseFailures=false,verboseFiltering=false,storyTimeouts=300,threads=1,failOnStoryTimeout=false]]
[INFO] Generating reports view to 'C:\Users\mylogin\myproject\target\jbehave' using formats '[stats, ide_console, txt, html]' and view properties '{navigator=ftl/jbehave-navigator.ftl, views=ftl/jbehave-views.ftl, reports=ftl/jbehave-reports.ftl, nonDecorated=ftl/jbehave-report-non-decorated.ftl, decorated=ftl/jbehave-report-decorated.ftl, maps=ftl/jbehave-maps.ftl}'
[INFO] Reports view generated with 2 stories (of which 1 pending) containing 1 scenarios (of which 1 pending)
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 12.714 s
[INFO] Finished at: 2017-03-28T13:25:28-04:00
[INFO] Final Memory: 38M/299M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.jbehave:jbehave-maven-plugin:4.0.4:run-stories-as-embeddables (run-stories-as-embeddables) on project MyProject: Failed to run stories as embeddables: Failure in running embeddable: com.mycompany.myproject.test.behavior.steps.SampleRestCallWithInvalidAccountSteps: NullPointerException -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.jbehave:jbehave-maven-plugin:4.0.4:run-stories-as-embeddables (run-stories-as-embeddables) on project MyProject: Failed to run stories as embeddables
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:212)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:116)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:80)
at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build(SingleThreadedBuilder.java:51)
at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:128)
at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:307)
at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:193)
at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:106)
at org.apache.maven.cli.MavenCli.execute(MavenCli.java:863)
at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:288)
at org.apache.maven.cli.MavenCli.main(MavenCli.java:199)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:289)
at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:229)
at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:415)
at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:356)
Caused by: org.apache.maven.plugin.MojoFailureException: Failed to run stories as embeddables
at org.jbehave.mojo.RunStoriesAsEmbeddables.execute(RunStoriesAsEmbeddables.java:20)
at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:134)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:207)
... 20 more
Caused by: org.jbehave.core.embedder.Embedder$RunningEmbeddablesFailed: Failure in running embeddable: com.mycompany.myproject.test.behavior.steps.SampleRestCallWithInvalidAccountSteps
at org.jbehave.core.embedder.Embedder.runAsEmbeddables(Embedder.java:140)
at org.jbehave.mojo.RunStoriesAsEmbeddables.execute(RunStoriesAsEmbeddables.java:18)
... 22 more
Caused by: java.lang.NullPointerException
at org.jbehave.core.steps.spring.SpringStepsFactory.stepsTypes(SpringStepsFactory.java:39)
at org.jbehave.core.steps.AbstractStepsFactory.createCandidateSteps(AbstractStepsFactory.java:34)
at org.jbehave.core.embedder.PerformableTree$RunContext.<init>(PerformableTree.java:458)
at org.jbehave.core.embedder.PerformableTree.newRunContext(PerformableTree.java:1105)
at org.jbehave.core.embedder.StoryManager.runStories(StoryManager.java:100)
at org.jbehave.core.embedder.StoryManager.runStoriesAsPaths(StoryManager.java:86)
at org.jbehave.core.embedder.Embedder.runStoriesAsPaths(Embedder.java:213)
at org.jbehave.core.junit.JUnitStory.run(JUnitStory.java:24)
at org.jbehave.core.embedder.Embedder.runAsEmbeddables(Embedder.java:131)
... 23 more
[ERROR]
[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
My story file, named sample_rest_call_with_invalid_account_steps.story:
Scenario: Call the sample rest resource
Given an initial value
When this API is called
Then expect failure
My java story class, named SampleRestCallWithInvalidAccountSteps.java:
import com.mycompany.myproject.test.behavior.driver.AbstractSpringJBehaveStory;
import com.mycompany.myproject.test.behavior.driver.annotations.BehaviorTest;
import org.jbehave.core.annotations.*;
import org.junit.runner.RunWith;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
/**
* Scenario: Call the sample rest resource
*/
#RunWith(SpringJUnit4ClassRunner.class)
#BehaviorTest
public class SampleRestCallWithInvalidAccountSteps extends AbstractSpringJBehaveStory {
#Given("an initial value")
public void Given() {
// purposely empty
}
#When("this API is called")
public void When() {
// purposely empty
}
#Then("expect failure")
public void Then() {
// purposely empty
}
}
My story superclass:
package com.mycompany.myproject.test.behavior.driver;
import java.util.Arrays;
import org.jbehave.core.configuration.Configuration;
import org.jbehave.core.configuration.MostUsefulConfiguration;
import org.jbehave.core.embedder.Embedder;
import org.jbehave.core.embedder.EmbedderControls;
import org.jbehave.core.io.CodeLocations;
import org.jbehave.core.io.LoadFromClasspath;
import org.jbehave.core.io.StoryLoader;
import org.jbehave.core.io.StoryPathResolver;
import org.jbehave.core.io.UnderscoredCamelCaseResolver;
import org.jbehave.core.junit.JUnitStory;
import org.jbehave.core.reporters.FilePrintStreamFactory;
import org.jbehave.core.reporters.Format;
import org.jbehave.core.reporters.StoryReporterBuilder;
import org.jbehave.core.steps.InjectableStepsFactory;
import org.jbehave.core.steps.ParameterControls;
import org.jbehave.core.steps.spring.SpringStepsFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
public abstract class AbstractSpringJBehaveStory extends JUnitStory {
#Autowired
private ApplicationContext appContext;
public AbstractSpringJBehaveStory() {
Embedder embedder = new Embedder();
embedder.useEmbedderControls(embedderControls());
embedder.useMetaFilters(Arrays.asList("-skip"));
useEmbedder(embedder);
}
#Override
public InjectableStepsFactory stepsFactory() {
return new SpringStepsFactory(configuration(), appContext);
}
#Override
public Configuration configuration() {
return new MostUsefulConfiguration()
.useStoryPathResolver(storyPathResolver())
.useStoryLoader(storyLoader())
.useStoryReporterBuilder(storyReporterBuilder())
.useParameterControls(parameterControls());
}
private EmbedderControls embedderControls() {
return new EmbedderControls()
.doIgnoreFailureInStories(true)
.doGenerateViewAfterStories(true)
.doVerboseFailures(true);
}
private StoryPathResolver storyPathResolver() {
return new UnderscoredCamelCaseResolver();
}
private StoryLoader storyLoader() {
return new LoadFromClasspath();
}
private StoryReporterBuilder storyReporterBuilder() {
return new StoryReporterBuilder()
.withCodeLocation(CodeLocations.codeLocationFromClass(this.getClass()))
.withPathResolver(new FilePrintStreamFactory.ResolveToPackagedName())
.withFailureTrace(true)
.withDefaultFormats()
.withFormats(Format.IDE_CONSOLE, Format.TXT, Format.HTML);
}
private ParameterControls parameterControls() {
return new ParameterControls()
.useDelimiterNamedParameters(true);
}
}
For reference, I was loosely following this guide.
I now have a working solution. I believe that I have narrowed the culprit to improperly extending AbstractSpringJBehaveStory in the SampleRestCallSteps class. I fixed this by creating a new empty class to serve as an instantiable subclass of AbstractSpringJBehaveStory and removing the extends from SampleRestCallSteps.
Also, I did find a few missing lines when creating the Configuration, which I believe is the real cause. I got the new ones that are now shown in the method below from generating a blank new JBehave-Spring archetype with maven.
#Override
public Configuration configuration() {
ParameterConverters parameterConverters = new ParameterConverters();
ExamplesTableFactory examplesTableFactory = new ExamplesTableFactory(
new LocalizedKeywords(),
new LoadFromClasspath(this.getClass()),
parameterConverters);
parameterConverters.addConverters(
new DateConverter(new SimpleDateFormat("yyyy-MM-dd")),
new ExamplesTableConverter(examplesTableFactory));
return new MostUsefulConfiguration()
.useStoryLoader(storyLoader())
.useStoryParser(new RegexStoryParser(examplesTableFactory))
.useStoryReporterBuilder(storyReporterBuilder())
.useStoryPathResolver(storyPathResolver())
.useParameterControls(parameterControls())
.useParameterConverters(parameterConverters);
}
Lastly, I think a Spring context was not being autowired properly, so I changed the stepsFactory() method like this (again copied from the maven template):
#Override
public InjectableStepsFactory stepsFactory() {
ApplicationContext appContext = new SpringApplicationContextFactory("jbehave-app-context.xml")
.createApplicationContext();
return new SpringStepsFactory(configuration(), appContext);
}

Why maven-surefire-plugin skip tests with log message "because it has already been run for this configuration"?

I can't understand why maven-surefire-plugin doesn't run jUnit4 test. My pom is (can't add it here because "it looks post is mostly code"): http://pastebin.com/Jj3iJZpY
When I execute mvn clean test cmd window shows:
C:\Users\maya\git\services>mvn clean test
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building services 1.0.18
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) # services ---
[INFO] Deleting C:\Users\maya\git\services\target
[INFO]
[INFO] --- maven-mule-plugin:1.9:attach-test-resources (default-attach-test-resources) # services ---
[INFO] attaching test resource C:\Users\maya\git\services\src\main\app
[INFO]
[INFO] --- build-helper-maven-plugin:1.7:add-resource (add-resource) # services ---
[INFO]
[INFO] --- maven-resources-plugin:2.7:resources (default-resources) # services ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 4 resources
[INFO] Copying 3 resources
[INFO] Copying 0 resource
[INFO]
[INFO] --- maven-mule-plugin:1.9:filter-resources (default-filter-resources) # services ---
[INFO]
[INFO] --- maven-compiler-plugin:2.3.2:compile (default-compile) # services ---
[INFO] Compiling 60 source files to C:\Users\maya\git\services\target\classes
[INFO]
[INFO] --- maven-resources-plugin:2.7:testResources (default-testResources) # services ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 0 resource
[INFO] Copying 3 resources
[INFO]
[INFO] --- maven-compiler-plugin:2.3.2:testCompile (default-testCompile) # services ---
[INFO] Compiling 1 source file to C:\Users\maya\git\services\target\test-classes
[INFO]
[INFO] --- maven-surefire-plugin:2.19:test (default-test) # services ---
[INFO]
[INFO] --- maven-surefire-plugin:2.19:test (default) # services ---
[INFO] Skipping execution of surefire because it has already been run for this configuration
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 8.554 s
[INFO] Finished at: 2015-12-11T15:48:05+03:00
[INFO] Final Memory: 48M/312M
[INFO] ------------------------------------------------------------------------
Test class is:
package com.comp.utils.UtilsTest;
import static org.junit.Assert.assertTrue;
import org.apache.log4j.Logger;
import org.junit.Test;
public class UtilsTest {
private static final Logger LOG = Logger.getLogger(UtilsTest.class.getName());
#Test
public void testHasPersonSameProd() {
boolean hasSameProduct = false;
assertTrue("Should be True", hasSameProduct);
}
}
Why maven-surefire-plugin:2.19 runs twice and doesn't want to run my test class? How to run test in my case? Thank you.
Given the pom you linked (which should be included into the question actually, as the link may be broken in the future):
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.19</version>
<executions>
<execution>
<goals>
<goal>test</goal>
</goals>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>org.apache.maven.surefire</groupId>
<artifactId>surefire-junit47</artifactId>
<version>2.19</version>
</dependency>
</dependencies>
<configuration>
<includes>
<include>UtilTest.java</include>
</includes>
</configuration>
</plugin>
The Maven Surefire Plugin runs twice because you configured an additional execution of the plugin, without providing an id element and as such by default it is called default (maven-surefire-plugin:2.19:test (default)). This execution runs after the out-of-the-box Maven configuration for Surefire (maven-surefire-plugin:2.19:test (default-test)). So, as a consequence, you have two executions (default and default-test). Removing the executions section on the Surefire plugin configuration you would only have one execution (the default-test).
You also have a typo in the Surefire configuration, the <include>UtilTest.java</include> configuration points to the UtilTest.java class, while in your question it is named UtilsTest (note the additional 's').
If the test class is under src/test/java folder, then you don't need to configure its inclusion, since it also already follow the default convention of Surefire, "**/*Test.java".
The message you are having (Skipping execution of surefire because it has already been run for this configuration) is because your configuration element for the Surefire plugin is outside any executions element, which means is applied to all plugin executions, even the default one (default-test).
So you could probably remove the whole Surefire plugin section from your pom and the issue should be fixed.

How can I find the WSDL file after a successful build?

I'm developing a project containing different layers. I'm using Maven, JAX-WS, the Spring framework and Hibernate. I tried to generate the WSDL file using jax ws maven plugin. First I used a JRE 7 but it didn't work. When I used a JDK 1.7 this message appeared:
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 BSCSwebservices Maven Webapp 0.0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[WARNING] The POM for bsh:bsh:jar:1.2b3 is missing, no dependency information available
[WARNING] The POM for com.sun.xml.stream.buffer:streambuffer:jar:0.4 is invalid, transitive dependencies (if any) will not be available, enable debug logging for more details
[WARNING] The POM for org.jvnet.staxex:stax-ex:jar:1.0 is invalid, transitive dependencies (if any) will not be available, enable debug logging for more details
[WARNING] The artifact woodstox:wstx-asl:jar:3.2.0 has been relocated to org.codehaus.woodstox:wstx-asl:jar:3.2.0
[INFO]
[INFO] --- maven-resources-plugin:2.5:resources (default-resources) # BSCSwebservices ---
[debug] execute contextualize
[WARNING] File encoding has not been set, using platform encoding Cp1252, i.e. build is platform dependent!
[WARNING] Using platform encoding (Cp1252 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] Copying 6 resources
[INFO]
[INFO] --- maven-compiler-plugin:2.3.1:compile (default-compile) # BSCSwebservices ---
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] --- maven-resources-plugin:2.5:testResources (default-testResources) # BSCSwebservices ---
[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\sayed\workspace\BSCSwebservices1\src\test\resources
[INFO]
[INFO] --- maven-compiler-plugin:2.3.1:testCompile (default-testCompile) # BSCSwebservices ---
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] --- maven-surefire-plugin:2.10:test (default-test) # BSCSwebservices ---
[INFO] No tests to run.
[INFO] Surefire report directory: C:\Users\sayed\workspace\BSCSwebservices1\target\surefire-reports
-------------------------------------------------------
T E S T S
-------------------------------------------------------
Results :
Tests run: 0, Failures: 0, Errors: 0, Skipped: 0
[INFO]
[INFO] --- maven-war-plugin:2.1.1:war (default-war) # BSCSwebservices ---
[INFO] Packaging webapp
[INFO] Assembling webapp [BSCSwebservices] in [C:\Users\sayed\workspace\BSCSwebservices1\target\BSCSwebservices]
[INFO] Processing war project
[INFO] Copying webapp resources [C:\Users\sayed\workspace\BSCSwebservices1\src\main\webapp]
[INFO] Webapp assembled in [607 msecs]
[INFO] Building war: C:\Users\sayed\workspace\BSCSwebservices1\target\BSCSwebservices.war
[WARNING] Warning: selected war files include a WEB-INF/web.xml which will be ignored
(webxml attribute is missing from war task, or ignoreWebxml attribute is specified as 'true')
[INFO]
[INFO] --- jaxws-maven-plugin:1.11:wsgen (service_BillingAccountRead) # BSCSwebservices ---
[WARNING] The POM for woodstox:wstx-asl:jar:3.2.3 is missing, no dependency information available
warning: The apt tool and its associated API are planned to be
removed in the next major JDK release. These features have been
superseded by javac and the standardized annotation processing API,
javax.annotation.processing and javax.lang.model. Users are
recommended to migrate to the annotation processing features of
javac; see the javac man page for more information.
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 11.635s
[INFO] Finished at: Thu Aug 01 20:38:29 WAT 2013
[INFO] Final Memory: 16M/38M
[INFO] ------------------------------------------------------------------------
this a part of pom.xml
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>jaxws-maven-plugin</artifactId>
<version>1.11</version>
<executions>
<execution>
<id>service_BillingAccountRead</id>
<phase>package</phase>
<goals>
<goal>wsgen</goal>
</goals>
<configuration>
<sei>com.ws.BillingAccountRead</sei>
<genwsdl>true</genwsdl>
<keep>true</keep>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.1</version>
</plugin>
</plugins>
The build succeeds, but I don't find the WSDL file? And is that the warnings that have an effect after I completed the other layer?
I added the dependency of all all jars appearing in warnings, but the warnings are still shown.
WSDL's get placed by default in {module_root}\target\generated-sources\wsdl
You REALLY need to start including relevant info in your questions. You haven't even posted the relevant parts of your pom. Have you even told jax-ws to generate a wsdl?
Also, fix the tonne of warnings getting spat out when you run your maven build. That just adds to the mess of info you are posting.
EDIT:
Go look up the documentation. You can explicitly state where the wsdls will end up. All of your questions have had simple answers which you could have found yourself with a minimal amount of effort on your part.
Generally, when you build the project, the WSDL document file and the schema document files are not generated automatically. This files are generated on deploy time by the application server. Internally, the server executes the wsgen tool to generate the files. Next, when you request the WSLD document file (add ?wsdl on service endpoint) the application server on the fly update the service url in the files and serves.
If you want include the generation of this files, you can add in your pom.xml the JAX-WS commons. See an example in this question.

Categories

Resources