Rechercher dans ce blog

Affichage des articles dont le libellé est cobertura. Afficher tous les articles
Affichage des articles dont le libellé est cobertura. Afficher tous les articles

samedi 28 avril 2012

6. Code coverage

Maven post was not containing the full configuration. For simplicity sake, I deliberately removed the code coverage section.

Now that jenkins and maven are configured, we can now take some time to configure the code coverage. For this part, I use Cobertura because it runs under Jenkins and it is easy to use...

To configure it, there are two things to do:


  1. Configure the Maven configuration 
  2. Configure Jenkins to support Cobertura

Configure Maven

To configure maven, we have to edit the project pom.xml to set that cobertura must be run. We will run cobertura during the package goal:

 
49    
50    
51       <profiles> 
52           <!-- Jenkins by default defines a property BUILD_NUMBER which is used to enable the profile. --> 
53           <profile> 
54               <id>jenkins</id> 
55               <activation> 
56                   <property> 
57                       <name>env.BUILD_NUMBER</name> 
58                   </property> 
59               </activation> 
60               <build> 
61                   <pluginManagement> 
62                       <plugins> 
63                           <plugin> 
64                               <groupId>org.codehaus.mojo</groupId> 
65                               <artifactId>cobertura-maven-plugin</artifactId> 
66                               <version>2.5.1</version> 
67                               <configuration> 
68                                   <formats> 
69                                       <format>xml</format> 
70                                   </formats> 
71                               </configuration> 
72                               <executions> 
73                                   <execution> 
74                                       <phase>package</phase> 
75                                       <goals> 
76                                           <goal>cobertura</goal> 
77                                       </goals> 
78                                   </execution> 
79                               </executions> 
80    
81                           </plugin> 
82                       </plugins> 
83                   </pluginManagement> 
84    
85                   <plugins> 
86                       <plugin> 
87                           <groupId>org.codehaus.mojo</groupId> 
88                           <artifactId>findbugs-maven-plugin</artifactId> 
89                           <version>2.4.0</version> 
90                           <executions> 
91                               <execution> 
92                                   <phase>package</phase> 
93                                   <goals> 
94                                       <goal>findbugs</goal> 
95                                   </goals> 
96                               </execution> 
97                           </executions> 
98                       </plugin> 
99                   </plugins> 
100              </build> 
101          </profile> 
102      </profiles>

A few explanations are needed:

  • We set here a profile: that means this goal is run only when a particular "user" is running the target. It is good in this case because cobertura will not be run in developer's environment but only by jenkins
  • The plugin is specified to run during the package phase

Configure Jenkins

Now that maven is configured, we can configure Jenkins to use cobertura and this is quite easy:

  1. Install the Cobertura plugin: Jenkins Cobertura plugin. It will be installed with a couple of dependencies.
  2. Go in the project settings and set that you want to run the following goals:
    • package: to run cobertura
    • cobertura:cobertura: to build the result
  3. Go in the project settings and set that you want to display the coverage report. You are asked for a report pattern: set: **/target/site/cobertura/coverage.xml. This will inform cobertura where the pattern are stored and that they are in xml (exactly what we set in the pom.xml.
Now you can run a build and you will see the code coverage of the project.

jeudi 12 avril 2012

1. Introduction

When I look for projects, I usually found some code samples on a particular technology but it is quite rare to find:
  • How to install the test framework
  • How to put the project in production
  • How to use the VCS
The goal of this blog is to introduce a small project and explain the different steps of development. I will not go in details and will only provide a small overview of the project.

Overview

The goal of the project is to provide a map where you can see all the yoctopuce devices from the people who have come on the page. Yoctopuce provide a meteo sensor device that can be plugged through USB. In this project, we would like to have the following flow:


  1. An user goes on the web page with his browser
  2. The web page is loaded and tries to contact known yoctopuce device URL: http://127.0.0.1:4444
  3. If it is successful
    1. The Web page analyzes which yoctopuce devices are plugged
    2. The Web page stores the data in the database with the current location
  4. The webpage loads and displays the world map with all the yoctopuce devices stored in the database




In this blog, I will describe:
  1. Prepare GIT to store the source code
  2. Configure the maven project
  3. Configure and install a virtual appliance with Jenkins
  4. Run a code coverage with Cobertura in Jenkins
  5. Use yoctopuce devices
  6. Basic introduction of java API for yoctopuce
  7. GWT introduction
  8. Put in production with google app engine