Skip to content
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
15 changes: 11 additions & 4 deletions .github/workflows/foresight.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,22 @@ 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:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3

- name: Collect Workflow Telemetry
if: always()
uses: runforesight/foresight-workflow-kit-action@v1
Expand All @@ -29,13 +36,13 @@ jobs:
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: jacoco/xml
coverage_path: "**/target/site/jacoco/*.xml"
68 changes: 16 additions & 52 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,55 +1,19 @@
[![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.

## Documentation
## runforesight.com Demo Projects - Junit Quickcheck

[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.*;

@RunWith(JUnitQuickcheck.class)
public class StringProperties {
@Property public void concatenationLength(String s1, String s2) {
assertEquals(s1.length() + s2.length(), (s1 + s2).length());
}
}
```

## Other examples
<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>

After browsing the [documentation](#documentation), have a look at some
[examples](examples) in module `junit-quickcheck-examples`. These are built
with junit-quickcheck.
---
![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)

| 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 @@ -47,6 +47,25 @@ private static AnnotatedType makePlainType(Class<?> type) {
return new FakeAnnotatedType(type);
}

private static void testUpdate(int v) {
if(v > 0) {
System.out.println("v > 0");
}
else if(v < 0) {
System.out.println("v < 0");
}
else {
System.out.println("v == 0");
}
}

private static int testDemo(int x, int y) {
int sum = x+y;
int div = y != 0 ? x/y : 1;

return sum * sum + div * div;
}

private static final class FakeAnnotatedArrayType
implements AnnotatedArrayType {

Expand Down