Skip to content

Commit

Permalink
junit: Add transitive dependency on launcher
Browse files Browse the repository at this point in the history
The transitive dependency on org.junit.platform:junit-platform-launcher
removes the requirement to specify it manually in every project.
  • Loading branch information
bertschneider committed Mar 16, 2023
1 parent 9313d63 commit cec3a81
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 2 deletions.
35 changes: 33 additions & 2 deletions examples/junit-spring-web/build-and-run-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ sed -i "/<artifactId>jazzer-junit<\/artifactId>/ {n;s/<version>.*<\/version>/<ve
./mvnw install:install-file -Dfile=../../bazel-bin/deploy/jazzer-project.jar -DpomFile=../../bazel-bin/deploy/jazzer-pom.xml
./mvnw install:install-file -Dfile=../../bazel-bin/deploy/jazzer-api-project.jar -DpomFile=../../bazel-bin/deploy/jazzer-api-pom.xml


## Regression and unit tests
echo "[SPRINGBOOT-JUNIT]: These unit and regression fuzz tests should pass"
./mvnw test -Dtest="JunitSpringWebApplicationTests#unitTestShouldPass+fuzzTestShouldPass"
Expand All @@ -52,7 +51,6 @@ else
exit 1
fi


## Fuzz tests
echo "[SPRINGBOOT-JUNIT]: This fuzz test should pass"
JAZZER_FUZZ=1 ./mvnw test -Dtest="JunitSpringWebApplicationTests#fuzzTestShouldPass"
Expand All @@ -71,4 +69,37 @@ else
exit 1
fi

## CLI tests
## Assert transitive JUnit dependencies are specified
assertDependency() {
if ./mvnw dependency:tree | grep -q "$1"
then
echo "[SPRINGBOOT-JUNIT]: Found $1 dependency in project"
else
echo "[SPRINGBOOT-JUNIT]: Did not find $1 dependency in project"
exit 1
fi
}
assertDependency "org.junit.jupiter:junit-jupiter-api"
assertDependency "org.junit.jupiter:junit-jupiter-params"
assertDependency "org.junit.platform:junit-platform-launcher"

# Only build project and test jars, no need for a fat-jar or test execution
./mvnw jar:jar
./mvnw jar:test-jar

# Extract dependency locations
out=$(./mvnw dependency:build-classpath -DforceStdout)
deps=$(echo "$out" | sed '/^\[/d')

# Directly execute Jazzer without Maven
echo "[SPRINGBOOT-JUNIT]: Direct Jazzer execution of fuzz test should pass"
java -cp "target/*:${deps}" \
com.code_intelligence.jazzer.Jazzer \
--target_class=com.example.JunitSpringWebApplicationTests \
--target_method=fuzzTestShouldPass \
--instrumentation_includes=com.example.* \
--custom_hook_includes=com.example.*


echo "[SPRINGBOOT-JUNIT]: All tests passed"
6 changes: 6 additions & 0 deletions src/main/java/com/code_intelligence/jazzer/junit/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@ java_library(
visibility = [
"//examples/junit/src/test/java/com/example:__pkg__",
],
runtime_deps = [
# The JUnit launcher that is part of the Jazzer driver needs this on the classpath
# to run an @FuzzTest with JUnit. This will also result in a transitive dependency
# in the generated pom file.
"@maven//:org_junit_platform_junit_platform_launcher",
],
deps = [
":agent_configurator",
":fuzz_test_executor",
Expand Down

0 comments on commit cec3a81

Please sign in to comment.