question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Work around missing JUnit reporting entry support in Gradle

See original GitHub issue

I tried to get a basic test running with gradle but it seems like jazzer is trying to instrument the gradle workers and fails somewhere.

$ gradle build
INFO: Instrumented org.gradle.api.internal.tasks.testing.processors.DefaultStandardOutputRedirector$DiscardAction with custom hooks only (took 1 ms, size +0%)

> Task :app:test

DummyFuzzTest > dummyFuzz(FuzzedDataProvider) > dummy.DummyFuzzTest.initializationError FAILED
    java.lang.IllegalStateException at AgentInstaller.java:55
        Caused by: java.lang.reflect.InvocationTargetException at NativeMethodAccessorImpl.java:-2
            Caused by: java.lang.VerifyError at InstrumentationImpl.java:-2

build.gradle

plugins {
    // Apply the application plugin to add support for building a CLI application in Java.
    id 'application'
}

repositories {
    // Use Maven Central for resolving dependencies.
    mavenCentral()
}

dependencies {
    testImplementation 'org.junit.jupiter:junit-jupiter:5.8.2'
    
    testImplementation 'com.code-intelligence:jazzer-api:0.13.0'
    testImplementation 'com.code-intelligence:jazzer-junit:0.13.0'
}

application {
    // Define the main class for the application.
    mainClass = 'dummy.App'
}

tasks.named('test') {
    // Use JUnit Platform for unit tests.
    useJUnitPlatform()
}

App.java

package dummy;

public class App {
    public int add(int a, int b) {
        return a+b;
    }

    public static void main(String[] args) {
        System.out.println(new App().add(1, 2));
    }
}

AppTest.java

package dummy;

import com.code_intelligence.jazzer.api.FuzzedDataProvider;
import com.code_intelligence.jazzer.junit.FuzzTest;

class DummyFuzzTest {
    @FuzzTest
    void dummyFuzz(FuzzedDataProvider data) {
        new App().add(data.consumeInt(), data.consumeInt());
    }
}

Any idea how to get this running?

Issue Analytics

  • State:open
  • Created a year ago
  • Comments:12 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
fmeumcommented, Oct 27, 2022

By default, the tests are only run on a fixed set of inputs stored in the src/test/resources/dummy/DummyFuzzTestInputs directory (for your example), plus the empty input. This directory is populated with findings encountered during actual fuzzing runs, which you can start by running the tests with the environment variable JAZZER_FUZZ set to 1. I tried that on your example and got a finding emitted into the directory that I could then reproduce when running the test without JAZZER_FUZZ set.

We actually use JUnit’s reporting entry feature to tell you about all this right in your test logs, which works well with Maven but for some reason doesn’t show up with Gradle.

1reaction
CodeLowSkycommented, Oct 27, 2022

Attached is the stack trace, thanks for looking into this. In the meanwhile I try the instrument option.

trace.txt

Read more comments on GitHub >

github_iconTop Results From Across the Web

Support JUnit platform reporting entries #4605 - GitHub
The junit platform TestExecutionListener has a method reportingEntryPublished which is called when tests report additional data. Those entries ...
Read more >
Testing in Java & JVM projects - Gradle User Manual
All JVM testing revolves around a single task type: Test. This runs a collection of test cases using any supported test library —...
Read more >
JUnit tests missing test resources in classpath - Issue Tracker
So the temporary workaround is to follow Comment #13 . The good news is that IntelliJ 14 provides native support for running Gradle...
Read more >
How to use JUnit 5 with Gradle? - Stack Overflow
First, make sure you are using the latest Gradle version, check latest releases at their GitHub releases. If that is for example 4.6,...
Read more >
JUnit 5 Tutorial: Running Unit Tests With Gradle
This blog post describes how we can create a Gradle project that can compile and run unit tests which use JUnit 5.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found