Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Foresight Workflow with Cobertura Integration #2

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 11 additions & 7 deletions .github/workflows/foresight.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,12 @@ on:
pull_request:
branches: [ "master" ]
workflow_dispatch:
schedule:
- cron: "0 1 * * *"

env:
FORESIGHT_UPLOADER_SIGNER_URL: https://upload.service.runforesight.us
WORKFLOW_TELEMETRY_BASE_URL: https://api.service.runforesight.us

jobs:
build:
Expand All @@ -21,21 +26,20 @@ jobs:
with:
api_key: ${{ secrets.FORESIGHT_API_KEY }}

- name: Set up JDK 11
- name: Set up JDK 8
uses: actions/setup-java@v3
with:
java-version: '11'
java-version: '8'
distribution: 'temurin'
cache: maven

- name: Build with Maven
run: mvn clean install
run: mvn clean -fn install


- name: Analyze Test and/or Coverage Results
if: always()
uses: thundra-io/foresight-test-kit-action@v1
uses: runforesight/foresight-test-kit-action@v1
with:
api_key: ${{ secrets.FORESIGHT_API_KEY }}
test_framework: junit
test_path: "**/target/surefire-reports/**"
coverage_format: cobertura/xml
coverage_path: "**/target/site/cobertura/*.xml"
65 changes: 15 additions & 50 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,55 +1,20 @@
[![Maven Central](https://maven-badges.herokuapp.com/maven-central/com.pholser/property-binder/badge.svg?style=plastic)](https://maven-badges.herokuapp.com/maven-central/com.pholser/junit-quickcheck)
[![Build Status](https://travis-ci.org/pholser/junit-quickcheck.svg?branch=master)](https://travis-ci.org/pholser/junit-quickcheck)
[![Code Quality: Java](https://img.shields.io/lgtm/grade/java/g/pholser/junit-quickcheck.svg?logo=lgtm&logoWidth=18)](https://lgtm.com/projects/g/pholser/junit-quickcheck/context:java)
[![Total Alerts](https://img.shields.io/lgtm/alerts/g/pholser/junit-quickcheck.svg?logo=lgtm&logoWidth=18)](https://lgtm.com/projects/g/pholser/junit-quickcheck/alerts)

<a href="http://www.yegor256.com/2015/10/17/award-2016.html">
<img src="http://www.yegor256.com/images/award/2016/winner-pholser.png" width="203" height="45" alt="Software Quality Award 2016"/>
</a>

# junit-quickcheck: Property-based testing, JUnit-style

junit-quickcheck is a library that supports writing and running property-based
tests in JUnit, inspired by QuickCheck for Haskell.

Property-based tests capture characteristics, or "properties", of the output
of code that should be true given arbitrary inputs that meet certain criteria.
For example, imagine a function that produces a list of the prime factors of
a positive integer `n` greater than 1. Regardless of the specific value of
`n`, the function must give a list whose members are all primes, must
equal `n` when all multiplied together, and must be different from the
factorization of a positive integer `m` greater than 1 and not equal to
`n`.

Rather than testing such properties for all possible inputs, junit-quickcheck
and other QuickCheck kin generate some number of random inputs, and verify
that the properties hold at least for the generated inputs. This gives us
some reasonable assurance upon repeated test runs that the properties
hold true for any valid inputs.
## runforesight.com Demo Projects - Junit Quickcheck

## Documentation

[Documentation for the current stable version](https://pholser.github.io/junit-quickcheck/index.html)

## Basic example

```java
import com.pholser.junit.quickcheck.Property;
import com.pholser.junit.quickcheck.runner.JUnitQuickcheck;
import org.junit.runner.RunWith;

import static org.junit.Assert.*;
<a href="https://demo.app.runforesight.com/repositories/github/runforesight-demo/junit-quickcheck/workflow-runs">
<img src="https://4750167.fs1.hubspotusercontent-na1.net/hubfs/4750167/foresight-live-badge-72.png" height="36" alt="see it on foresight" />
</a>

@RunWith(JUnitQuickcheck.class)
public class StringProperties {
@Property public void concatenationLength(String s1, String s2) {
assertEquals(s1.length() + s2.length(), (s1 + s2).length());
}
}
```
---
![Success Details](https://api-public.service.runforesight.com/api/v1/badge/success?repoId=5c43d0bb-71db-429f-a5b5-ebf7d5622aef)
![Test Result](https://api-public.service.runforesight.com/api/v1/badge/test?repoId=5c43d0bb-71db-429f-a5b5-ebf7d5622aef)
![Utilization](https://api-public.service.runforesight.com/api/v1/badge/utilization?repoId=5c43d0bb-71db-429f-a5b5-ebf7d5622aef)

## Other examples

After browsing the [documentation](#documentation), have a look at some
[examples](examples) in module `junit-quickcheck-examples`. These are built
with junit-quickcheck.
| Report Attribute | Value |
|---|---|
| Language | Java |
| Test Framework | Junit |
| Test Report Format | JUnit |
| Coverage Format | Jacoco / XML |
| Coverage Format 2 | Cobertura / XML |
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ a copy of this software and associated documentation files (the
import java.util.ArrayList;
import java.util.List;

import java.util.Arrays;

/**
* Produces values of type {@link Optional}.
*/
Expand Down Expand Up @@ -85,4 +87,11 @@ public OptionalGenerator() {
.map(componentGenerators().get(0)::magnitude)
.orElse(ZERO);
}
private void sum() {
int a[] = {2, 6, 1, 4};
int b[] = {2, 1, 4, 4};

int result[] = new int[a.length];
Arrays.setAll(result, i -> a[i] + b[i]);
}
}
51 changes: 35 additions & 16 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,35 @@
</pluginManagement>

<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>cobertura-maven-plugin</artifactId>
<version>2.7</version>
<configuration>
<check>
<branchRate>0</branchRate>
<lineRate>0</lineRate>
<haltOnFailure>true</haltOnFailure>
<totalBranchRate>0</totalBranchRate>
<totalLineRate>0</totalLineRate>
<packageLineRate>0</packageLineRate>
<packageBranchRate>0</packageBranchRate>
</check>
<formats>
<format>xml</format>
</formats>
<aggregate>true</aggregate>
</configuration>
<executions>
<execution>
<phase>post-integration-test</phase>
<goals>
<goal>check</goal>
<goal>cobertura</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
Expand Down Expand Up @@ -409,28 +438,17 @@
<reporting>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-project-info-reports-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<groupId>org.codehaus.mojo</groupId>
<artifactId>cobertura-maven-plugin</artifactId>
<version>2.7</version>
<reportSets>
<reportSet>
<id>default</id>
<reports>
<report>javadoc</report>
<report>cobertura</report>
</reports>
</reportSet>
</reportSets>
</plugin>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-pmd-plugin</artifactId>

</plugin>
</plugins>
</reporting>
Expand All @@ -449,6 +467,7 @@
</profile>
</profiles>


<distributionManagement>
<site>
<id>github-pages-site</id>
Expand Down