I have a testng.xml file to bring in parameters into my test software.
<suite name="My suite">
<parameter name="first-name" value="Cedric"/>
<test name="Simple example">
<-- ... -->
I would like to know how to run a exclude test while using the testng.xml file via command line only.
mvn -DexclueTest=!apiXMLTest test
If any packages are needing to be installed or uninstalled this would help.
mvn install -Dmaven.test.skip=false
Maven packages are all up to date.
I know exactly what you need.
mvn test -DexcludedGroups=Broken
Then add the tag to your test
groups = {"con" , "Broken"},
Or if you are using Groovy (Bleh)
groups = ['con' , 'Broken'],
Yeah Dtest doesnt work do to the xml grouping
It maybe because your are on unix or cmd but try
mvn -Dtest=!%regex[.*.RESTTest.class#apiXMLTest.*]
test
Related
I have wrote a piece of code in Junit. I need to run it without eclipse. Any suggestions how can I do that ?
Since Eclipse 2018-09 in Java Application and JUnit launch configurations there is a button Show Command Line for that.
See also: video that shows this feature in action
Yes, you have an option to run your test cases in command line,
Example:
As you are running the mvn clean install for building your application,
In the same way, you can also run your test cases as well by using the command.
1. Command to compile your test class >> **javac -cp junit-4.12.jar;. UserDAOTest.java ProductDAOTest.java** --> general command is >> **javac -cp <junit-jar-file>;. TestClass1.java TestClass2.java**
2. Run the test cases >> ** java -cp <junit-jar>;<hamcrest-jar>;. org.junit.runner.JUnitCore TestClass1 TestClass2 **
3. Running the unit test cases by Maven Command Line >> mvn test >> mvn clean test >> mvn clean compile test
The location to my project is C:\Users\ess\workspace\myproject1. I tried to generate the wsdl file via the mvn command but this error appeared
The goal you specified requires a project to execute but there no pom in this directory c:\users\ess
and Maven home is c:\program files\apache-maven-3.1.0
Any idea?
You need to change to the directory where your pom.xml sits:
cd C:\Users\ess\workspace\myproject1
Make sure your pom.xml is located inside myproject1
Now run the maven command.
If still the error comes, please share your complete maven output.
the location where you are trying to execute the command is not the root directory of the maven project. Check whether at this location C:\Users\ess you have pom.xml, i don't think you have.
Now go to this location C:\Users\ess\workspace\myproject1 and try to run the same command again.
A newbie question on Maven - Surefire - Eclipse - JUnit
I have configured the maven-surefire-plugin in the pom file of my project to pass some additional JVM arguments as below:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>${maven.surefire.plugin.version}</version>
<configuration>
<argLine>-d64 -Xms128m -Xmx4096m -XX:PermSize=512m -Duser.timezone=UTC -XX:-UseSplitVerifier</argLine>
</configuration>
</plugin>
When I run a test case of this project from Eclipse as Run As->JUnit Test, though the classpath is correctly set, the additional arguments specified in the argLine are not included in the invocation. I have to go and manually key in the arguments under the relevant Debug Configurations. I don't quite understand how JUnit is aware that it needs to put jars of the test scope on the classpath and in some way means that JUnit tool in Eclipse is aware of Maven via M2E? If so, how can we make it also read argLine. I know this sounds very specific - but how do others manage in similar situations?
Thanks in advance!
Eclipse JUnit Launcher (choose Run As -> JUnit Test) is a independent test runner which has its own pre-defined build and running life cycle and has nothing to do with Maven, it will not pick up your pom magically and read in the surefire configuration and use them to drive the test running.
If your project is imported as an existing Maven project, use Maven (choose Run as -> Maven test) launch your JUnit test which will pick up and use the surefire configuration. This is exactly same as running mvn test from commandline, it only output run log in console and you will not able to use the nice red & green JUnit UI window.
Hope this make sense.
I have a project with src, classes & tests. I keep my JUnit tests in the tests folder.
I keep getting a ClassNotFoundException while running them in Eclipse.
I tried running them using from the Command line.
javac -d classes src\brick\*.java test\brick\*.java
The compiler reports 20 errors telling me that the package org.junit does not exist.
Could anybody help me?
Thanks.
What are you using to manage your dependencies (maven, contained in a lib dir)? Are all of the necessary jars in your classpath?
Javac needs to know where your JUnit jar is located in order to compile your classes.
You should try something like:
javac -cp <path to junit jar> -d classes src\brick\*.java test\brick\*.java
When in Eclipse, you need to add the JUnit jar to your project. Normally this is
done automatically if you have a test case...
We have a multi-module Maven setup with a master pom.xml that includes all the others. So mvn test from the root directory runs all our unit tests, with textual output.
I can do Run / Run As / JUnit Test to run a single test class with a graphical test runner.
Question: How do I combine the two, so that I can run all the tests that mvn test runs but with a graphical runner, like the one from Run / Run As / JUnit Test?
Create an eclipse project with all your modules as Maven Dependecies and then create a JUnit Suite which incorporates all tests. Eclipse's JUnit Runner then will execute all declared Tests if you run this suite.
In Eclipse Juno, assuming your project is a Maven Project, you can just right click the project name in the Project Explorer and select Run As ... jUnit test. Alternatively you can produce the same text output you get from mvn test by selecting Run As ... Maven test