Debugging JBehave scenarios - java

I'm having trouble debugging my jbehave tests. I cannot get maven to start the jbehave tests and stop at a breakpoint. I have this in my pom:
<pluginManagement>
<plugins>
<plugin>
<groupId>org.jbehave</groupId>
<artifactId>jbehave-maven-plugin</artifactId>
<version>2.0.1</version>
</plugin>
</plugins>
</pluginManagement>
<plugins>
<plugin>
<groupId>org.jbehave</groupId>
<artifactId>jbehave-maven-plugin</artifactId>
<executions>
<execution>
<id>run-scenarios-found</id>
<phase>test</phase>
<configuration>
<scenarioIncludes>
<scenarioInclude>**/scenario/**/*${test}.java</scenarioInclude>
</scenarioIncludes>
<scenarioExcludes>
<scenarioExclude>**/*Steps.java</scenarioExclude>
</scenarioExcludes>
</configuration>
<goals>
<goal>run-scenarios</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
and I have tried things like:
$ mvn -e -o -Dtest=MyTest -Dmaven.surefire.debug="-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8787 -Xnoagent -Djava.compiler=NONE" clean test
and
$ export MVN_OPTS="-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8787 -Xnoagent -Djava.compiler=NONE" ; mvn -Dtest=MyTest clean test
I can try to use jsadebugd, but I that will probably require immaculate timing to automate, so that sounds like a suboptimal solution, and I feel like the JBehave Maven plugin should provide this functionality. Clearly I have just not found the right piece of documetation yet. Any ideas how I go about this ?

The following worked for me:
export MAVEN_OPTS="-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8787 -Xnoagent -Djava.compiler=NONE"
then start my mvn tests:
mvn install
(maven now hangs waiting for the debugger to connect)
Then start Eclipse in a remote debug session, pointing at local host, port 8787 (as above), with appropriate breakpoints set.

Wouldn't it be easier not to start the tests with maven, but rather in the IDE with JUnit? Then you can use the debugger directly? I normally do it so, that the CI server uses maven to execute JBehave, but in the IDE, I prefer a more direct way of execution.

This worked for me:
In Eclipse Run -> Debug Configurations...
Select Maven Build and click New button
Set the goals (clean very in my case) and possible parameters
Hit Debug button

mvn -e -o -Dmaven.surefire.debug="-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8787 -Xnoagent -Djava.compiler=NONE" integration-test
This line worked perfect for me. Setup your Jbehave project in eclipse
with the debug port (8787) and connect to the debugger quickly while mvn is waiting to connect to your eclipse project.

Related

Deploy to specific version

I'm using GAE, I usually do Deploy with a plugin for eclipse where it gives me the option to send it a version to upload, however I want to do it by command line, the command is as follows
mvn appengine:deploy
However I want to set the "version" parameter, but I do not know how.
To solve it I added the following plugin in the pom:
<plugin>
<groupId>com.google.appengine</groupId>
<artifactId>gcloud-maven-plugin</artifactId>
<version>2.0.9.120.v20160803</version>
<configuration>
<gcloud_directory>/usr/lib/google-cloud-sdk</gcloud_directory>
</configuration>
</plugin>
And I executed the following command:
mvn gcloud:deploy -Dgcloud.version=VERSION

How to add JVM options to program started by mvn spring-boot:run

What is the best way to add JVM options to the program started by mvn spring-boot:run?
You can configure spring-boot-maven-plugin to always include you jvm options when run:
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<jvmArguments>
-Dapp.name=test
</jvmArguments>
</configuration>
</plugin>
Or if you don't need that arguments to stay permanently, use this on the command line:
mvn spring-boot:run -Drun.jvmArguments="..."
Check documentation for details.
Now it is:
mvn spring-boot:run -Dspring-boot.run.jvmArguments="-Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=5005"

Automation of JMeter tests using Maven

I have included JMeter plugin by lazycode in my application.
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>com.lazerycode.jmeter</groupId>
<artifactId>jmeter-maven-plugin</artifactId>
<version>2.1.0</version>
<executions>
<execution>
<id>jmeter-tests</id>
<goals>
<goal>jmeter</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</pluginManagement>
</build>
This runs when I use mvn verify. But, it runs all integration tests and unit tests too. I don't want this to happen. I want to run just mvn jmeter:jmeter and run performance tests.
If I run mvn jmeter:jmeter, I get
No plugin found for prefix 'jmeter' in the current project and in the plugin groups [org.sonarsource.scanner.maven, org.apache.maven.plugins, org.codehaus.mojo] available from the repositories
I don't want to configure global .m2/settings.xml. How to run it using Maven?
You are almost there, the correct Maven command to run only JMeter tests would be:
mvn jmeter:jmeter -Pjmeter
References:
Maven - Introduction to Build Profiles
JMeter Maven Plugin
Five Ways To Launch a JMeter Test without Using the JMeter GUI

Is it possible to have two mainClass in the pom.xml or be able to run two classes in the same pom.xml?

I am working on a java project. We use Continuous Integration with maven 3, svn and Jenkins. We have one utility java project in which we've implemented some useful features. We build a jenkins tasks to run the mainClass in this project. Here is the code snippet on project pom.xml :
<plugin>
..
<artifactId>exec-maven-plugin</artifactId>
<version>1.2.1</version>
<executions>
<execution>
<goals>
<goal>java</goal>
</goals>
</execution>
</executions>
<configuration>
<mainClass>com.ent.uti.Cleaner</mainClass>
<arguments>
<argument>value1</argument>
<argument>value2</argument>
</arguments>
</configuration>
</plugin>
This class is execute in jenkins task configuration :
mvn exec:java -o -f cleaner/pom.xml
I am wondering if it is possible for me to implement some features in the same project and add another task in Jenkins ?
Is it possible to have two main classes in the same pom.xml configuration ?
I know i could create another project and configure a mainClass in the pom. I think doing so is not a good idea. The both task are independant so it's not suitable to run the both class one after another.
Thanks for reading.
You can use profiles for that purpose. All details are available here : http://www.jpeterson.com/2009/08/25/using-a-maven-profile-to-run-a-test-program/
Then your command line will look like :
mvn -P program1 exec:java -o -f cleaner/pom.xml
mvn -P program2 exec:java -o -f cleaner/pom.xml

SonarQube: Create HTML reports without run sonar:sonar command

In Sonar, we just download the sonar setup and if need, change the db credentials and run the command on maven project sonar:sonar, our coding stats and bugs are are analyzed by sonar and make the good html reports. But for this we need to run sonar:sonar command. Like findbugs, its possible to integrate with maven and create reports and time of maven:install .In this LINK at 4th step explain. Is also possible with sonar for make the report on maven:install command?
Like you can see on the SonarQube documentation, we strongly advise you to first run mvn clean install and then mvn sonar:sonar separately - otherwise you can have some side effects.
However, if you want to have all this in a single run, this is a Maven-related question. You just have to bind the "sonar" goal to the "install" phase in your POM, with something like:
...
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>sonar-maven-plugin</artifactId>
<executions>
<execution>
<phase>install</phase>
<goals>
<goal>sonar</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
...

Categories

Resources