Jenkins JUnit report for maven project - maven

In Jenkins I am not getting the Publish Junit test result report option in post build actions for my maven projects.
However, for freestyle projects I am getting the option, and am able to configure it properly.
Question: Is there any different approach that I need to follow for Maven projects? How can I configure JUnit for maven projects?

This is a known issue:
JENKINS-9980: Add the "Publish JUnit test result report" option to maven job configuration page
The main idea around this is that a Jenkins Maven job should publish the JUnit report automatically (so no need for this option), while in a freestyle job you may turn it to be a maven job yet having the flexibility of a freestyle/open configuration.
From comments to the JIRA ticket above, you could check suggestion on this old SO thread.
Basically, you are left with two options:
Use a freestyle Jenkins job to have full control, or
Use a Maven Jenkins job and review your pom.xml configuration or the way you are getting JUnit tests executed if the report isn't provided automatically (which could already be the case, hence end of the story).

Related

Parallel testing a Jenkins with specific tests from a maven project

I currently have a maven project with ~500 tests. These are webdriver test with the Thucydides framework. There are several types of tests such as swiping tests, article link tests, sharing tests, etc.
Details of the current setup:
* Selenium
* Thucydides
* Jenkins
I would like to run parallel tests in Jenkins but I want each jenkins job to only run a specific type of test. Is there anyway of using the "Goals and options" in the Build section in jenkins job configuration page to only run a specific type of test i.e. run only the swiping tests? or are there other options available?
Ideally I Would like to run separate jobs for each type of tests and run in parallel all those jobs together.
Not sure how to achieve it purely in Jenkins, but the first option coming to my mind is that you could create separate maven profiles for each test type and create one jenkins job per profile.
For more info on maven profiles, see official docs: http://maven.apache.org/guides/introduction/introduction-to-profiles.html

jenkins Running jobs based on packages available

i have test packages like
test.regression.pacakgea
test.regression.pacakgeb
test.regression.pacakgec
these packages are developed by different people and am running them on VMs. i have configured an email notification for success and failures for each job. people may not be interested in going thru the mail for all the failures to find out which of their tests failed. the tests inside the packages extend junit and am using maven as a build tool
so is there a way in which jenkins can execute each package as a separate job. i can make each pacakge into a different project and in jenkins i can configure this as a new job but thats too tedious as everyone has to checkin into 2 locations.
If you're using Maven:
Make a Maven profile for each package you want to test.
Configure the Surefire plugin to only include the packages you want to test in that build using a variable from that profile.
Create a different Jenkins Job for each build with one of the three profiles.
Now Jenkins will test only that package in the given class.
Note that the include/exclude only works for the test packages. Those test might test code outside of that package.

Bamboo doesn't recognize test in my Spring project

I have a Spring project (Apache CXF, Spring, Hibernate, Maven ...) hosted on BitBucket and I'm trying to use Bamboo as my CI server. My idea is deploying the code directly to Heroku from Bamboo so that deploying time is automated.
I made a plan with a couple of tasks to achieve this. First I have a Source Code Checkout task and a builder task. Both of them are working, code is compiling and test are passing, I can see that in the task log. The problem is that Bamboo doesn't seem to recognize the tests (it marks the task are testless).
I have also tried to create a new JUnit test task and it's even worst. Log shows that everything is working properly but Bamboo marks the plan as a failure after the test task is executed.
Any ideas?
Not sure which version of Bamboo you're using, but in the version that we have, you have to turn on unit test result evaluation on the Builder tab. Please see the attached screenshot, and make sure that this is enabled, and the directory setting is pointing to the directory where Maven Surefire creates the test results (in XML format).

How to run tests after deployment using Maven?

I'm trying to decide how to create a set of Acceptance Tests for a Java-EE web application.
Here's the setup: Maven is used to generate a WAR file and deploy it into Glassfish. On deployment, the MySQL database schema is automatically updated from model classes using Hibernate ("hbm2ddl=auto" option).
The Acceptance Tests need to test the deployed code by invoking various methods and checking the results are as expected(*). We wrote an additional set of packages to hook into an existing system so the Acceptance Tests should show how these can be integrated into the existing codebase.
(*) This may sound more like Unit/Integration Testing but they are Acceptance Tests in the sense that they should prove what we did works and they need to be run after deployment so there is a database in place.
From the above, my current thinking is to use JUnit to check expected values etc. The bit I'm struggling with is how to invoke these tests after deployment. "deploy" is Maven's last phase so not sure if this is possible?
Just because that phase is called deploy doesn't mean that you have to use it for deploying your application for testing. In fact, it should only be used for "deploying" the artifact to a maven repository. Read through the description of the Maven lifecycle phases and you'll see that there are some phases dedicated to your use case:
pre-integration-test
integration-test
post-integration-test
Have a look at the Cargo Maven plugin. It's made to deploy your WAR file to various containers for testing. They definitely show demos of use cases like the one you describe on your site. I would expect that ultimately, you can be using Cargo to deploy to your container ( from one of the earlier phases like pre-integration-test )
Note, Jenkins also has a plugin that is a wrapper around the Cargo plugin. So you might do what you need via Jenkins. Also note, you don't need to run your Jenkins build job as mvn clean deploy. You could have one build job that just runs the integration tests, and fires another "deploy" job only when it succeeds.
If you really need to do stuff after deployment, then you can either run failsafe, and by implication JUnit) as part of the deploy phase.
What I usually do, if to have seperate module. So, you can have one maven project, which contains your project and a separate 'deployment test' project. Then, building the parent project will build and run your war and then run the deployment tests. You can use junit as normal.
The second fits better into jenkins because you'll still have a single project as well.

Why use SonarQube plugin for Jenkins rather than simply use maven goal sonar:sonar?

I want to launch SonarQube analysis with Jenkins for a Maven 2 project. I first used the goal sonar:sonar in the build configuration.
But I just found the SonarQube plugin for Jenkins. Why use it? Is it a better practice and why?
You can of course do a simple mvn sonar:sonar, this will work.
On the other side, there's the SonarQube plugin for Jenkins that will make the configuration easier. For instance you will be able to define information about your SonarQube server (URL, DB user and password) or your multiple SonarQube servers in a single place (the configuration section of Jenkins) so that you don't have to repeat it everywhere.
The plugin also offers the ability to run a SonarQube analysis on the fly (without Maven): you just have to provide some mandatory properties (like sonar.projectKey and sonar.projectVersion for instance) and the plugin will start the Java Standalone Runner transparently for you (this is helpful mostly for other languages than Java which don't rely on Maven for their build).
So if you're just making some tests, you don't really need this plugin. But if you're setting up a production instance of Jenkins, then it's best to use the SonarQube plugin.

Resources