Eclipse and Junit, skipover some testcase with some pattern - eclipse

000 unit test in one application. I know in one particular folder, all the tests takes long time, I donot want to test these cases everytime I run unit test. So may I have some property file to indiciate a pattern/folder which test cases shall skip?
I am using mvn. Java 1.6.

Take a look at Maven Surefire Plugin: Inclusions and Exclusions of Tests.
To exclude certain tests you can use:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.9</version>
<configuration>
<excludes>
<exclude>**/TestCircle.java</exclude>
<exclude>**/TestSquare.java</exclude>
</excludes>
</configuration>
</plugin>
Alternatively, on the command line, you can explicitly specify which tests you want to run. For example:
mvn -Dtest=TestSquare,TestCi*le test

Related

how to run both tests scalatest and junit?

I have a project, there are some Scala tests for Scala code, as well as junit tests for Java. How to run Scala and Junit tests with Maven.
Project is multi-modular, with scala and java modules.
You may have to manually specify the Java tests a work-around would be something like this
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.12</version>
<configuration>
<includes>
<include>**/*Suite.class</include>
<include>**/*Tests.class</include>
<include>**/*Spec.class</include>
<include>**/*Specs.class</include>
</includes>
</configuration>
</plugin>

Having only a JAR Maven Archetype file, how can it be generated a new project?

I'm just starting with Maven 3 for an Scala project in IntelliJ.
I have generated a JAR file following this guide.
I moved archetype.jar to a directory in where I want to create a new project. But my questions are:
Is this file stand-alone? Is it enough? It does not work with the command "mvn archetype:generate"
Is it possible to use the jar file without the intervention of any repository? So I can share it with collegues.
What's the best method for this, I've been reseaching and all the guides are based on repositories only and not in working local. Even the local repositories only consists in xmls files with the id but not the contents.
This is a sort of complex question you are asking...I am going to try summarise what I know and let's see if it helps.
Answers to your questions:
1) If you have just the basic Maven Project structure after you have generated the archtype and so on, if you run maven clean install and the project produces a jar, this in theory should be immediately executable from the command line and standalone.
However, as you add dependencies to your small projects, not all dependencies are automatically built into the standalone jar, sometimes you have to tell maven to bundle them into it.
Maven Shade Plugin - adds all the needed dependencies into your jar
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
</execution>
</executions>
<configuration>
<transformers>
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<mainClass>MainApp</mainClass>
</transformer>
<transformer implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer"/>
</transformers>
<shadedArtifactAttached>true</shadedArtifactAttached>
<shadedClassifierName>launcher</shadedClassifierName>
</configuration>
</plugin>
</plugins>
</build>
2) You do not need to integrate to any repository, its recommended for wider projects so that you can publish artifacts to your firms Repo for eas of use between developers
3) The easiest method is to create a new project in Intellij itself specifying Maven as the project type and that will give you the default project structure. In the pom file you then specify the build block I pasted above and you are essentially good to go...If you need Dependencies also t run your own code you will need to add them in a Dependencies block.
So, I finally used the following command before generating:
mvn install:install-file -Dfile=<path-to-jar-archetype-file> -DgroupId=<groupId> -DartifactId=<artifactId> -Dversion=<version> -Dpackaging=jar
After executing the command, the jar is installed in your local repo. You can generate the project with for instance IntelliJ or go to the path where you want to generate the project and...
mvn archetype:generate

How to execute SoapUI testcases for Cucumber scenarios?

I have a project in Eclipse with Maven, Cucumber, SoapUI and JUnit.I have been able to successfully build it without errors (Yay! I am new to Maven, SoapUI and Cucumber).
This project has a Cucumber feature file with two scenarios. I have the following configuration for SoapUI in pom.xml file
.
.
<pluginRepositories>
<pluginRepository>
<id>smartbear-sweden-plugin-repository</id>
<url>http://www.soapui.org/repository/maven2/</url>
</pluginRepository>
</pluginRepositories>
<build>
<plugins>
<plugin>
<groupId>com.smartbear.soapui</groupId>
<artifactId>soapui-pro-maven-plugin</artifactId>
<version>4.6.1</version>
<executions>
<execution>
<phase>test</phase>
<goals>
<goal>test</goal>
</goals>
<configuration>
<projectFile>soapui-project.xml</projectFile>
<outputFolder>soapuiOut</outputFolder>
<junitReport>true</junitReport>
<exportwAl>true</exportwAl>
<printReport>false</printReport>
</configuration>
</execution>
</executions>
</plugin>
.
.
Currently when I build it with maven, it runs the whole SoapUI project with all test cases in it. I want to link the two test cases in SoapUI to the two scenarios in the feature file. Is it possible to run a single testcase from SoapUI test suite in test step definition for a scenario? The scenario should pass only if the SoapUI testcase related to it passes.
Q: Is it possible to run a single testcase from SoapUI test suite in test step definition for a scenario?
A: Sure, use testCase in your configuration, as per documentation here: http://www.soapui.org/Test-Automation/maven-2x.html#5-1-test-settings
One small comment: You mentioned you are new to Maven. If you wish to make you project much more Maven-ized, place your soapui-project.xml in src/test/soapui, and adjust your pom.xml accordingly.

