How to collect statistics about java integration tests - java

My development environment includes Maven, Failsafe and Spring testing IS (AbstractJUnit4SpringContextTests).
I'm looking for a way to collect statistics about the integration tests run.
Information such as Test duration, process memory, etc...
What is the best way to collect such information with the above configuration (and to integrate with the maven flow).

as far as i recall, the surefire plugin is able to write reports to some directory (which will be used by e.g. jenkins to present results)

There is a maven plugin for Sonar. It is highly configurable, maybe solution to your problem.

The failsafe plugin generates a xml file with the tests result. this can be used, for example by a jenkins plugin.

Related

Use Karate framework with Fail Safe and Sure Fire plugin [duplicate]

Is there a way to run Karate test during maven's integration test phase? It seems that surefire plugin is hardcoded into Karate. I have tried to override it using failsafe plugin but with no luck. I don't want test to run along with unit tests.
Thank in advance!
It seems that surefire plugin is hardcoded into Karate
I'm not sure where you got that impression, but no, the surefire plugin is not hardcoded into Karate.
Keep in mind that the simplest way to not run a JUnit test via surefire is to not use the *Test.java naming convention.
I think the solution for you is simple, whichever JUnit test is the "entry-point" for your Karate tests (the parallel runner is recommended) - just use the failsafe naming conventions.
And then, just include the failsafe plugin as per the examples and it should work. If you have trouble getting that to work (unlikely), then you should look at maven profiles.
EDIT: also see this comment: Is there a way to run Karate tests as an integration test suite against a pre-booted spring boot server?
Turns out that I cannot be done and it is a limitation of Maven, not Karate. Howto add another test source folder to Maven and compile it to a separate folder? - Here is my test project to prove it out: https://github.com/djangofan/spring-boot-hello - Thanks for leading me down what appears to have been the correct path to discover the limitation. Using Gradle would likely solve my issue but that is not an option on my project. If I use Karate for "separated integration tests", I need a separate mvn test module.

Check java coding styles using jenkins plugin

Does anyone know a jenkins plugin for Java that analyses the coding styles and fails the build (not only provide a report) in case there are styles violations?
You can use Findbugs and Checkstyle for the same.
https://plugins.jenkins.io/checkstyle
https://plugins.jenkins.io/findbugs
Jacoco is used to unit test coverage and not really for static analysis.
the solution is to use a plugin of your build tool(like jacoco plugin in your pom for maven build).
And then configure your jenkins pipline to fail if quality is not satisfying

Getting Integration tests code coverage of java project built using TestNG

I wanted to get code coverage of regression tests,which tests java webserver endpoints.
Things I have
1. I am having jar file of source
2. Regression code written using TestNG framework.
So here, I will run this jar file to run webserver and then I will run my regression code which will test running webserver.Here I wanted to get code coverage report of Regression tests.Can anyone give any suggestion ?
You can use EMMA(A free code coverage tool). If you are using eclipse you can directly get it from market place. Also it supports running individual Java class file or jar file. Here is the link for more information.
http://emma.sourceforge.net/intro.html
If you're using Maven, you can have a look at qualinsight-maven-cobertura-mojo. There is a companion Github project that provides examples showing how to use it along with jetty (versions 7.6.x, 8.1.x, 9.2.x, 9.3.x). In the exmaples JUnit is being used, but it has no impact at all on the result, you can use TestNG if you want to.
The example shows how to use this Maven plugin and configure your project in order to:
Instrument your code for coverage with qualinsight-maven-mojo-core
run your Jetty server and deploy instrumented code
run your tests (you'll have to replace Junit tests by TestNG ones, and make sure they are run during the integration-test phase)
stop your Jetty server (this will dump coverage file to disk)
Generate coverage report
If needed coverage reports can then be imported in SonarQube using the Generic Coverage plugin (see documentation.)
Note that this plugin has some advantages and limitations compared to cobertura-maven-plugin (see its documentation), but given the description of your requirements, none of the limitations seems to be a blocker in your context.

Can I do these using Code Coverage with Cobertura

I am just looking at the cobertura maven plugin and I wasnt sure if the following is possible
Instrument classes
Run junit tests
Generate Cobertura report without reinstrumenting classes and running tests
I have a multi module maven project and the coverage of the domain module is showing up as 0% even though its been used by every other module
I have tried different combinations of things but the coverage of my domain module always stays at 0%.
People have mentioned writing separate tests for the domain classes but i dont want to do this as you could easily write a tests to test a function that isn't actually being used anywhere within the codebase
Any pointers would be greatly appreciated
In order to do so you would have to execute the maven goals in the correct order so :
cobertura:instrument
test
goalToAskCoberturaToGenerateReport
But then comes the trouble : there is no such goal as cobertura:report, if you look at the documentation and source code of the maven plugin : The goal cobertura:cobertura is the only goal generating the report. I suspect it is as such because of some maven internal limitation.
So in short, given the state of the maven plugin it is not possible.
You might have a chance to manage what you want to achieve by executing cobertura from the command line.
For multi-module maven projects cross-module coverage seems not to be available off-the-shelf with Cobertura.
A solution using a mixture of maven and ant is described byThomas Sundberg:
http://thomassundberg.wordpress.com/2012/02/18/test-coverage-in-a-multi-module-maven-project/
See also this related question:
Maven2 Multiproject Cobertura Reporting Problems During mvn site Build

Maven: running Unit-Tests remotely

We are currently working on a distributed Java EE-Application and have therefore a separated test and production system.
Compiling and Bundling is done via an Ant-Task. Now we want to deploy the Jar-Files of the different servers to the test-servers and run the JUnit Integration / Function-Tests there. If they succeed, then the current version should be deployed to the live-servers.
Plain Unit-Tests are executed by Hudson.
Is that possible with Maven and is there any information or best practice available?
Yes. Hudson has maven integration. Take a loot this wiki and this link.
You can set unit test case thresholds for your job to see if it does not pass a certain number of test cases. In that the deploy plugin will not get invoked and the app will not get deployed.
Take a JAR built from Ant and reuse it. I would add a Maven repository to your environment such as Artifactory, Archiva, or Nexus and deploy to that using Ivy. You almost certainly need to use a Maven repository to be happy with Maven for anything other than small scale personal projects. http://ant.apache.org/ivy/
Use Maven to grab the JAR from the Maven Repository. For this, just use a normal Maven dependency declaration.
Run Maven on the QA server, with the JUnit tests declared in that project. If that succeeds, deploy the JAR to the production server. For this, the details depend on the production server. If it's a WAR, I would use Cargo, but if it's a JAR it really depends on what's executing the JAR - you might need some sort of file copy, scp, etc. http://cargo.codehaus.org/
Hudson and TeamCity both have deployment features as well. You just set up a job to run (in this case the Maven job) and tell the CI server to deploy on success.

Categories