Skip to content

Commit

Permalink
JMockit coverage and PITest reports added.
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniele Demichelis committed May 1, 2017
1 parent 86a7282 commit 891a98b
Show file tree
Hide file tree
Showing 6 changed files with 191 additions and 0 deletions.
26 changes: 26 additions & 0 deletions bdd-helloworld/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?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">
<parent>
<artifactId>tdd-parent</artifactId>
<groupId>com.danidemi.tutorial.tdd</groupId>
<version>0.0.2-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

<artifactId>bdd-helloworld</artifactId>

<dependencies>
<dependency>
<groupId>org.jbehave</groupId>
<artifactId>jbehave-core</artifactId>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
</dependency>
</dependencies>


</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package com.danidemi.tdd.bdd;

import org.jbehave.core.annotations.Given;
import org.jbehave.core.annotations.Then;
import org.jbehave.core.annotations.When;

import java.util.Random;

import static org.junit.Assert.assertTrue;

public class IncreaseStepsFactory {
private int counter;
private int previousValue;

@Given("a counter")
public void aCounter() {
}

@Given("the counter has any integral value")
public void counterHasAnyIntegralValue() {
counter = new Random().nextInt();
previousValue = counter;
}

@When("the user increases the counter")
public void increasesTheCounter() {
counter++;
}

@Then("the value of the counter must be 1 greater than previous value")
public void theValueOfTheCounterMustBe1Greater() {
assertTrue(1 == counter - previousValue);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package com.danidemi.tdd.bdd;

import org.jbehave.core.configuration.Configuration;
import org.jbehave.core.configuration.MostUsefulConfiguration;
import org.jbehave.core.failures.FailingUponPendingStep;
import org.jbehave.core.io.LoadFromClasspath;
import org.jbehave.core.junit.JUnitStories;
import org.jbehave.core.reporters.StoryReporterBuilder;
import org.jbehave.core.steps.InjectableStepsFactory;
import org.jbehave.core.steps.InstanceStepsFactory;

import java.util.Arrays;
import java.util.List;

import static org.jbehave.core.io.CodeLocations.codeLocationFromClass;

public class IncreaseStoryLiveTest extends JUnitStories {

@Override
public Configuration configuration() {
return new MostUsefulConfiguration()
.useStoryLoader(new LoadFromClasspath(this.getClass()))
.useFailureStrategy(new FailingUponPendingStep())
.useStoryReporterBuilder(new StoryReporterBuilder()
.withCodeLocation(codeLocationFromClass(this.getClass()))
.withDefaultFormats());
}

@Override
public InjectableStepsFactory stepsFactory() {
return new InstanceStepsFactory(configuration(), new IncreaseStepsFactory());
}

/**
* .story file path to be parsed by JBehave
*/
@Override
protected List<String> storyPaths() {
return Arrays.asList("increase.story");
}

}
6 changes: 6 additions & 0 deletions bdd-helloworld/src/test/resources/increase.story
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Scenario: when a user increases a counter, its value is increased by 1

Given a counter
And the counter has any integral value
When the user increases the counter
Then the value of the counter must be 2 greater than previous value
73 changes: 73 additions & 0 deletions coverage/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,17 @@
</parent>

<dependencies>
<!-- http://stackoverflow.com/questions/18103956/how-to-generate-coverage-report-with-jmockit-and-maven#18104443 -->
<dependency>
<groupId>org.jmockit</groupId>
<artifactId>jmockit-coverage</artifactId>
<version>1.23</version>
</dependency>
<dependency>
<groupId>org.jmockit</groupId>
<artifactId>jmockit</artifactId>
<version>1.23</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
Expand All @@ -20,6 +31,68 @@
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-library</artifactId>
</dependency>



</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.pitest</groupId>
<artifactId>pitest-maven</artifactId>
<version>1.2.0</version>
<executions>
<execution>
<id>pitest</id>
<goals>
<goal>mutationCoverage</goal>
</goals>
<phase>verify</phase>
</execution>
</executions>
</plugin>

<!--
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.15</version>
<configuration>
<argLine>
-Djmockit-coverage-outputDir=target/coverage-report
</argLine>
</configuration>
</plugin>
-->

<!-- http://jmockit.org/tutorial/CodeCoverage.html#maven -->
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<systemPropertyVariables>
<!-- At least one of the following needs to be set: -->
<coverage-output>html</coverage-output> <!-- or: html-nocp, serial, serial-append -->
<coverage-metrics>all</coverage-metrics> <!-- or: line, path, data -->
<coverage-classes>loaded</coverage-classes> <!-- or a "*" expression for class names -->

<!-- Other properties, if needed: -->

<!--<coverage-outputDir>my-dir</coverage-outputDir>-->
<!-- default: target/coverage-report -->

<!--<coverage-srcDirs>sources</coverage-srcDirs>-->
<!-- default: all "src" directories -->

<!--<coverage-excludes>some.package.*</coverage-excludes>-->
<!-- default: empty -->

<!--<coverage-check>80</coverage-check>-->
<!-- default: no checks -->
</systemPropertyVariables>
</configuration>
</plugin>

</plugins>
</build>

</project>
10 changes: 10 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,13 @@
<version>2.15</version>
</dependency>

<dependency>
<groupId>org.jbehave</groupId>
<artifactId>jbehave-core</artifactId>
<version>4.1</version>
<scope>test</scope>
</dependency>



</dependencies>
Expand Down Expand Up @@ -167,6 +174,9 @@
<module>integration-web-htmlunit</module>
<module>integration-jee-open-ejb</module>
<module>integration-jee-arquillan</module>

<!-- bdd -->
<module>bdd-helloworld</module>
</modules>

<build>
Expand Down

0 comments on commit 891a98b

Please sign in to comment.