-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit f62ddda
Showing
22 changed files
with
1,370 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
target | ||
.idea | ||
*.iml | ||
*.log |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
|
||
# Capturing remote/ui acceptance test code coverage results using JaCoCo | ||
|
||
## Prerequisites | ||
|
||
The below describes an example setup of Sonar using MySQL as db backend (see also http://chapter31.com/2013/05/02/installing-sonar-source-on-mac-osx/) and has been | ||
tested with MySQL 5.6, SonarQube 4.3.1 and Maven 3.0.5 | ||
|
||
1. MySQL for SonarQube (e.g.) | ||
|
||
OSX: $>brew install mysql | ||
|
||
create the sonar database using e.g. [create_database.sql](https://github.com/SonarSource/sonar-examples/blob/master/scripts/database/mysql/create_database.sql) | ||
|
||
``` | ||
# File: create_database.sql | ||
# Create SonarQube database and user. | ||
# Command: mysql -u root -p < create_database.sql | ||
# | ||
CREATE DATABASE sonar CHARACTER SET utf8 COLLATE utf8_general_ci; | ||
CREATE USER 'sonar' IDENTIFIED BY 'sonar'; | ||
GRANT ALL ON sonar.* TO 'sonar'@'%' IDENTIFIED BY 'sonar'; | ||
GRANT ALL ON sonar.* TO 'sonar'@'localhost' IDENTIFIED BY 'sonar'; | ||
FLUSH PRIVILEGES; | ||
``` | ||
2. Download and run [SonarQube](http://www.sonarsource.org/downloads/) 4.3 or higher | ||
OSX: | ||
a) $>brew install sonar | ||
b) with (at least) version 4.3.1 there may be a conflict with the currently installed version of ruby on your system (see https://jira.codehaus.org/browse/SONAR-3579) | ||
in order to fix that, open /usr/local/Cellar/sonar/4.3.1/libexec/web/WEB-INF/config/environment.rb and after the line | ||
``` | ||
ENV['GEM_HOME'] = $servlet_context.getRealPath('/WEB-INF/gems') | ||
``` | ||
add | ||
``` | ||
ENV['GEM_HOME'] = $servlet_context.getRealPath('/WEB-INF/gems') | ||
# avoid ruby version conflicts | ||
ENV['GEM_PATH']='' | ||
``` | ||
c) ensure you have the Sonar Java plugin installed | ||
open http://localhost:9000, login as admin/admin and go to Settings->System->Update Center to install the Java plugin | ||
3. Maven 3.0.5 | ||
OSX: $>brew install maven30 | ||
## Running | ||
from the toplevel folder of the project run | ||
``` | ||
$>mvn clean install | ||
$>mvn sonar:sonar | ||
``` | ||
Now open the project dashboard in Sonar. You should see the IT coverage at 44.1%. Drill down and you should see that both methods (home(), edit()) in HomeController are covered by integration tests. | ||
## Steps to configure your own project | ||
1. *absolute* file path for jacoco-it.exec coverage record | ||
2. add javaagent to target jvm with output=none | ||
3. add jacocoremotelistener controller to your application | ||
## How does it work | ||
## TODO | ||
*) read target url in junit listener from config property | ||
*) migrate from spring mvc controller to servlet/filter for better reuse | ||
*) maybe no need to dump() after every request? IT don't support per-test coverage anyway | ||
## Useful Links | ||
http://docs.codehaus.org/display/SONAR/Analysis+Parameters | ||
http://www.eclemma.org/jacoco/trunk/doc/examples/java/ExecutionDataClient.java | ||
http://www.eclemma.org/jacoco/trunk/doc/examples/java/ReportGenerator.java | ||
https://groups.google.com/forum/#!topic/jacoco/04MOA-C22SM | ||
http://docs.codehaus.org/display/SONAR/Code+Coverage+by+Unit+Tests+for+Java+Project | ||
http://dougonjava.blogspot.co.il/2013/07/integration-testing-using-maven-tomcat.html | ||
https://github.com/SonarSource/sonar-examples | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<parent> | ||
<groupId>sample</groupId> | ||
<artifactId>reactor</artifactId> | ||
<version>0.0.1-SNAPSHOT</version> | ||
</parent> | ||
|
||
<artifactId>acceptance-tests</artifactId> | ||
<packaging>jar</packaging> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>junit</groupId> | ||
<artifactId>junit</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>${project.groupId}</groupId> | ||
<artifactId>web</artifactId> | ||
<version>${project.version}</version> | ||
<classifier>classes</classifier> | ||
<scope>test</scope> | ||
</dependency> | ||
</dependencies> | ||
|
||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.eclipse.jetty</groupId> | ||
<artifactId>jetty-maven-plugin</artifactId> | ||
<executions> | ||
<execution> | ||
<id>stop-jetty</id> | ||
<phase>post-integration-test</phase> | ||
<goals> | ||
<goal>stop</goal> | ||
</goals> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
|
||
</plugins> | ||
</build> | ||
|
||
</project> |
35 changes: 35 additions & 0 deletions
35
acceptance-tests/src/test/java/uk/co/postoffice/spike/esi/helloworld/HomeControllerAT.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package uk.co.postoffice.spike.esi.helloworld; | ||
|
||
import org.junit.Before; | ||
import org.junit.Test; | ||
import sun.misc.IOUtils; | ||
|
||
import java.io.*; | ||
import java.net.URL; | ||
|
||
import static org.hamcrest.CoreMatchers.containsString; | ||
import static org.hamcrest.CoreMatchers.equalTo; | ||
import static org.hamcrest.MatcherAssert.assertThat; | ||
|
||
/** | ||
* @author Erich Eichinger | ||
* @since 05/06/2014 | ||
*/ | ||
public class HomeControllerAT { | ||
|
||
@Test | ||
public void home_should_render_helloFromHOME() throws Exception { | ||
final String strUrl = "http://localhost:8080/home"; | ||
final byte[] bytes = fetchBytes(strUrl); | ||
|
||
String content = new String(bytes); | ||
|
||
assertThat(content, containsString("Hello from HOME")); | ||
} | ||
|
||
private byte[] fetchBytes(String strUrl) throws IOException { | ||
URL url = new URL(strUrl); | ||
return IOUtils.readFully((InputStream) url.getContent(), -1, true); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<parent> | ||
<artifactId>reactor</artifactId> | ||
<groupId>sample</groupId> | ||
<version>0.0.1-SNAPSHOT</version> | ||
</parent> | ||
|
||
<artifactId>integration-tests</artifactId> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>junit</groupId> | ||
<artifactId>junit</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>${project.groupId}</groupId> | ||
<artifactId>web</artifactId> | ||
<version>${project.version}</version> | ||
<classifier>classes</classifier> | ||
<scope>test</scope> | ||
</dependency> | ||
</dependencies> | ||
|
||
</project> |
19 changes: 19 additions & 0 deletions
19
integration-tests/src/test/java/uk/co/postoffice/spike/esi/helloworld/HomeControllerIT.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package uk.co.postoffice.spike.esi.helloworld; | ||
|
||
import org.junit.Ignore; | ||
import org.junit.Test; | ||
|
||
import static org.hamcrest.CoreMatchers.*; | ||
import static org.hamcrest.MatcherAssert.*; | ||
|
||
/** | ||
* @author Erich Eichinger | ||
* @since 03/06/2014 | ||
*/ | ||
public class HomeControllerIT { | ||
|
||
@Test | ||
public void edit_should_return_editview() throws Exception { | ||
assertThat(new HomeController().edit(), equalTo("edit")); | ||
} | ||
} |
Oops, something went wrong.