Does Maven surefire require a testng.xml file to run testng classes and methods? I have a multi module reactor setup in maven. Testng and some custom tools are located on one module and our tests are located on another module. Our structure is like this
/pom.xml
/testng-utils/pom.xml
/testng-utils/src
/tests/pom.xml
/tests/src
The tests module has a dependency on testng utils. testng-utils module brings in testng and hamcrest. Surefire is a plugin in tests/pom.xml.
I use testng annotations inside my tests, and I don't use an testng.xml file, I realize I'm providing very little information so I'm not expecting anything too in depth for an answer, just maybe a hint as to why my tests aren't being found.
Does anyone use a setup at all similar to this, and invoke testng without the use of a testng.xml file through surefire? I can try to include more information if anyone wants it if I'm able, but this is for the company I work for so I can't put much.
Thanks!
As long as you place your tests under src/test/java directory and follow the *Test.java naming convention surefire should be able to pick them up without any further configuration.
Surefire + TestNG
Related
I am working on understanding Maven and I'm learning about building your Java app with it.
So when I do a :
maven package
It does build my jar as expected but I see in the output console that Maven does build tests (it always say that the test a run and there are no failure).
I researched on the web about that and learned that Maven use a plugin called Maven Surefire. But I can't understand what does that plugin do to my code, what does the tests "means" ? What does the tests do with my code and how it works behind the console ?
The Maven surefire plugin runs the tests you have written. These are usually in the src/test/java folder. If you have none, the plugin does nothing.
Is this only one question? :D
So. Different things are going on.
You create an application with Java. To test the single components / packages / classes that you create most people use JUnit or TestNg. You usually have dedicated test classes that verify your production code behaves as intended without you clicking through all the things on every change.
When you now use maven to run your build the pom.xml file defines a packaging - in your case "jar" since you create a jar file. The packaging defines what set of default plugins run in the defined maven phases. You probably recognize package here. Maven executes all phases up to package and the registered / configured plugins.
To execute those tests maven provides the surefire plugin which supports running JUnit or TestNg tests. If you follow the directory conventions your tests reside in src/test/java and the surefire includes naming convention maven will execute those tests in every build (as this is the best practice). If you also want to write integration tests then there is the failsafe plugin. That plugin is not enabled by default and runs in different maven phases.
So the tests just run your production code - in fact they just do what you implement in the tests. They don't alter it in any way.
The maven introduction documentation has step by step explanations: Maven in 5 Minutes and the Getting Started Guide.
Starting from scratch this is probably a lot. So don't rush this. The build setup and test setup are very important things to have.
TFS and TestNG - Possible to Execute TestNG test(s) within TFS2015?
I have uploaded a Java Maven project to a Repo in my instance of TFS.
My java Maven project comprises of TestNG Test / classes
I can see that there is a Maven plugin within the TFS which also has a JUnit link.
4. I cant see any option to enable me to execute TestNG tests within the TFS, is it even possible?
It's able to use Maven task to build a Java application or test the application including TestNG test. Detail steps please refer this tutorial: Get started testing Java applications with Visual Studio Team Services
For test result report just follow juherr's reply in this question.
Yes you should be able to run your TestNG tests.
I think its eventually going to be Maven that is going to be executing your tests.
Maven makes use of surefire-plugin to basically execute your tests. For TestNG here's two of executing tests via surefire-plugin
If your test matches the default pattern "/Test*.java", "/*Test.java", "**/*TestCase.java" (See here)
Create a suite xml file for TestNG (See here) and have surefire plugin refer to it (see here).
I am working on a Maven project and am trying to exclude some tests that should not run in the build phase. However, all the guides I can find give instructions for how to exclude either through command line arguments or with the Surefire plugin. Isn't there a way to exclude the file through the pom.xml without using Surefire, as I'm not using Surefire to run the unit tests in the first place? Where would this exclusion go?
Surefire is the name of the framework for executing tests (it's an abstraction layer for the specific tool). It support JUnit, TestNG and others. To exclude tests by pom.xml, have a look at http://maven.apache.org/surefire/maven-surefire-plugin/examples/inclusion-exclusion.html
I am trying to set the "name" option for Cucumber to be able to run a specific feature or scenario.
I have entered this,
mvn test -DCucumber.Options--name="MyFeatureName"
but it just runs all the features and doesn't give an error.
Any ideas?
Here is a snippet from the Cucumber-JVM repo on how to run the java-helloworld example by passing cucumber options:
mvn test -Dcucumber.options="--format json-pretty --glue classpath:cucumber/examples/java/helloworld src/test/resources"
Keep in mind that it will override all the options in the #Cucumber.Options annotation you have on "RunCukesTest". I haven't got it to work for my own tests but maybe this will help.
So it looks like you need to give all the options needed to run cucumber, including the java class path and where the code is located using the "--glue" parameter.
Your tests are running in separate JVM, so you need to specify that system property in the test plugin configuration (i.e. surefire or failsafe plugin config in your pom.xml).
I'm looking at adding TestNG support to http://pitest.org and could do with some real and dirty code to try it out on.
Can anyone suggest some smallish open source projects that are build using maven and use TestNG for unit testing?
For clarity - I am not asking how to configure maven to use TestNG, I am looking for some example projects to use as input to a mutation testing tool.
Off the top of my head, Seam and Tapestry both use TestNG. Obviously, TestNG itself uses TestNG.
There is also a lot of activity on the Selenium front, check out the Selenium boards.
Usually you only need to add the testng dependency to your pom with scope test and surefire will handle that already...(may be you need to update surefire plugin).