Maven with TestNG and Selenium, TestNG file being ignored

Story: So I am running a WebDriver2 test suite with TestNG and all that's bundled up in a Maven architecture. I built everything in Eclipse project first, then converted this over to a Maven project. I am not a programmer but I can hack my way through Java, I am new to Maven but pretty good with TestNG and Selenium and from everything I have researched I am approaching this correctly, I have to be missing something stupid.
Problem: I am running this all in Eclipse with Maven plugin, when I run POM as TEST I get an error:
org.testng.TestNGException: Parameter 'dataMode' is required by #Configuration of method prepareDriver but has not been marked #Optional or defined
So POM setup thusly for SureFire to grab my file, testNG dependency also set and appears to work since my error is coming from TestNG itself:
<plugins>
[...]
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.12</version>
<configuration>
<suiteXmlFiles>
<suiteXmlFile>src\test\resources\testng.xml</suiteXmlFile>
</suiteXmlFiles>
</configuration>
</plugin>
[...]
</plugins>
I have also passed in the parameters to this plugin as well:
<systemPropertyVariables>
<dataMode>Custom</dataMode>
</systemPropertyVariables>
<systemPropertyVariables>
<log_level>DEBUG</log_level>
</systemPropertyVariables>
Everything in my TestNG file is correct, if I run as a TestNG test just from the testng.xml everything runs like it is supposed to, if you want that code I will update but that part works, parameters are in there correctly.
Also, when I execute the POM as TEST I get a report that 2 out of 11 tests failed... I don't have 11 tests, if you go by my testNG.xml I have only 2 #Test's that it would find, I think it's counting every TestNG annotation in this portion of my test-suite...
My theory is that it's trying to run without the TestNG file and just running every TestNG annotation in any file it finds but I don't have it setup to do that, or do I?
Try something like this:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.19</version>
<configuration>
<suiteXmlFiles>
<suiteXmlFile>testng.xml</suiteXmlFile>
</suiteXmlFiles>
<systemProperties>
<property>
</property>
</systemProperties>
</configuration>
</plugin>

Replace Maven Site Plugin with GWT Compile Plugin

I have successfully set up a few projects which use Maven to automatically deploy the Maven-generated site to the gh-pages branch of their git repository. GitHub then serves these files at a public URL on a personal subdomain. I'm looking to utilize this functionality to serve a rich client-side only GWT application.
I have modified my pom.xml to compile the GWT application to the target/site/ directory. The two main goals I am still attempting to achieve are:
How do I prevent the standard Maven site plugin from running during the site phase?
What is required so gwt:compile executes during the site phase?
A goal can be bound to a phase by specifying a new execution for the plugin. I'm assuming you've got some custom stuff you need to make most of this work correctly, so I'm just going to focus on what should work to bind a plugin goal to a particular phase.
<plugin>
<artifactId>gwt-maven-plugin</artifactId>
...
<executions>
<execution>
<id>gwt-site</id>
<phase>site</phase><!-- phase to bind to -->
<goals>
<goal>compile</goal><!-- goal to run in that phase -->
</goals>
<configuration>
<!-- Your magic configuration stuff goes here -->
</configuration>
</execution>
<!-- Possible other executions might be defined here -->
</executions>
</plugin>
Preventing the default maven site from being run is more interesting, as it is a phase, with a variety of goals bound to it. The standard site:site goal can be prevented from running in the site phase by explicitly specifying an execution with no goals. This may vary slightly from maven 2 to 3, so I'm going to be a little general here. Take a look at your build logs to see what is currently specified in terms of execution id, group/artifact id to correct possible oversights in my example:
<plugin>
<artifactId>maven-site-plugin</artifactId>
...
<executions>
<execution>
<phase>site</phase>
<goals></goals><!-- This is empty to indicate that no goals should be run in this phase -->
</execution>
</executions>
</plugin>