How to run specified Selenese test by maven - testing

I have Selenese with maven and testSuite with a lot of tests, my question how to run some of test cases?

Just like running any specific test in maven:
mvn test -Dtest=(YOUR_TEST_CLASS_NAME)
You can also supply test=TEST_CLASS* for all of that type, etc. Maven has some pretty good name and package matching. You may even be able to run a single test method by supplying the method name (although I have not tried this).

Check the Selunit maven plugin out, it provides include and exclude filters for Selenese suites in the pom.xml configuration.

Related

How to target specific Cucumber runner classes or feature files within Jenkins?

Is it possible to target specific runner classes or feature files within Jenkins?
Let's say for example I have the following files.
Runner classes:
RunnerClass1.java
RunnerClass1.java
Feature Files:
Login.feature
SignUp.feature
Is there a way to trigger specific runner classes or feature files within the Jenkins UI, I know you can use specific plugins such as: 'Parameterised / String Parameters', has anyone else found a solution to target specific tests from Jenkins?
thanks for your help
You can tag your test cases and maven will be able to run them by these tags.
For example, When I have Login cases with #Login tags and I want to run them with Maven, I am using the following terminal script :
mvn clean test -Dcucumber.options="--tags #Login"

How to avoid maven compiling testClass in normale compiling

I have a default maven project:
/src/main/java
/src/test/java (include *Test.java).
When I exeucte "mvn compile", maven also tries to compile the testClasses under /src/test/java. This fails, as of some dependencies such as JUnit are under "test"-scope. Changing the scope of e.g. JUnit to "provided" everything works fine.
How can I avoid maven to compile testClasses when compiling? In my understanding, I expect to maven to compile this files only when executing "testcompile".
I am using maven 2.2.1
I believe it is nothing to do with the scope of JUnit. Normally we set JUnit's scope to test (instead of provided) and everything is just fine.
src/test/java is compiled by Maven Compiler Plugin's testCompile goal. However, you don't need to explicitly run that goal. Please have a look in topics about Maven's Lifecycle. For example, if you run maven install, it is implicitly going through many phases (e.g. compile, compile test, generate resources etc), and many of them is bounded to a default plugin goal.
If you want to avoid test source from building, from Maven Compiler Plugin's usage page, compiler:testCompile will be skipped if you turn off testing by setting maven.test.skip=true
So, if your unit tests are not yet ready, just build with Maven, with -Dmaven.test.skip=true parameter.
Just to add, this is absolutely not a good practice to assume "unit test failing" being normal during development.
Just use the skip parameter for the maven-surefire-plugin which skip tests as well as compiling the test.
The pom.xml had defined "sourceDirectory" incorrectly. Removing it fixed the issue
Instead of command "maven clean compile" , use "mvn -B -Dmaven.test.skip=true clean compile". This parameter skips test.

Can maven-exec-plugin fail the build?

I have a maven execution that runs a javascript compressor as a command line program, however, this tool also does some jslint checks as well.
If these jslint checks fail so should my build.
These errors are output as a parseable string to stdout.
If this maven plugin cannot solve this problem, I'm happy to use any other suggested.
Thanks.
To my knowledge, exec:exec will fail the build if the return code of the executed command is not 0 (or one of the configured successCodes). Maybe you can build something around this.
As an alternative, have a look at these plugins, they both can fail a build on problems:
the Jslint Maven Plugin
the YUI Compressor Maven Mojo
Depending on what you need exactly, there is also the Maven Javascript Plugin.
And also have a look at this Maven plugins for javascript question.

maven junit pom.xml

i have a following problem.
I'd like ti test my JSF Application with JSFUnit.But JSFUnit supports inly junit3 (all our unit tests run with JUnit4).
Is it possible to include in pom.xml two junit dependencies (junit4 and junit3) with e.g. different scopes?
Please help and thanx in advance
If you separate the project into two submodules, one which needs JUnit3 and the other which needs JUnit4, you can specify the test dependencies separately in the child pom.
As Péter said, you should split your project in separate modules. In cases like this I've also seen the use of dedicated test modules turn out good results.
This way the JUnit4 test dependency you have in foo-web is not visible to the tests running from foo-web-jsf-tests.

How to display a list of available goals?

I'm rather new to Maven and I often find myself wanting to see what's actually there in terms of goals.
So, is there a command which lists all available goals for e.g. a given prefix?
Since Maven is an open system of plugins, the best answer is probably "Google" ;-). If you mean all build lifecycle phases, they are static, and can be found at http://maven.apache.org/guides/introduction/introduction-to-the-lifecycle.html and at other places.
Then, for a given plugin, the help plugin can be used to get the possible goals and all their parameters:
mvn help:describe -DgroupId=org.apache.maven.plugins \
-DartifactId=maven-war-plugin \
-Ddetail=true
But this doesn't really answer your question, especially the "for a given prefix" part. For this, the best solution might be to use **auto completion with BASH (**not sure it will be exhaustive though). See for example the Guide to Maven 2.x auto completion using BASH. To get bash completion working under Windows, you'll need CYGWIN. See Maven Tab Auto Completion in Bash for detailed setup steps (and a "better" working auto completion script).
A shorter way
As an alternative, you can also use the -Dplugin parameter to display the list of available goals.
mvn help:describe -Dplugin=org.apache.maven.plugins:maven-war-plugin\
-Ddetail=true
See Maven help plugin.
More and more Maven plugins propose an help goal as alternative to the verbose
mvn help:describe command.
You can read from the Maven doc:
Recent Maven plugins have generally an help goal to have in the
command line the description of the plugin, with their parameters and
types
That is really more natural and pleasant to use.
It works of course for Maven core plugins.
Some examples :
to list goals of the dependency plugin :
mvn dependency:help
to have detail about the javadoc goal of the javadoc plugin :
mvn javadoc:help -Ddetail -Dgoal=javadoc
And it works also for third party plugins.
For example, to list goals of the spring-boot-maven-plugin :
mvn org.springframework.boot:spring-boot:help
[INFO] Spring Boot Maven Plugin 2.0.0.RELEASE Spring Boot Maven
Plugin
This plugin has 6 goals:
spring-boot:build-info
Generate a build-info.properties file based the content of the
current MavenProject.
spring-boot:help
Display help information on spring-boot-maven-plugin. Call mvn
spring-boot:help -Ddetail=true -Dgoal= to display
parameter details.
spring-boot:repackage
Repackages existing JAR and WAR archives so that they can be
executed from the command line using java -jar. With layout=NONE can
also be used simply to package a JAR with nested dependencies (and
no main class, so not executable).
.....
Or to get detailed information about the build goal of the dockerfile-maven-plugin :
mvn com.spotify:dockerfile-maven-plugin:help -Ddetail -Dgoal=build
[INFO] Dockerfile Maven Plugin 1.3.6
Adds support for building Dockerfiles in Maven
dockerfile:build
Available parameters:
- archive
The archive configuration to use for the Docker info JAR. This can be used
to embed additional information in the JAR.
....
You could note that the syntax to get a detailed output of the help and to focus on a specific goal (-Ddetail -Dgoal=myGoal) is exactly the same as this used for the core maven plugins.
Of course some esoteric plugins may not provide the help goal but in most of well designed plugins this is present.