├── junit-migration-gradle ├── settings.gradle ├── gradle │ └── wrapper │ │ ├── gradle-wrapper.jar │ │ └── gradle-wrapper.properties ├── .gitignore ├── src │ ├── main │ │ └── java │ │ │ └── com │ │ │ └── example │ │ │ └── project │ │ │ └── Calculator.java │ └── test │ │ └── java │ │ └── com │ │ └── example │ │ └── project │ │ ├── OtherTests.java │ │ ├── JUnit4Test.java │ │ ├── SecondTest.java │ │ └── FirstTest.java ├── build.gradle ├── gradlew.bat └── README.md ├── junit-jupiter-extensions ├── settings.gradle ├── gradle │ └── wrapper │ │ ├── gradle-wrapper.jar │ │ └── gradle-wrapper.properties ├── .gitignore ├── build.gradle ├── README.md ├── src │ ├── test │ │ └── java │ │ │ └── com │ │ │ └── example │ │ │ ├── random │ │ │ └── RandomParametersExtensionTests.java │ │ │ └── cartesian │ │ │ └── CartesianProductTests.java │ └── main │ │ └── java │ │ └── com │ │ └── example │ │ ├── cartesian │ │ ├── CartesianProductContext.java │ │ ├── CartesianProductResolver.java │ │ ├── CartesianProductTest.java │ │ └── CartesianProductProvider.java │ │ └── random │ │ └── RandomParametersExtension.java └── gradlew.bat ├── junit-multiple-engines ├── settings.gradle.kts ├── buildSrc │ ├── settings.gradle.kts │ ├── build.gradle.kts │ └── src │ │ └── main │ │ └── kotlin │ │ └── ReportsDirArgumentProvider.kt ├── gradle │ └── wrapper │ │ ├── gradle-wrapper.jar │ │ └── gradle-wrapper.properties ├── .gitignore ├── src │ └── test │ │ ├── java │ │ ├── mainrunner │ │ │ └── MainrunnerTest.java │ │ ├── junit │ │ │ ├── vintage │ │ │ │ ├── JUnit3Test.java │ │ │ │ └── JUnit4Test.java │ │ │ └── jupiter │ │ │ │ └── JupiterTests.java │ │ ├── testng │ │ │ └── TestNGTests.java │ │ ├── jqwik │ │ │ └── JQwikTest.java │ │ └── suite │ │ │ └── SuiteTests.java │ │ ├── kotlin │ │ ├── kotest │ │ │ └── KotestSpec.kt │ │ └── spek │ │ │ └── SpekTest.kt │ │ └── groovy │ │ └── spock │ │ └── SpockSpec.groovy ├── README.md ├── gradlew.bat └── build.gradle.kts ├── junit-jupiter-starter-gradle ├── settings.gradle ├── gradle │ └── wrapper │ │ ├── gradle-wrapper.jar │ │ └── gradle-wrapper.properties ├── .gitignore ├── README.md ├── src │ ├── main │ │ └── java │ │ │ └── com │ │ │ └── example │ │ │ └── project │ │ │ └── Calculator.java │ └── test │ │ └── java │ │ └── com │ │ └── example │ │ └── project │ │ └── CalculatorTests.java ├── build.gradle └── gradlew.bat ├── junit-jupiter-starter-bazel ├── .bazelversion ├── .bazelrc ├── README.md ├── src │ ├── main │ │ └── java │ │ │ └── com │ │ │ └── example │ │ │ └── project │ │ │ └── Calculator.java │ └── test │ │ └── java │ │ └── com │ │ └── example │ │ └── project │ │ └── CalculatorTests.java ├── BUILD ├── MODULE.bazel └── .gitignore ├── junit-jupiter-starter-gradle-groovy ├── settings.gradle ├── gradle │ └── wrapper │ │ ├── gradle-wrapper.jar │ │ └── gradle-wrapper.properties ├── .gitignore ├── README.md ├── src │ ├── main │ │ └── groovy │ │ │ └── com │ │ │ └── example │ │ │ └── project │ │ │ └── Calculator.groovy │ └── test │ │ └── groovy │ │ └── com │ │ └── example │ │ └── project │ │ └── CalculatorTests.groovy ├── build.gradle └── gradlew.bat ├── junit-jupiter-starter-gradle-kotlin ├── settings.gradle.kts ├── gradle │ └── wrapper │ │ ├── gradle-wrapper.jar │ │ └── gradle-wrapper.properties ├── README.md ├── src │ ├── main │ │ └── kotlin │ │ │ └── com │ │ │ └── example │ │ │ └── project │ │ │ └── Calculator.kt │ └── test │ │ └── kotlin │ │ └── com │ │ └── example │ │ └── project │ │ └── CalculatorTests.kt ├── build.gradle.kts └── gradlew.bat ├── junit-source-launcher ├── .gitignore ├── src │ ├── junit-platform.properties │ └── HelloTests.java ├── README.md └── lib │ └── DownloadRequiredModules.java ├── junit-jupiter-starter-sbt ├── project │ ├── build.properties │ └── plugins.sbt ├── .gitignore ├── README.md ├── src │ ├── main │ │ └── scala │ │ │ └── com │ │ │ └── example │ │ │ └── project │ │ │ └── Calculator.scala │ └── test │ │ └── scala │ │ └── com │ │ └── example │ │ └── project │ │ └── CalculatorTests.scala └── build.sbt ├── junit-modular-world ├── .gitignore ├── doc │ ├── screenshot-bin.png │ ├── screenshot-lib.png │ └── screenshot-src.png ├── src │ ├── main │ │ ├── com.example.tool │ │ │ ├── module-info.java │ │ │ └── com │ │ │ │ └── example │ │ │ │ └── tool │ │ │ │ ├── internal │ │ │ │ └── MathHelper.java │ │ │ │ └── Calculator.java │ │ ├── com.example.application │ │ │ ├── module-info.java │ │ │ └── com │ │ │ │ └── example │ │ │ │ └── application │ │ │ │ └── Main.java │ │ └── ice.cream │ │ │ ├── module-info.java │ │ │ └── ice │ │ │ └── cream │ │ │ ├── Flavor.java │ │ │ ├── Scoop.java │ │ │ └── Machine.java │ ├── build │ │ ├── Compile.java │ │ └── Build.java │ └── test │ │ ├── com.example.application │ │ ├── module-info.java │ │ └── com │ │ │ └── example │ │ │ └── application │ │ │ └── MainTests.java │ │ ├── com.example.tool │ │ ├── module-info.java │ │ └── com │ │ │ └── example │ │ │ └── tool │ │ │ ├── CalculatorTests.java │ │ │ └── internal │ │ │ └── MathHelperTests.java │ │ ├── extra.modular │ │ ├── extra │ │ │ └── modular │ │ │ │ ├── GoodOldTest.java │ │ │ │ ├── JQwikTests.java │ │ │ │ └── ExtraModularTests.java │ │ └── module-info.java │ │ └── ice.cream │ │ ├── ice │ │ └── cream │ │ │ ├── FlavorTests.java │ │ │ └── MachineTests.java │ │ └── module-info.java └── README.md ├── junit-migration-maven ├── .gitignore ├── .mvn │ └── wrapper │ │ └── maven-wrapper.properties ├── src │ ├── main │ │ └── java │ │ │ └── com │ │ │ └── example │ │ │ └── project │ │ │ └── Calculator.java │ └── test │ │ └── java │ │ └── com │ │ └── example │ │ └── project │ │ ├── OtherTests.java │ │ ├── JUnit4Test.java │ │ ├── SecondTest.java │ │ └── FirstTest.java ├── pom.xml ├── README.md └── mvnw.cmd ├── .github ├── PULL_REQUEST_TEMPLATE.md ├── renovate.json5 └── workflows │ ├── gradle-wrapper-validation.yml │ ├── nohttp.yml │ ├── build-all-examples.yml │ └── codeql.yml ├── .gitattributes ├── junit-jupiter-starter-maven-kotlin ├── .gitignore ├── .mvn │ └── wrapper │ │ └── maven-wrapper.properties ├── README.md ├── src │ ├── main │ │ └── kotlin │ │ │ └── com │ │ │ └── example │ │ │ └── project │ │ │ └── Calculator.kt │ └── test │ │ └── kotlin │ │ └── com │ │ └── example │ │ └── project │ │ └── CalculatorTests.kt ├── pom.xml └── mvnw.cmd ├── junit-jupiter-starter-maven ├── .mvn │ └── wrapper │ │ └── maven-wrapper.properties ├── .gitignore ├── README.md ├── src │ ├── main │ │ └── java │ │ │ └── com │ │ │ └── example │ │ │ └── project │ │ │ └── Calculator.java │ └── test │ │ └── java │ │ └── com │ │ └── example │ │ └── project │ │ └── CalculatorTests.java ├── pom.xml └── mvnw.cmd ├── junit-jupiter-starter-ant ├── .gitignore ├── README.md ├── src │ ├── main │ │ └── java │ │ │ └── com │ │ │ └── example │ │ │ └── project │ │ │ └── Calculator.java │ └── test │ │ └── java │ │ └── com │ │ └── example │ │ └── project │ │ └── CalculatorTests.java ├── build.sh └── build.xml ├── src ├── eclipse-public-license-2.0.java ├── central-staging-maven-settings.xml ├── Updater.java ├── StagingRepoInjector.java └── Builder.java ├── .gitignore └── README.md /junit-migration-gradle/settings.gradle: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /junit-jupiter-extensions/settings.gradle: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /junit-multiple-engines/settings.gradle.kts: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /junit-jupiter-starter-gradle/settings.gradle: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /junit-jupiter-starter-bazel/.bazelversion: -------------------------------------------------------------------------------- 1 | 8.5.0 2 | -------------------------------------------------------------------------------- /junit-jupiter-starter-gradle-groovy/settings.gradle: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /junit-multiple-engines/buildSrc/settings.gradle.kts: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /junit-jupiter-starter-gradle-kotlin/settings.gradle.kts: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /junit-source-launcher/.gitignore: -------------------------------------------------------------------------------- 1 | out/ 2 | 3 | *.jar 4 | -------------------------------------------------------------------------------- /junit-jupiter-starter-sbt/project/build.properties: -------------------------------------------------------------------------------- 1 | sbt.version=1.11.7 2 | -------------------------------------------------------------------------------- /junit-modular-world/.gitignore: -------------------------------------------------------------------------------- 1 | bin/ 2 | lib/ 3 | !src/build/ 4 | .jqwik-database 5 | -------------------------------------------------------------------------------- /junit-migration-maven/.gitignore: -------------------------------------------------------------------------------- 1 | /.classpath 2 | /.project 3 | /.settings 4 | /target 5 | /bin 6 | -------------------------------------------------------------------------------- /junit-jupiter-starter-sbt/project/plugins.sbt: -------------------------------------------------------------------------------- 1 | addSbtPlugin("net.aichler" % "sbt-jupiter-interface" % "0.11.1") 2 | -------------------------------------------------------------------------------- /.github/PULL_REQUEST_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | ## Overview 2 | 3 | - 4 | 5 | --- 6 | I hereby agree to the terms of the JUnit Contributor License Agreement. 7 | -------------------------------------------------------------------------------- /junit-modular-world/doc/screenshot-bin.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/junit-team/junit-examples/HEAD/junit-modular-world/doc/screenshot-bin.png -------------------------------------------------------------------------------- /junit-modular-world/doc/screenshot-lib.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/junit-team/junit-examples/HEAD/junit-modular-world/doc/screenshot-lib.png -------------------------------------------------------------------------------- /junit-modular-world/doc/screenshot-src.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/junit-team/junit-examples/HEAD/junit-modular-world/doc/screenshot-src.png -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | # Set default behavior to automatically normalize line endings. 2 | * text=auto 3 | 4 | # Force batch scripts to always use crlf 5 | *.bat text eol=crlf 6 | -------------------------------------------------------------------------------- /.github/renovate.json5: -------------------------------------------------------------------------------- 1 | { 2 | $schema: 'https://docs.renovatebot.com/renovate-schema.json', 3 | extends: [ 4 | 'github>junit-team/renovate-config', 5 | ], 6 | } 7 | -------------------------------------------------------------------------------- /junit-migration-gradle/gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/junit-team/junit-examples/HEAD/junit-migration-gradle/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /junit-multiple-engines/gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/junit-team/junit-examples/HEAD/junit-multiple-engines/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /junit-jupiter-extensions/gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/junit-team/junit-examples/HEAD/junit-jupiter-extensions/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /junit-jupiter-starter-gradle/gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/junit-team/junit-examples/HEAD/junit-jupiter-starter-gradle/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /junit-jupiter-starter-gradle-groovy/gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/junit-team/junit-examples/HEAD/junit-jupiter-starter-gradle-groovy/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /junit-jupiter-starter-gradle-kotlin/gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/junit-team/junit-examples/HEAD/junit-jupiter-starter-gradle-kotlin/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /junit-jupiter-starter-maven-kotlin/.gitignore: -------------------------------------------------------------------------------- 1 | target/ 2 | /.classpath 3 | /.settings/ 4 | /.project 5 | /bin/ 6 | .idea 7 | *.iml 8 | *.ipr 9 | *.iws 10 | /out/ 11 | *.log* 12 | .DS_Store 13 | -------------------------------------------------------------------------------- /junit-migration-maven/.mvn/wrapper/maven-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionType=only-script 2 | distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.9.11/apache-maven-3.9.11-bin.zip 3 | -------------------------------------------------------------------------------- /junit-jupiter-starter-maven/.mvn/wrapper/maven-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionType=only-script 2 | distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.9.11/apache-maven-3.9.11-bin.zip 3 | -------------------------------------------------------------------------------- /junit-jupiter-starter-maven-kotlin/.mvn/wrapper/maven-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionType=only-script 2 | distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.9.11/apache-maven-3.9.11-bin.zip 3 | -------------------------------------------------------------------------------- /junit-jupiter-starter-bazel/.bazelrc: -------------------------------------------------------------------------------- 1 | build --java_language_version=21 2 | build --java_runtime_version=remotejdk_21 3 | 4 | build --tool_java_language_version=21 5 | build --tool_java_runtime_version=remotejdk_21 6 | 7 | test --test_output=all 8 | -------------------------------------------------------------------------------- /junit-jupiter-starter-bazel/README.md: -------------------------------------------------------------------------------- 1 | # junit-jupiter-starter-bazel 2 | 3 | The `junit-jupiter-starter-bazel` project demonstrates how to execute JUnit Jupiter 4 | tests using Bazel. 5 | 6 | Run `./bazelisk.py test //...` to execute all tests. 7 | -------------------------------------------------------------------------------- /junit-jupiter-starter-maven/.gitignore: -------------------------------------------------------------------------------- 1 | # Maven 2 | target/ 3 | 4 | # Ignore Gradle GUI config 5 | gradle-app.setting 6 | 7 | # Eclipse 8 | /.classpath 9 | /.settings/ 10 | /.project 11 | /bin/ 12 | 13 | # IntelliJ 14 | .idea 15 | *.iml 16 | *.ipr 17 | *.iws 18 | 19 | # Misc 20 | *.log 21 | -------------------------------------------------------------------------------- /junit-source-launcher/src/junit-platform.properties: -------------------------------------------------------------------------------- 1 | ## 2 | ## Enable JUnit Platform Reporting 3 | ## -> https://docs.junit.org/current/user-guide/#junit-platform-reporting 4 | ## 5 | # junit.platform.reporting.output.dir=out/junit-{uniqueNumber} 6 | # junit.platform.reporting.open.xml.enabled=true 7 | -------------------------------------------------------------------------------- /junit-jupiter-extensions/.gitignore: -------------------------------------------------------------------------------- 1 | # Gradle 2 | .gradle 3 | build/ 4 | 5 | # Ignore Gradle GUI config 6 | gradle-app.setting 7 | 8 | # Eclipse 9 | /.classpath 10 | /.settings/ 11 | /.project 12 | /bin/ 13 | 14 | # IntelliJ 15 | .idea 16 | *.iml 17 | *.ipr 18 | *.iws 19 | 20 | # Misc 21 | *.log 22 | -------------------------------------------------------------------------------- /junit-jupiter-starter-ant/.gitignore: -------------------------------------------------------------------------------- 1 | # Ant 2 | apache-ant-* 3 | build 4 | 5 | # Ignore Gradle GUI config 6 | gradle-app.setting 7 | 8 | # Eclipse 9 | bin 10 | .classpath 11 | .settings 12 | .project 13 | 14 | # IntelliJ 15 | .idea 16 | *.iml 17 | *.ipr 18 | *.iws 19 | 20 | # Misc 21 | *.log 22 | -------------------------------------------------------------------------------- /junit-jupiter-starter-sbt/.gitignore: -------------------------------------------------------------------------------- 1 | # sbt specific 2 | dist/* 3 | target/ 4 | lib_managed/ 5 | src_managed/ 6 | project/boot/ 7 | project/plugins/project/ 8 | project/local-plugins.sbt 9 | .history 10 | .ensime 11 | .ensime_cache/ 12 | .sbt-scripted/ 13 | local.sbt 14 | 15 | # Bloop 16 | .bsp 17 | -------------------------------------------------------------------------------- /junit-migration-gradle/.gitignore: -------------------------------------------------------------------------------- 1 | # Gradle 2 | .gradle 3 | build/ 4 | 5 | # Ignore Gradle GUI config 6 | gradle-app.setting 7 | 8 | # Eclipse 9 | /.classpath 10 | /.settings/ 11 | /.project 12 | /bin/ 13 | 14 | # IntelliJ 15 | .idea 16 | *.iml 17 | *.ipr 18 | *.iws 19 | 20 | # Misc 21 | *.log 22 | -------------------------------------------------------------------------------- /junit-jupiter-starter-gradle/.gitignore: -------------------------------------------------------------------------------- 1 | # Gradle 2 | .gradle 3 | build/ 4 | 5 | # Ignore Gradle GUI config 6 | gradle-app.setting 7 | 8 | # Eclipse 9 | /.classpath 10 | /.settings/ 11 | /.project 12 | /bin/ 13 | 14 | # IntelliJ 15 | .idea 16 | *.iml 17 | *.ipr 18 | *.iws 19 | 20 | # Misc 21 | *.log 22 | -------------------------------------------------------------------------------- /junit-jupiter-starter-gradle-groovy/.gitignore: -------------------------------------------------------------------------------- 1 | # Gradle 2 | .gradle 3 | build/ 4 | 5 | # Ignore Gradle GUI config 6 | gradle-app.setting 7 | 8 | # Eclipse 9 | /.classpath 10 | /.settings/ 11 | /.project 12 | /bin/ 13 | 14 | # IntelliJ 15 | .idea 16 | *.iml 17 | *.ipr 18 | *.iws 19 | 20 | # Misc 21 | *.log 22 | -------------------------------------------------------------------------------- /junit-multiple-engines/.gitignore: -------------------------------------------------------------------------------- 1 | # Gradle 2 | .gradle 3 | build/ 4 | 5 | # Ignore Gradle GUI config 6 | gradle-app.setting 7 | 8 | # Eclipse 9 | /.classpath 10 | /.settings/ 11 | /.project 12 | /bin/ 13 | 14 | # IntelliJ 15 | .idea 16 | *.iml 17 | *.ipr 18 | *.iws 19 | 20 | # Misc 21 | *.log 22 | .jqwik-database 23 | .kotlintest 24 | -------------------------------------------------------------------------------- /junit-jupiter-starter-maven/README.md: -------------------------------------------------------------------------------- 1 | # junit-jupiter-starter-maven 2 | 3 | The `junit-jupiter-starter-maven` project demonstrates how to execute JUnit Jupiter 4 | tests using Maven. 5 | 6 | Please note that this project uses the [Maven Wrapper](https://github.com/apache/maven-wrapper). 7 | Thus, to ensure that the correct version of Maven is used, invoke `mvnw` instead of `mvn`. 8 | -------------------------------------------------------------------------------- /junit-multiple-engines/buildSrc/build.gradle.kts: -------------------------------------------------------------------------------- 1 | import org.jetbrains.kotlin.gradle.dsl.JvmTarget.JVM_17 2 | 3 | plugins { 4 | `kotlin-dsl` 5 | } 6 | 7 | repositories { 8 | mavenCentral() 9 | } 10 | 11 | tasks { 12 | compileKotlin { 13 | compilerOptions.jvmTarget = JVM_17 14 | } 15 | compileJava { 16 | options.release = 17 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/eclipse-public-license-2.0.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2025 the original author or authors. 3 | * 4 | * All rights reserved. This program and the accompanying materials are 5 | * made available under the terms of the Eclipse Public License v2.0 which 6 | * accompanies this distribution and is available at 7 | * 8 | * https://www.eclipse.org/legal/epl-v20.html 9 | */ 10 | -------------------------------------------------------------------------------- /junit-jupiter-starter-gradle/README.md: -------------------------------------------------------------------------------- 1 | # junit-jupiter-starter-gradle 2 | 3 | The `junit-jupiter-starter-gradle` project demonstrates how to run tests based on JUnit 4 | Jupiter using [Gradle's native JUnit Platform support], Gradle's Groovy DSL 5 | and code and tests written in Java. 6 | 7 | [Gradle's native JUnit Platform support]: https://docs.gradle.org/current/userguide/java_testing.html#using_junit5 8 | -------------------------------------------------------------------------------- /junit-jupiter-starter-sbt/README.md: -------------------------------------------------------------------------------- 1 | # junit-jupiter-starter-sbt 2 | 3 | The `junit-jupiter-starter-sbt` project demonstrates how to run tests based on JUnit 4 | Jupiter using [sbt] and its [sbt-jupiter-interface] plugin and code and tests written in Scala. 5 | 6 | [sbt]: https://docs.gradle.org/current/userguide/java_testing.html#using_junit5 7 | [sbt-jupiter-interface]: https://github.com/sbt/sbt-jupiter-interface 8 | -------------------------------------------------------------------------------- /junit-jupiter-extensions/gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionBase=GRADLE_USER_HOME 2 | distributionPath=wrapper/dists 3 | distributionSha256Sum=72f44c9f8ebcb1af43838f45ee5c4aa9c5444898b3468ab3f4af7b6076c5bc3f 4 | distributionUrl=https\://services.gradle.org/distributions/gradle-9.2.1-bin.zip 5 | networkTimeout=10000 6 | validateDistributionUrl=true 7 | zipStoreBase=GRADLE_USER_HOME 8 | zipStorePath=wrapper/dists 9 | -------------------------------------------------------------------------------- /junit-migration-gradle/gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionBase=GRADLE_USER_HOME 2 | distributionPath=wrapper/dists 3 | distributionSha256Sum=72f44c9f8ebcb1af43838f45ee5c4aa9c5444898b3468ab3f4af7b6076c5bc3f 4 | distributionUrl=https\://services.gradle.org/distributions/gradle-9.2.1-bin.zip 5 | networkTimeout=10000 6 | validateDistributionUrl=true 7 | zipStoreBase=GRADLE_USER_HOME 8 | zipStorePath=wrapper/dists 9 | -------------------------------------------------------------------------------- /junit-multiple-engines/gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionBase=GRADLE_USER_HOME 2 | distributionPath=wrapper/dists 3 | distributionSha256Sum=72f44c9f8ebcb1af43838f45ee5c4aa9c5444898b3468ab3f4af7b6076c5bc3f 4 | distributionUrl=https\://services.gradle.org/distributions/gradle-9.2.1-bin.zip 5 | networkTimeout=10000 6 | validateDistributionUrl=true 7 | zipStoreBase=GRADLE_USER_HOME 8 | zipStorePath=wrapper/dists 9 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Gradle 2 | .gradle 3 | build/ 4 | 5 | # Maven 6 | maven-wrapper.jar 7 | 8 | # Ignore Gradle GUI config 9 | gradle-app.setting 10 | 11 | # Eclipse 12 | /.classpath 13 | /.settings/ 14 | /.project 15 | bin/ 16 | 17 | # IntelliJ 18 | .idea 19 | out 20 | *.iml 21 | *.ipr 22 | *.iws 23 | .ijwb/ 24 | 25 | # Misc 26 | *.log 27 | *.class 28 | .jqwik-database 29 | install-jdk.sh 30 | .sdkmanrc 31 | .tool-versions 32 | -------------------------------------------------------------------------------- /junit-jupiter-starter-gradle/gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionBase=GRADLE_USER_HOME 2 | distributionPath=wrapper/dists 3 | distributionSha256Sum=72f44c9f8ebcb1af43838f45ee5c4aa9c5444898b3468ab3f4af7b6076c5bc3f 4 | distributionUrl=https\://services.gradle.org/distributions/gradle-9.2.1-bin.zip 5 | networkTimeout=10000 6 | validateDistributionUrl=true 7 | zipStoreBase=GRADLE_USER_HOME 8 | zipStorePath=wrapper/dists 9 | -------------------------------------------------------------------------------- /junit-jupiter-starter-gradle-groovy/gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionBase=GRADLE_USER_HOME 2 | distributionPath=wrapper/dists 3 | distributionSha256Sum=72f44c9f8ebcb1af43838f45ee5c4aa9c5444898b3468ab3f4af7b6076c5bc3f 4 | distributionUrl=https\://services.gradle.org/distributions/gradle-9.2.1-bin.zip 5 | networkTimeout=10000 6 | validateDistributionUrl=true 7 | zipStoreBase=GRADLE_USER_HOME 8 | zipStorePath=wrapper/dists 9 | -------------------------------------------------------------------------------- /junit-jupiter-starter-gradle-kotlin/gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionBase=GRADLE_USER_HOME 2 | distributionPath=wrapper/dists 3 | distributionSha256Sum=72f44c9f8ebcb1af43838f45ee5c4aa9c5444898b3468ab3f4af7b6076c5bc3f 4 | distributionUrl=https\://services.gradle.org/distributions/gradle-9.2.1-bin.zip 5 | networkTimeout=10000 6 | validateDistributionUrl=true 7 | zipStoreBase=GRADLE_USER_HOME 8 | zipStorePath=wrapper/dists 9 | -------------------------------------------------------------------------------- /junit-modular-world/src/main/com.example.tool/module-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2025 the original author or authors. 3 | * 4 | * All rights reserved. This program and the accompanying materials are 5 | * made available under the terms of the Eclipse Public License v2.0 which 6 | * accompanies this distribution and is available at 7 | * 8 | * https://www.eclipse.org/legal/epl-v20.html 9 | */ 10 | 11 | module com.example.tool { 12 | exports com.example.tool; 13 | } 14 | -------------------------------------------------------------------------------- /junit-jupiter-starter-gradle-groovy/README.md: -------------------------------------------------------------------------------- 1 | # junit-jupiter-starter-gradle-groovy 2 | 3 | The `junit-jupiter-starter-gradle-groovy` project demonstrates how to run tests based on JUnit 4 | Jupiter using [Gradle's native JUnit Platform support], Gradle's Groovy DSL 5 | and code and tests written in Groovy. 6 | 7 | [Gradle's native JUnit Platform support]: https://docs.gradle.org/current/userguide/java_testing.html#using_junit5 8 | 9 | Run `./gradlew test` to execute all tests. 10 | -------------------------------------------------------------------------------- /junit-jupiter-starter-gradle-kotlin/README.md: -------------------------------------------------------------------------------- 1 | # junit-jupiter-starter-gradle-kotlin 2 | 3 | The `junit-jupiter-starter-gradle-kotlin` project demonstrates how to run tests based on 4 | JUnit Jupiter using [Gradle's native JUnit Platform support], Gradle's Kotlin DSL 5 | and code and tests written in Kotlin. 6 | 7 | [Gradle's native JUnit Platform support]: https://docs.gradle.org/current/userguide/java_testing.html#using_junit5 8 | 9 | Run `./gradlew test` to execute all tests. 10 | -------------------------------------------------------------------------------- /junit-jupiter-starter-ant/README.md: -------------------------------------------------------------------------------- 1 | # junit-jupiter-starter-ant 2 | 3 | The `junit-jupiter-starter-ant` project demonstrates how to execute JUnit Jupiter 4 | tests using [Apache Ant](https://ant.apache.org/) 1.10.15 or higher. 5 | 6 | This example project does not aim to demonstrate how to use the JUnit Jupiter APIs. 7 | 8 | For detailed information on the JUnit Jupiter programming and extension models, 9 | please consult the [User Guide](https://docs.junit.org/current/user-guide/). 10 | -------------------------------------------------------------------------------- /junit-modular-world/src/main/com.example.application/module-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2025 the original author or authors. 3 | * 4 | * All rights reserved. This program and the accompanying materials are 5 | * made available under the terms of the Eclipse Public License v2.0 which 6 | * accompanies this distribution and is available at 7 | * 8 | * https://www.eclipse.org/legal/epl-v20.html 9 | */ 10 | 11 | module com.example.application { 12 | requires com.example.tool; 13 | } 14 | -------------------------------------------------------------------------------- /junit-jupiter-starter-maven-kotlin/README.md: -------------------------------------------------------------------------------- 1 | # junit-jupiter-starter-maven-kotlin 2 | 3 | The `junit-jupiter-starter-maven-kotlin` example demonstrates the bare minimum configuration for 4 | getting started with JUnit Jupiter project using Maven build system and Kotlin programming language. 5 | 6 | Please note that this project is uses the [Maven Wrapper](https://github.com/takari/maven-wrapper) 7 | 3.6.1 version. This helps you ensure that already tested versions are not going to be failed if 8 | locally installed different maven version. 9 | -------------------------------------------------------------------------------- /junit-jupiter-starter-maven-kotlin/src/main/kotlin/com/example/project/Calculator.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2025 the original author or authors. 3 | * 4 | * All rights reserved. This program and the accompanying materials are 5 | * made available under the terms of the Eclipse Public License v2.0 which 6 | * accompanies this distribution and is available at 7 | * 8 | * https://www.eclipse.org/legal/epl-v20.html 9 | */ 10 | 11 | package com.example.project 12 | 13 | class Calculator { 14 | fun add(a: Int, b: Int) = a + b 15 | } 16 | -------------------------------------------------------------------------------- /junit-jupiter-starter-sbt/src/main/scala/com/example/project/Calculator.scala: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2025 the original author or authors. 3 | * 4 | * All rights reserved. This program and the accompanying materials are 5 | * made available under the terms of the Eclipse Public License v2.0 which 6 | * accompanies this distribution and is available at 7 | * 8 | * https://www.eclipse.org/legal/epl-v20.html 9 | */ 10 | 11 | package com.example.project 12 | 13 | object Calculator { 14 | def add(a: Int, b: Int): Int = a + b 15 | } 16 | -------------------------------------------------------------------------------- /junit-migration-maven/src/main/java/com/example/project/Calculator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2025 the original author or authors. 3 | * 4 | * All rights reserved. This program and the accompanying materials are 5 | * made available under the terms of the Eclipse Public License v2.0 which 6 | * accompanies this distribution and is available at 7 | * 8 | * https://www.eclipse.org/legal/epl-v20.html 9 | */ 10 | 11 | package com.example.project; 12 | 13 | public class Calculator { 14 | 15 | public int add(int a, int b) { 16 | return a + b; 17 | } 18 | 19 | } 20 | -------------------------------------------------------------------------------- /junit-multiple-engines/src/test/java/mainrunner/MainrunnerTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2025 the original author or authors. 3 | * 4 | * All rights reserved. This program and the accompanying materials are 5 | * made available under the terms of the Eclipse Public License v2.0 which 6 | * accompanies this distribution and is available at 7 | * 8 | * https://www.eclipse.org/legal/epl-v20.html 9 | */ 10 | 11 | package mainrunner; 12 | 13 | public class MainrunnerTest { 14 | public static void main(String... args) { 15 | // empty on purpose 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /junit-jupiter-starter-ant/src/main/java/com/example/project/Calculator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2025 the original author or authors. 3 | * 4 | * All rights reserved. This program and the accompanying materials are 5 | * made available under the terms of the Eclipse Public License v2.0 which 6 | * accompanies this distribution and is available at 7 | * 8 | * https://www.eclipse.org/legal/epl-v20.html 9 | */ 10 | 11 | package com.example.project; 12 | 13 | public class Calculator { 14 | 15 | public int add(int a, int b) { 16 | return a + b; 17 | } 18 | 19 | } 20 | -------------------------------------------------------------------------------- /junit-jupiter-starter-gradle-groovy/src/main/groovy/com/example/project/Calculator.groovy: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2025 the original author or authors. 3 | * 4 | * All rights reserved. This program and the accompanying materials are 5 | * made available under the terms of the Eclipse Public License v2.0 which 6 | * accompanies this distribution and is available at 7 | * 8 | * https://www.eclipse.org/legal/epl-v20.html 9 | */ 10 | 11 | package com.example.project 12 | 13 | class Calculator { 14 | 15 | int add(int a, int b) { 16 | return a + b; 17 | } 18 | 19 | } 20 | -------------------------------------------------------------------------------- /junit-migration-gradle/src/main/java/com/example/project/Calculator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2025 the original author or authors. 3 | * 4 | * All rights reserved. This program and the accompanying materials are 5 | * made available under the terms of the Eclipse Public License v2.0 which 6 | * accompanies this distribution and is available at 7 | * 8 | * https://www.eclipse.org/legal/epl-v20.html 9 | */ 10 | 11 | package com.example.project; 12 | 13 | public class Calculator { 14 | 15 | public int add(int a, int b) { 16 | return a + b; 17 | } 18 | 19 | } 20 | -------------------------------------------------------------------------------- /junit-jupiter-starter-bazel/src/main/java/com/example/project/Calculator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2025 the original author or authors. 3 | * 4 | * All rights reserved. This program and the accompanying materials are 5 | * made available under the terms of the Eclipse Public License v2.0 which 6 | * accompanies this distribution and is available at 7 | * 8 | * https://www.eclipse.org/legal/epl-v20.html 9 | */ 10 | 11 | package com.example.project; 12 | 13 | public class Calculator { 14 | 15 | public int add(int a, int b) { 16 | return a + b; 17 | } 18 | 19 | } 20 | -------------------------------------------------------------------------------- /junit-jupiter-starter-gradle/src/main/java/com/example/project/Calculator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2025 the original author or authors. 3 | * 4 | * All rights reserved. This program and the accompanying materials are 5 | * made available under the terms of the Eclipse Public License v2.0 which 6 | * accompanies this distribution and is available at 7 | * 8 | * https://www.eclipse.org/legal/epl-v20.html 9 | */ 10 | 11 | package com.example.project; 12 | 13 | public class Calculator { 14 | 15 | public int add(int a, int b) { 16 | return a + b; 17 | } 18 | 19 | } 20 | -------------------------------------------------------------------------------- /junit-jupiter-starter-maven/src/main/java/com/example/project/Calculator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2025 the original author or authors. 3 | * 4 | * All rights reserved. This program and the accompanying materials are 5 | * made available under the terms of the Eclipse Public License v2.0 which 6 | * accompanies this distribution and is available at 7 | * 8 | * https://www.eclipse.org/legal/epl-v20.html 9 | */ 10 | 11 | package com.example.project; 12 | 13 | public class Calculator { 14 | 15 | public int add(int a, int b) { 16 | return a + b; 17 | } 18 | 19 | } 20 | -------------------------------------------------------------------------------- /junit-modular-world/src/build/Compile.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2025 the original author or authors. 3 | * 4 | * All rights reserved. This program and the accompanying materials are 5 | * made available under the terms of the Eclipse Public License v2.0 which 6 | * accompanies this distribution and is available at 7 | * 8 | * https://www.eclipse.org/legal/epl-v20.html 9 | */ 10 | 11 | // default package 12 | 13 | public class Compile { 14 | public static void main(String[] args) throws Exception { 15 | Project.ofCurrentWorkingDirectory().compile(); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /junit-modular-world/src/main/ice.cream/module-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2025 the original author or authors. 3 | * 4 | * All rights reserved. This program and the accompanying materials are 5 | * made available under the terms of the Eclipse Public License v2.0 which 6 | * accompanies this distribution and is available at 7 | * 8 | * https://www.eclipse.org/legal/epl-v20.html 9 | */ 10 | 11 | import org.junit.platform.engine.TestEngine; 12 | 13 | module ice.cream { 14 | requires org.junit.platform.engine; 15 | 16 | provides TestEngine with ice.cream.Machine; 17 | } 18 | -------------------------------------------------------------------------------- /junit-source-launcher/src/HelloTests.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2025 the original author or authors. 3 | * 4 | * All rights reserved. This program and the accompanying materials are 5 | * made available under the terms of the Eclipse Public License v2.0 which 6 | * accompanies this distribution and is available at 7 | * 8 | * https://www.eclipse.org/legal/epl-v20.html 9 | */ 10 | 11 | import module org.junit.start; 12 | 13 | void main() { 14 | JUnit.run(); 15 | } 16 | 17 | @Test 18 | void stringLength() { 19 | Assertions.assertEquals(11, "Hello JUnit".length()); 20 | } 21 | -------------------------------------------------------------------------------- /junit-jupiter-starter-gradle/build.gradle: -------------------------------------------------------------------------------- 1 | plugins { 2 | id 'java' 3 | id 'eclipse' // optional (to generate Eclipse project files) 4 | id 'idea' // optional (to generate IntelliJ IDEA project files) 5 | } 6 | 7 | repositories { 8 | mavenCentral() 9 | } 10 | 11 | dependencies { 12 | testImplementation(platform('org.junit:junit-bom:6.0.1')) 13 | testImplementation('org.junit.jupiter:junit-jupiter') 14 | testRuntimeOnly('org.junit.platform:junit-platform-launcher') 15 | } 16 | 17 | test { 18 | useJUnitPlatform() 19 | testLogging { 20 | events "passed", "skipped", "failed" 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /junit-modular-world/src/main/com.example.tool/com/example/tool/internal/MathHelper.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2025 the original author or authors. 3 | * 4 | * All rights reserved. This program and the accompanying materials are 5 | * made available under the terms of the Eclipse Public License v2.0 which 6 | * accompanies this distribution and is available at 7 | * 8 | * https://www.eclipse.org/legal/epl-v20.html 9 | */ 10 | 11 | package com.example.tool.internal; 12 | 13 | public class MathHelper { 14 | 15 | public static int pow(int a, int b) { 16 | return (int) Math.pow(a, b); 17 | } 18 | 19 | } 20 | -------------------------------------------------------------------------------- /junit-multiple-engines/src/test/java/junit/vintage/JUnit3Test.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2025 the original author or authors. 3 | * 4 | * All rights reserved. This program and the accompanying materials are 5 | * made available under the terms of the Eclipse Public License v2.0 which 6 | * accompanies this distribution and is available at 7 | * 8 | * https://www.eclipse.org/legal/epl-v20.html 9 | */ 10 | 11 | package junit.vintage; 12 | 13 | import junit.framework.TestCase; 14 | 15 | public class JUnit3Test extends TestCase { 16 | 17 | public void test() { 18 | assertEquals(3, 1 + 2); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /junit-multiple-engines/src/test/java/testng/TestNGTests.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2025 the original author or authors. 3 | * 4 | * All rights reserved. This program and the accompanying materials are 5 | * made available under the terms of the Eclipse Public License v2.0 which 6 | * accompanies this distribution and is available at 7 | * 8 | * https://www.eclipse.org/legal/epl-v20.html 9 | */ 10 | 11 | package testng; 12 | 13 | import org.testng.annotations.Test; 14 | 15 | public class TestNGTests { 16 | 17 | @Test 18 | public void test1() {} 19 | 20 | @Test 21 | public void test2() {} 22 | } 23 | -------------------------------------------------------------------------------- /junit-multiple-engines/src/test/java/jqwik/JQwikTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2025 the original author or authors. 3 | * 4 | * All rights reserved. This program and the accompanying materials are 5 | * made available under the terms of the Eclipse Public License v2.0 which 6 | * accompanies this distribution and is available at 7 | * 8 | * https://www.eclipse.org/legal/epl-v20.html 9 | */ 10 | 11 | package jqwik; 12 | 13 | import net.jqwik.api.*; 14 | 15 | class JQwikTest { 16 | @Property(tries = 10) 17 | @Label("Hello from JQwik!") 18 | boolean helloFromJQwik(@ForAll int aNumber) { 19 | return true; 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /junit-multiple-engines/src/test/kotlin/kotest/KotestSpec.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2025 the original author or authors. 3 | * 4 | * All rights reserved. This program and the accompanying materials are 5 | * made available under the terms of the Eclipse Public License v2.0 which 6 | * accompanies this distribution and is available at 7 | * 8 | * https://www.eclipse.org/legal/epl-v20.html 9 | */ 10 | 11 | package kotest 12 | 13 | import io.kotest.core.spec.style.StringSpec 14 | import io.kotest.matchers.shouldBe 15 | 16 | class KotestSpec : StringSpec({ 17 | "1 + 2 should be 3" { 18 | 1 + 2 shouldBe 3 19 | } 20 | }) 21 | -------------------------------------------------------------------------------- /junit-jupiter-starter-gradle-groovy/build.gradle: -------------------------------------------------------------------------------- 1 | plugins { 2 | id 'groovy' 3 | id 'eclipse' // optional (to generate Eclipse project files) 4 | id 'idea' // optional (to generate IntelliJ IDEA project files) 5 | } 6 | 7 | repositories { 8 | mavenCentral() 9 | } 10 | 11 | dependencies { 12 | implementation(localGroovy()) 13 | testImplementation(platform('org.junit:junit-bom:6.0.1')) 14 | testImplementation('org.junit.jupiter:junit-jupiter') 15 | testRuntimeOnly('org.junit.platform:junit-platform-launcher') 16 | } 17 | 18 | test { 19 | useJUnitPlatform() 20 | testLogging { 21 | events "passed", "skipped", "failed" 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /junit-modular-world/src/test/com.example.application/module-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2025 the original author or authors. 3 | * 4 | * All rights reserved. This program and the accompanying materials are 5 | * made available under the terms of the Eclipse Public License v2.0 which 6 | * accompanies this distribution and is available at 7 | * 8 | * https://www.eclipse.org/legal/epl-v20.html 9 | */ 10 | 11 | open module com.example.application { 12 | // 13 | // copied from "main" module 14 | // 15 | requires com.example.tool; 16 | 17 | // 18 | // test dependencies 19 | // 20 | requires org.junit.jupiter.api; 21 | } 22 | -------------------------------------------------------------------------------- /junit-jupiter-starter-sbt/build.sbt: -------------------------------------------------------------------------------- 1 | ThisBuild / organization := "com.example" 2 | ThisBuild / scalaVersion := "3.7.4" 3 | ThisBuild / version := "0.1.0-SNAPSHOT" 4 | 5 | lazy val root = project 6 | .in(file(".")) 7 | .settings( 8 | name := "junit-jupiter-starter-sbt", 9 | libraryDependencies ++= Seq( 10 | "net.aichler" % "jupiter-interface" % JupiterKeys.jupiterVersion.value % Test, 11 | "org.junit.jupiter" % "junit-jupiter" % "6.0.1" % Test, 12 | "org.junit.platform" % "junit-platform-launcher" % "6.0.1" % Test, 13 | ), 14 | testOptions += Tests.Argument(jupiterTestFramework, "--display-mode=tree") 15 | ) 16 | -------------------------------------------------------------------------------- /.github/workflows/gradle-wrapper-validation.yml: -------------------------------------------------------------------------------- 1 | name: "Validate Gradle Wrapper" 2 | on: 3 | push: 4 | branches: 5 | - main 6 | - 'r5.*' 7 | - 'r6.*' 8 | - 'releases/**' 9 | pull_request: 10 | branches: 11 | - '*' 12 | 13 | permissions: 14 | contents: read 15 | 16 | jobs: 17 | validation: 18 | name: "Validation" 19 | runs-on: ubuntu-latest 20 | steps: 21 | - uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1 22 | - uses: gradle/actions/wrapper-validation@4d9f0ba0025fe599b4ebab900eb7f3a1d93ef4c2 # v5.0.0 23 | with: 24 | min-wrapper-count: 6 25 | -------------------------------------------------------------------------------- /junit-migration-gradle/src/test/java/com/example/project/OtherTests.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2025 the original author or authors. 3 | * 4 | * All rights reserved. This program and the accompanying materials are 5 | * made available under the terms of the Eclipse Public License v2.0 which 6 | * accompanies this distribution and is available at 7 | * 8 | * https://www.eclipse.org/legal/epl-v20.html 9 | */ 10 | 11 | package com.example.project; 12 | 13 | import org.junit.jupiter.api.Test; 14 | 15 | class OtherTests { 16 | 17 | @Test 18 | void testThisThing() { 19 | } 20 | 21 | @Test 22 | void testThisOtherThing() { 23 | } 24 | 25 | } 26 | -------------------------------------------------------------------------------- /junit-migration-maven/src/test/java/com/example/project/OtherTests.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2025 the original author or authors. 3 | * 4 | * All rights reserved. This program and the accompanying materials are 5 | * made available under the terms of the Eclipse Public License v2.0 which 6 | * accompanies this distribution and is available at 7 | * 8 | * https://www.eclipse.org/legal/epl-v20.html 9 | */ 10 | 11 | package com.example.project; 12 | 13 | import org.junit.jupiter.api.Test; 14 | 15 | class OtherTests { 16 | 17 | @Test 18 | void testThisThing() { 19 | } 20 | 21 | @Test 22 | void testThisOtherThing() { 23 | } 24 | 25 | } 26 | -------------------------------------------------------------------------------- /junit-multiple-engines/src/test/java/junit/vintage/JUnit4Test.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2025 the original author or authors. 3 | * 4 | * All rights reserved. This program and the accompanying materials are 5 | * made available under the terms of the Eclipse Public License v2.0 which 6 | * accompanies this distribution and is available at 7 | * 8 | * https://www.eclipse.org/legal/epl-v20.html 9 | */ 10 | 11 | package junit.vintage; 12 | 13 | import static org.junit.Assert.assertEquals; 14 | 15 | import org.junit.Test; 16 | 17 | public class JUnit4Test { 18 | 19 | @Test 20 | public void test() { 21 | assertEquals(3, 1 + 2); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /junit-modular-world/src/build/Build.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2025 the original author or authors. 3 | * 4 | * All rights reserved. This program and the accompanying materials are 5 | * made available under the terms of the Eclipse Public License v2.0 which 6 | * accompanies this distribution and is available at 7 | * 8 | * https://www.eclipse.org/legal/epl-v20.html 9 | */ 10 | 11 | // default package 12 | 13 | public class Build { 14 | public static void main(String[] args) throws Exception { 15 | var project = Project.ofCurrentWorkingDirectory(); 16 | project.clean(); 17 | project.compile(); 18 | project.test(); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /junit-modular-world/src/test/com.example.tool/module-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2025 the original author or authors. 3 | * 4 | * All rights reserved. This program and the accompanying materials are 5 | * made available under the terms of the Eclipse Public License v2.0 which 6 | * accompanies this distribution and is available at 7 | * 8 | * https://www.eclipse.org/legal/epl-v20.html 9 | */ 10 | 11 | open module com.example.tool { 12 | // 13 | // copied from "main" module 14 | // 15 | exports com.example.tool; 16 | 17 | // 18 | // test dependencies 19 | // 20 | requires org.junit.jupiter.api; 21 | requires org.junit.jupiter.params; 22 | } 23 | -------------------------------------------------------------------------------- /junit-migration-gradle/src/test/java/com/example/project/JUnit4Test.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2025 the original author or authors. 3 | * 4 | * All rights reserved. This program and the accompanying materials are 5 | * made available under the terms of the Eclipse Public License v2.0 which 6 | * accompanies this distribution and is available at 7 | * 8 | * https://www.eclipse.org/legal/epl-v20.html 9 | */ 10 | 11 | package com.example.project; 12 | 13 | import static org.junit.Assert.assertEquals; 14 | 15 | import org.junit.Test; 16 | 17 | public class JUnit4Test { 18 | 19 | @Test 20 | public void test() { 21 | assertEquals(3, 1 + 2); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /junit-migration-maven/src/test/java/com/example/project/JUnit4Test.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2025 the original author or authors. 3 | * 4 | * All rights reserved. This program and the accompanying materials are 5 | * made available under the terms of the Eclipse Public License v2.0 which 6 | * accompanies this distribution and is available at 7 | * 8 | * https://www.eclipse.org/legal/epl-v20.html 9 | */ 10 | 11 | package com.example.project; 12 | 13 | import static org.junit.Assert.assertEquals; 14 | 15 | import org.junit.Test; 16 | 17 | public class JUnit4Test { 18 | 19 | @Test 20 | public void test() { 21 | assertEquals(3, 1 + 2); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /junit-modular-world/src/main/ice.cream/ice/cream/Flavor.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2025 the original author or authors. 3 | * 4 | * All rights reserved. This program and the accompanying materials are 5 | * made available under the terms of the Eclipse Public License v2.0 which 6 | * accompanies this distribution and is available at 7 | * 8 | * https://www.eclipse.org/legal/epl-v20.html 9 | */ 10 | 11 | package ice.cream; 12 | 13 | enum Flavor { 14 | 15 | Chocolate, 16 | 17 | Stracciatella, 18 | 19 | Vanilla; 20 | 21 | static Flavor random() { 22 | Flavor[] flavors = values(); 23 | return flavors[(int) (Math.random() * flavors.length)]; 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /junit-modular-world/src/test/extra.modular/extra/modular/GoodOldTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2025 the original author or authors. 3 | * 4 | * All rights reserved. This program and the accompanying materials are 5 | * made available under the terms of the Eclipse Public License v2.0 which 6 | * accompanies this distribution and is available at 7 | * 8 | * https://www.eclipse.org/legal/epl-v20.html 9 | */ 10 | 11 | package black.box; 12 | 13 | import com.example.tool.*; 14 | import org.junit.*; 15 | 16 | public class GoodOldTest { 17 | 18 | @Test 19 | public void eighteenEqualsNineAndNine() { 20 | Assert.assertEquals(18, new Calculator().add(9, 9)); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /junit-modular-world/src/test/ice.cream/ice/cream/FlavorTests.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2025 the original author or authors. 3 | * 4 | * All rights reserved. This program and the accompanying materials are 5 | * made available under the terms of the Eclipse Public License v2.0 which 6 | * accompanies this distribution and is available at 7 | * 8 | * https://www.eclipse.org/legal/epl-v20.html 9 | */ 10 | 11 | package ice.cream; 12 | 13 | import static org.junit.jupiter.api.Assertions.assertNotNull; 14 | 15 | import org.junit.jupiter.api.Test; 16 | 17 | class FlavorTests { 18 | 19 | @Test 20 | void random() { 21 | Flavor flavor = Flavor.random(); 22 | assertNotNull(flavor); 23 | } 24 | 25 | } 26 | -------------------------------------------------------------------------------- /junit-multiple-engines/src/test/groovy/spock/SpockSpec.groovy: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2025 the original author or authors. 3 | * 4 | * All rights reserved. This program and the accompanying materials are 5 | * made available under the terms of the Eclipse Public License v2.0 which 6 | * accompanies this distribution and is available at 7 | * 8 | * https://www.eclipse.org/legal/epl-v20.html 9 | */ 10 | 11 | package spock 12 | 13 | import spock.lang.Specification 14 | 15 | class SpockSpec extends Specification { 16 | def "assert that the sum of two numbers equals an expected result"() { 17 | expect: 18 | a + b == result 19 | 20 | where: 21 | a | b | result 22 | 1 | 2 | 3 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /junit-multiple-engines/src/test/kotlin/spek/SpekTest.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2025 the original author or authors. 3 | * 4 | * All rights reserved. This program and the accompanying materials are 5 | * made available under the terms of the Eclipse Public License v2.0 which 6 | * accompanies this distribution and is available at 7 | * 8 | * https://www.eclipse.org/legal/epl-v20.html 9 | */ 10 | 11 | package spek 12 | 13 | import org.spekframework.spek2.Spek 14 | import org.spekframework.spek2.style.specification.describe 15 | 16 | class SpekTest : Spek({ 17 | describe("a simple test") { 18 | it("asserts that 1 + 2 equals 3") { 19 | assert(1 + 2 == 3) 20 | } 21 | } 22 | }) 23 | -------------------------------------------------------------------------------- /junit-jupiter-starter-gradle-kotlin/src/main/kotlin/com/example/project/Calculator.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2025 the original author or authors. 3 | * 4 | * All rights reserved. This program and the accompanying materials are 5 | * made available under the terms of the Eclipse Public License v2.0 which 6 | * accompanies this distribution and is available at 7 | * 8 | * https://www.eclipse.org/legal/epl-v20.html 9 | */ 10 | 11 | package com.example.project 12 | 13 | class Calculator { 14 | 15 | fun add(a: Int, b: Int): Int { 16 | return a + b 17 | } 18 | 19 | fun div(a: Int, b: Int): Double { 20 | assert(b != 0) { "Division by Zero" } 21 | return a / b * 1.0 22 | } 23 | 24 | } 25 | -------------------------------------------------------------------------------- /junit-modular-world/src/test/extra.modular/module-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2025 the original author or authors. 3 | * 4 | * All rights reserved. This program and the accompanying materials are 5 | * made available under the terms of the Eclipse Public License v2.0 which 6 | * accompanies this distribution and is available at 7 | * 8 | * https://www.eclipse.org/legal/epl-v20.html 9 | */ 10 | 11 | open module extra.modular { 12 | // 13 | // modules under test 14 | // 15 | requires com.example.application; 16 | requires com.example.tool; 17 | 18 | // 19 | // test framework api 20 | // 21 | requires org.junit.jupiter.api; 22 | requires junit; // JUnit 4 "automatic module" 23 | requires net.jqwik.api; 24 | } 25 | -------------------------------------------------------------------------------- /junit-jupiter-starter-bazel/BUILD: -------------------------------------------------------------------------------- 1 | load("@rules_jvm_external//:defs.bzl", "artifact") 2 | load("@contrib_rules_jvm//java:defs.bzl", "JUNIT5_DEPS", "java_test_suite") 3 | 4 | java_library( 5 | name = "junit-jupiter-starter-bazel", 6 | srcs = glob(["src/main/java/**/*.java"]), 7 | ) 8 | 9 | java_test_suite( 10 | name = "junit-jupiter-starter-bazel-tests", 11 | size = "small", 12 | srcs = glob(["src/test/java/**/*.java"]), 13 | runner = "junit5", 14 | test_suffixes = ["Tests.java"], 15 | runtime_deps = JUNIT5_DEPS, 16 | deps = [ 17 | ":junit-jupiter-starter-bazel", 18 | artifact("org.junit.jupiter:junit-jupiter-api"), 19 | artifact("org.junit.jupiter:junit-jupiter-params"), 20 | ], 21 | ) 22 | -------------------------------------------------------------------------------- /junit-multiple-engines/src/test/java/junit/jupiter/JupiterTests.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2025 the original author or authors. 3 | * 4 | * All rights reserved. This program and the accompanying materials are 5 | * made available under the terms of the Eclipse Public License v2.0 which 6 | * accompanies this distribution and is available at 7 | * 8 | * https://www.eclipse.org/legal/epl-v20.html 9 | */ 10 | 11 | package junit.jupiter; 12 | 13 | import static org.junit.jupiter.api.Assertions.assertEquals; 14 | 15 | import org.junit.jupiter.api.DisplayName; 16 | import org.junit.jupiter.api.Test; 17 | 18 | class JupiterTests { 19 | 20 | @Test 21 | @DisplayName("1 + 2 = 3") 22 | void test() { 23 | assertEquals(3, 1 + 2); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /junit-modular-world/src/main/com.example.tool/com/example/tool/Calculator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2025 the original author or authors. 3 | * 4 | * All rights reserved. This program and the accompanying materials are 5 | * made available under the terms of the Eclipse Public License v2.0 which 6 | * accompanies this distribution and is available at 7 | * 8 | * https://www.eclipse.org/legal/epl-v20.html 9 | */ 10 | 11 | package com.example.tool; 12 | 13 | import com.example.tool.internal.MathHelper; 14 | 15 | public class Calculator { 16 | 17 | public int add(int a, int b) { 18 | return a + b; 19 | } 20 | 21 | protected int mul(int a, int b) { 22 | return a * b; 23 | } 24 | 25 | int pow(int a, int b) { 26 | return MathHelper.pow(a, b); 27 | } 28 | 29 | } 30 | -------------------------------------------------------------------------------- /.github/workflows/nohttp.yml: -------------------------------------------------------------------------------- 1 | name: Verify HTTPS URLs are used 2 | 3 | on: 4 | push: 5 | branches: 6 | - main 7 | - 'r5.*' 8 | - 'r6.*' 9 | - 'releases/**' 10 | pull_request: 11 | branches: 12 | - '*' 13 | 14 | permissions: 15 | contents: read 16 | 17 | jobs: 18 | nohttp: 19 | runs-on: ubuntu-latest 20 | steps: 21 | - uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1 22 | - name: 'Run nohttp' 23 | uses: jbangdev/jbang-action@d0ab22dc0ea8b6bf9114e50e44ba89b0fb939238 # v0.135.0 24 | with: 25 | script: io.spring.nohttp:nohttp-cli:0.0.9 26 | scriptargs: "-D=\\.git -D=build -D=target -D=apache-ant-.+ -F=maven-wrapper\\.properties -F=mvnw\\.cmd -Fmvnw -FMODULE.bazel.lock" 27 | -------------------------------------------------------------------------------- /junit-modular-world/src/test/extra.modular/extra/modular/JQwikTests.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2025 the original author or authors. 3 | * 4 | * All rights reserved. This program and the accompanying materials are 5 | * made available under the terms of the Eclipse Public License v2.0 which 6 | * accompanies this distribution and is available at 7 | * 8 | * https://www.eclipse.org/legal/epl-v20.html 9 | */ 10 | 11 | package black.box; 12 | 13 | import com.example.tool.*; 14 | import net.jqwik.api.*; 15 | 16 | class JQwikTests { 17 | 18 | @Example 19 | boolean exampleFor1And3Equals4() { 20 | return new Calculator().add(1, 3) == 4; 21 | } 22 | 23 | @Property 24 | boolean propertyAdd(@ForAll int a, @ForAll int b) { 25 | return new Calculator().add(a, b) == a + b; 26 | } 27 | 28 | } 29 | -------------------------------------------------------------------------------- /junit-modular-world/src/test/ice.cream/module-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2025 the original author or authors. 3 | * 4 | * All rights reserved. This program and the accompanying materials are 5 | * made available under the terms of the Eclipse Public License v2.0 which 6 | * accompanies this distribution and is available at 7 | * 8 | * https://www.eclipse.org/legal/epl-v20.html 9 | */ 10 | 11 | import org.junit.platform.engine.TestEngine; 12 | 13 | open module ice.cream { 14 | // 15 | // copied from "main" 16 | // 17 | requires org.junit.platform.engine; 18 | 19 | provides TestEngine with ice.cream.Machine; 20 | 21 | // 22 | // test dependencies 23 | // 24 | requires org.junit.jupiter.api; 25 | 26 | // "open module" or "opens ice.cream to org.junit.platform.commons;" 27 | } 28 | -------------------------------------------------------------------------------- /junit-jupiter-starter-bazel/MODULE.bazel: -------------------------------------------------------------------------------- 1 | JUNIT_VERSION = "6.0.1" 2 | 3 | bazel_dep(name = "rules_jvm_external", version = "6.9") 4 | bazel_dep(name = "contrib_rules_jvm", version = "0.31.1") 5 | 6 | maven = use_extension("@rules_jvm_external//:extensions.bzl", "maven") 7 | 8 | maven.install( 9 | artifacts = [ 10 | "org.junit.platform:junit-platform-launcher:%s" % JUNIT_VERSION, 11 | "org.junit.platform:junit-platform-reporting:%s" % JUNIT_VERSION, 12 | "org.junit.jupiter:junit-jupiter-api:%s" % JUNIT_VERSION, 13 | "org.junit.jupiter:junit-jupiter-params:%s" % JUNIT_VERSION, 14 | "org.junit.jupiter:junit-jupiter-engine:%s" % JUNIT_VERSION, 15 | ], 16 | repositories = [ 17 | "https://repo1.maven.org/maven2", 18 | ], 19 | ) 20 | 21 | use_repo(maven, "maven") 22 | -------------------------------------------------------------------------------- /junit-jupiter-starter-gradle-kotlin/build.gradle.kts: -------------------------------------------------------------------------------- 1 | import org.jetbrains.kotlin.gradle.dsl.JvmTarget.JVM_17 2 | import org.jetbrains.kotlin.gradle.tasks.KotlinCompile 3 | 4 | plugins { 5 | kotlin("jvm") version "2.2.21" 6 | } 7 | 8 | repositories { 9 | mavenCentral() 10 | } 11 | 12 | dependencies { 13 | testImplementation(platform("org.junit:junit-bom:6.0.1")) 14 | testImplementation("org.junit.jupiter:junit-jupiter") 15 | testRuntimeOnly("org.junit.platform:junit-platform-launcher") 16 | } 17 | 18 | tasks.test { 19 | useJUnitPlatform() 20 | testLogging { 21 | events("passed", "skipped", "failed") 22 | } 23 | } 24 | 25 | tasks.withType().configureEach { 26 | options.release = 17 27 | } 28 | 29 | tasks.withType().configureEach { 30 | compilerOptions.jvmTarget = JVM_17 31 | } 32 | -------------------------------------------------------------------------------- /junit-modular-world/src/main/com.example.application/com/example/application/Main.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2025 the original author or authors. 3 | * 4 | * All rights reserved. This program and the accompanying materials are 5 | * made available under the terms of the Eclipse Public License v2.0 which 6 | * accompanies this distribution and is available at 7 | * 8 | * https://www.eclipse.org/legal/epl-v20.html 9 | */ 10 | 11 | package com.example.application; 12 | 13 | import com.example.tool.Calculator; 14 | 15 | class Main { 16 | 17 | public static void main(String... args) { 18 | int a = args.length > 0 ? (Integer.valueOf(args[0])) : 1; 19 | int b = args.length > 1 ? (Integer.valueOf(args[1])) : 2; 20 | System.out.printf("%d + %d = %d%n", a, b, new Calculator().add(a, b)); 21 | } 22 | 23 | } 24 | -------------------------------------------------------------------------------- /junit-modular-world/src/main/ice.cream/ice/cream/Scoop.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2025 the original author or authors. 3 | * 4 | * All rights reserved. This program and the accompanying materials are 5 | * made available under the terms of the Eclipse Public License v2.0 which 6 | * accompanies this distribution and is available at 7 | * 8 | * https://www.eclipse.org/legal/epl-v20.html 9 | */ 10 | 11 | package ice.cream; 12 | 13 | import org.junit.platform.engine.UniqueId; 14 | import org.junit.platform.engine.support.descriptor.AbstractTestDescriptor; 15 | 16 | class Scoop extends AbstractTestDescriptor { 17 | 18 | Scoop(UniqueId uniqueId, int counter, Flavor flavor) { 19 | super(uniqueId.append("scoop", "#" + counter), flavor.name()); 20 | } 21 | 22 | @Override 23 | public Type getType() { 24 | return Type.TEST; 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /junit-multiple-engines/buildSrc/src/main/kotlin/ReportsDirArgumentProvider.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2025 the original author or authors. 3 | * 4 | * All rights reserved. This program and the accompanying materials are 5 | * made available under the terms of the Eclipse Public License v2.0 which 6 | * accompanies this distribution and is available at 7 | * 8 | * https://www.eclipse.org/legal/epl-v20.html 9 | */ 10 | 11 | import org.gradle.api.file.DirectoryProperty 12 | import org.gradle.api.tasks.OutputDirectory 13 | import org.gradle.process.CommandLineArgumentProvider 14 | 15 | abstract class ReportsDirArgumentProvider : CommandLineArgumentProvider { 16 | 17 | @get:OutputDirectory 18 | abstract val reportsDir: DirectoryProperty 19 | 20 | override fun asArguments() = listOf("--reports-dir", reportsDir.asFile.get().absolutePath) 21 | } 22 | -------------------------------------------------------------------------------- /junit-jupiter-extensions/build.gradle: -------------------------------------------------------------------------------- 1 | plugins { 2 | id 'java-library' 3 | id 'eclipse' // optional (to generate Eclipse project files) 4 | id 'idea' // optional (to generate IntelliJ IDEA project files) 5 | } 6 | 7 | repositories { 8 | mavenCentral() 9 | } 10 | 11 | version = '1.0.0-SNAPSHOT' 12 | 13 | tasks.withType(JavaCompile).configureEach { 14 | options.release = 17 15 | options.compilerArgs += '-parameters' 16 | } 17 | 18 | dependencies { 19 | api(platform("org.junit:junit-bom:6.0.1")) 20 | api("org.junit.jupiter:junit-jupiter-api") { 21 | because 'building extensions in "main" using JUnit Jupiter API' 22 | } 23 | testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine") { 24 | because 'at least one engine is needed at test runtime' 25 | } 26 | testRuntimeOnly('org.junit.platform:junit-platform-launcher') 27 | } 28 | 29 | test { 30 | useJUnitPlatform() 31 | } 32 | -------------------------------------------------------------------------------- /junit-migration-gradle/src/test/java/com/example/project/SecondTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2025 the original author or authors. 3 | * 4 | * All rights reserved. This program and the accompanying materials are 5 | * made available under the terms of the Eclipse Public License v2.0 which 6 | * accompanies this distribution and is available at 7 | * 8 | * https://www.eclipse.org/legal/epl-v20.html 9 | */ 10 | 11 | package com.example.project; 12 | 13 | import static org.junit.jupiter.api.Assertions.assertEquals; 14 | 15 | import org.junit.jupiter.api.Disabled; 16 | import org.junit.jupiter.api.Tag; 17 | import org.junit.jupiter.api.Test; 18 | 19 | class SecondTest { 20 | 21 | @Test 22 | @Disabled 23 | void mySecondTest() { 24 | assertEquals(2, 1, "2 is not equal to 1"); 25 | } 26 | 27 | @Test 28 | @Tag("slow") 29 | void aSlowTest() throws InterruptedException { 30 | Thread.sleep(1000); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /junit-migration-maven/src/test/java/com/example/project/SecondTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2025 the original author or authors. 3 | * 4 | * All rights reserved. This program and the accompanying materials are 5 | * made available under the terms of the Eclipse Public License v2.0 which 6 | * accompanies this distribution and is available at 7 | * 8 | * https://www.eclipse.org/legal/epl-v20.html 9 | */ 10 | 11 | package com.example.project; 12 | 13 | import static org.junit.jupiter.api.Assertions.assertEquals; 14 | 15 | import org.junit.jupiter.api.Disabled; 16 | import org.junit.jupiter.api.Tag; 17 | import org.junit.jupiter.api.Test; 18 | 19 | class SecondTest { 20 | 21 | @Test 22 | @Disabled 23 | void mySecondTest() { 24 | assertEquals(2, 1, "2 is not equal to 1"); 25 | } 26 | 27 | @Test 28 | @Tag("slow") 29 | void aSlowTest() throws InterruptedException { 30 | Thread.sleep(1000); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/central-staging-maven-settings.xml: -------------------------------------------------------------------------------- 1 | 3 | 4 | 5 | central-staging 6 | 7 | 8 | 9 | Authorization 10 | Bearer ${env.MAVEN_CENTRAL_USER_TOKEN} 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | central-staging 19 | 20 | 21 | central-staging 22 | ${env.STAGING_REPO_URL} 23 | 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /junit-modular-world/src/test/ice.cream/ice/cream/MachineTests.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2025 the original author or authors. 3 | * 4 | * All rights reserved. This program and the accompanying materials are 5 | * made available under the terms of the Eclipse Public License v2.0 which 6 | * accompanies this distribution and is available at 7 | * 8 | * https://www.eclipse.org/legal/epl-v20.html 9 | */ 10 | 11 | package ice.cream; 12 | 13 | import static org.junit.jupiter.api.Assertions.assertEquals; 14 | import static org.junit.jupiter.api.Assertions.assertTrue; 15 | 16 | import org.junit.jupiter.api.Test; 17 | 18 | class MachineTests { 19 | 20 | @Test 21 | void caption() { 22 | String actual = new Machine().getCaption(); 23 | assertTrue(actual.startsWith("Ice Cream Machine")); 24 | } 25 | 26 | @Test 27 | void id() { 28 | String expected = "ice-cream-machine"; 29 | String actual = new Machine().getId(); 30 | assertEquals(expected, actual, "Machine ID mismatch!"); 31 | } 32 | 33 | } 34 | -------------------------------------------------------------------------------- /junit-multiple-engines/src/test/java/suite/SuiteTests.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2025 the original author or authors. 3 | * 4 | * All rights reserved. This program and the accompanying materials are 5 | * made available under the terms of the Eclipse Public License v2.0 which 6 | * accompanies this distribution and is available at 7 | * 8 | * https://www.eclipse.org/legal/epl-v20.html 9 | */ 10 | 11 | package suite; 12 | 13 | import org.junit.platform.suite.api.ExcludeEngines; 14 | import org.junit.platform.suite.api.IncludeClassNamePatterns; 15 | import org.junit.platform.suite.api.IncludeEngines; 16 | import org.junit.platform.suite.api.SelectPackages; 17 | import org.junit.platform.suite.api.Suite; 18 | 19 | @Suite 20 | @SelectPackages({"spock", "jqwik", "junit.jupiter", "junit.vintage", "mainrunner", "testng", "kotest", "spek"}) 21 | @IncludeClassNamePatterns(".*((Tests?)|(Spec))$") 22 | @ExcludeEngines("spek") // https://github.com/spekframework/spek/issues/986 23 | public class SuiteTests { 24 | } 25 | -------------------------------------------------------------------------------- /junit-modular-world/src/test/com.example.tool/com/example/tool/CalculatorTests.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2025 the original author or authors. 3 | * 4 | * All rights reserved. This program and the accompanying materials are 5 | * made available under the terms of the Eclipse Public License v2.0 which 6 | * accompanies this distribution and is available at 7 | * 8 | * https://www.eclipse.org/legal/epl-v20.html 9 | */ 10 | 11 | package com.example.tool; 12 | 13 | import org.junit.jupiter.api.*; 14 | 15 | @DisplayName("com.example.tool/com.example.tool.CalculatorTests") 16 | class CalculatorTests { 17 | 18 | private final Calculator calculator = new Calculator(); 19 | 20 | @Test 21 | void add() { 22 | Assertions.assertEquals(2, calculator.add(1, 1), "1 + 1 should equal 2"); 23 | } 24 | 25 | @Test 26 | void mul() { 27 | Assertions.assertEquals(4, calculator.mul(2, 2), "2 * 2 should equal 4"); 28 | } 29 | 30 | @Test 31 | void pow() { 32 | Assertions.assertEquals(8, calculator.pow(2, 3), "2 ^ 3 should equal 8"); 33 | } 34 | 35 | } 36 | -------------------------------------------------------------------------------- /junit-jupiter-extensions/README.md: -------------------------------------------------------------------------------- 1 | # junit-jupiter-extensions 2 | 3 | A collection of JUnit Jupiter example extensions. 4 | 5 | * The `RandomParametersExtension` showcases the `ParameterResolver` extension 6 | API by providing injection support for random values at the method parameter 7 | level. 8 | 9 | * The `@CartesianProductTest` showcases the `@TestTemplate` extension API by 10 | providing an example implementation for invoking a method multiple times. It 11 | uses the `TestTemplateInvocationContextProvider`, `TestTemplateInvocationContext` 12 | and the `ParameterResolver` extension points to generate the [cartesian product] 13 | from a single or n-ary source sets. 14 | 15 | For real-world usage examples of the JUnit Jupiter Extension APIs, check out the 16 | list of [third-party extensions], e.g. the ones provided by Spring and Mockito. 17 | 18 | [third-party extensions]: https://github.com/junit-team/junit-framework/wiki/Third-party-Extensions#junit-jupiter-extensions 19 | [cartesian product]: https://en.wikipedia.org/wiki/Cartesian_product 20 | -------------------------------------------------------------------------------- /junit-migration-maven/src/test/java/com/example/project/FirstTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2025 the original author or authors. 3 | * 4 | * All rights reserved. This program and the accompanying materials are 5 | * made available under the terms of the Eclipse Public License v2.0 which 6 | * accompanies this distribution and is available at 7 | * 8 | * https://www.eclipse.org/legal/epl-v20.html 9 | */ 10 | 11 | package com.example.project; 12 | 13 | import static org.junit.jupiter.api.Assertions.assertEquals; 14 | 15 | import org.junit.jupiter.api.DisplayName; 16 | import org.junit.jupiter.api.Tag; 17 | import org.junit.jupiter.api.Test; 18 | import org.junit.jupiter.api.TestInfo; 19 | 20 | @Tag("fast") 21 | class FirstTest { 22 | 23 | @Test 24 | @DisplayName("My 1st JUnit 5 test! 😎") 25 | void myFirstTest(TestInfo testInfo) { 26 | Calculator calculator = new Calculator(); 27 | assertEquals(2, calculator.add(1, 1), "1 + 1 should equal 2"); 28 | assertEquals("My 1st JUnit 5 test! 😎", testInfo.getDisplayName(), () -> "TestInfo is injected correctly"); 29 | } 30 | 31 | } 32 | -------------------------------------------------------------------------------- /junit-migration-gradle/src/test/java/com/example/project/FirstTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2025 the original author or authors. 3 | * 4 | * All rights reserved. This program and the accompanying materials are 5 | * made available under the terms of the Eclipse Public License v2.0 which 6 | * accompanies this distribution and is available at 7 | * 8 | * https://www.eclipse.org/legal/epl-v20.html 9 | */ 10 | 11 | package com.example.project; 12 | 13 | import static org.junit.jupiter.api.Assertions.assertEquals; 14 | 15 | import org.junit.jupiter.api.DisplayName; 16 | import org.junit.jupiter.api.Tag; 17 | import org.junit.jupiter.api.Test; 18 | import org.junit.jupiter.api.TestInfo; 19 | 20 | @Tag("fast") 21 | class FirstTest { 22 | 23 | @Test 24 | @DisplayName("My 1st JUnit 5 test! 😎") 25 | void myFirstTest(TestInfo testInfo) { 26 | Calculator calculator = new Calculator(); 27 | assertEquals(2, calculator.add(1, 1), "1 + 1 should equal 2"); 28 | assertEquals("My 1st JUnit 5 test! 😎", testInfo.getDisplayName(), () -> "TestInfo is injected correctly"); 29 | } 30 | 31 | } 32 | -------------------------------------------------------------------------------- /junit-source-launcher/README.md: -------------------------------------------------------------------------------- 1 | # junit-source-launcher 2 | 3 | Starting with Java 25 it is possible to write minimal source code test programs using the `org.junit.start` module. 4 | For example, take a look at the [HelloTests.java](src/HelloTests.java) file reading: 5 | 6 | ```java 7 | import module org.junit.start; 8 | 9 | void main() { 10 | JUnit.run(); 11 | } 12 | 13 | @Test 14 | void stringLength() { 15 | Assertions.assertEquals(11, "Hello JUnit".length()); 16 | } 17 | ``` 18 | 19 | Download `org.junit.start` module and its transitively required modules into a local `lib/` directory by running in a shell: 20 | 21 | ```shell 22 | java lib/DownloadRequiredModules.java 23 | ``` 24 | 25 | With all required modular JAR files available in a local `lib/` directory, the following Java command will discover and execute tests using the JUnit Platform. 26 | 27 | ```shell 28 | java --module-path lib --add-modules org.junit.start src/HelloTests.java 29 | ``` 30 | 31 | It will also print the result tree to the console. 32 | 33 | ```text 34 | ╷ 35 | └─ JUnit Jupiter ✔ 36 | └─ HelloTests ✔ 37 | └─ stringLength() ✔ 38 | ``` 39 | -------------------------------------------------------------------------------- /junit-migration-gradle/build.gradle: -------------------------------------------------------------------------------- 1 | plugins { 2 | id 'java' 3 | id 'eclipse' // optional (to generate Eclipse project files) 4 | id 'idea' // optional (to generate IntelliJ IDEA project files) 5 | id 'jacoco' 6 | } 7 | 8 | repositories { 9 | mavenCentral() 10 | } 11 | 12 | dependencies { 13 | testImplementation(platform("org.junit:junit-bom:6.0.1")) 14 | 15 | testImplementation("org.junit.jupiter:junit-jupiter") { 16 | because 'allows to write and run Jupiter tests' 17 | } 18 | 19 | testImplementation("junit:junit:4.13.2") 20 | testRuntimeOnly("org.junit.vintage:junit-vintage-engine") { 21 | because 'allows JUnit 3 and JUnit 4 tests to run' 22 | } 23 | 24 | testRuntimeOnly("org.junit.platform:junit-platform-launcher") { 25 | because 'allows tests to run from IDEs that bundle older version of launcher' 26 | } 27 | } 28 | 29 | test { 30 | useJUnitPlatform { 31 | // includeEngines 'junit-jupiter', 'junit-vintage' 32 | // excludeEngines 'custom-engine' 33 | 34 | // includeTags 'fast' 35 | excludeTags 'slow' 36 | } 37 | 38 | testLogging { 39 | events 'passed', 'skipped', 'failed' 40 | } 41 | 42 | finalizedBy(jacocoTestReport) 43 | } 44 | -------------------------------------------------------------------------------- /junit-jupiter-extensions/src/test/java/com/example/random/RandomParametersExtensionTests.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2025 the original author or authors. 3 | * 4 | * All rights reserved. This program and the accompanying materials are 5 | * made available under the terms of the Eclipse Public License v2.0 which 6 | * accompanies this distribution and is available at 7 | * 8 | * https://www.eclipse.org/legal/epl-v20.html 9 | */ 10 | 11 | package com.example.random; 12 | 13 | import com.example.random.RandomParametersExtension.Random; 14 | import org.junit.jupiter.api.Test; 15 | import org.junit.jupiter.api.extension.ExtendWith; 16 | 17 | import static org.junit.jupiter.api.Assertions.assertEquals; 18 | import static org.junit.jupiter.api.Assertions.assertNotEquals; 19 | 20 | /** 21 | * @since 5.2 22 | * @see RandomParametersExtension 23 | */ 24 | @ExtendWith(RandomParametersExtension.class) 25 | class RandomParametersExtensionTests { 26 | 27 | @Test 28 | void injectsInteger(@Random int i, @Random int j) { 29 | assertNotEquals(i, j); 30 | } 31 | 32 | @Test 33 | void injectsDouble(@Random double d) { 34 | assertEquals(0.0, d, 1.0); 35 | } 36 | 37 | } 38 | -------------------------------------------------------------------------------- /junit-modular-world/src/test/com.example.application/com/example/application/MainTests.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2025 the original author or authors. 3 | * 4 | * All rights reserved. This program and the accompanying materials are 5 | * made available under the terms of the Eclipse Public License v2.0 which 6 | * accompanies this distribution and is available at 7 | * 8 | * https://www.eclipse.org/legal/epl-v20.html 9 | */ 10 | 11 | package com.example.application; 12 | 13 | import java.io.*; 14 | import org.junit.jupiter.api.*; 15 | 16 | @DisplayName("com.example.application/com.example.application.MainTests") 17 | class MainTests { 18 | 19 | @Test 20 | void simpleName() { 21 | Assertions.assertEquals("Main", Main.class.getSimpleName()); 22 | } 23 | 24 | @Test 25 | void main() { 26 | PrintStream standard = System.out; 27 | try { 28 | ByteArrayOutputStream bytes = new ByteArrayOutputStream(); 29 | System.setOut(new PrintStream(bytes)); 30 | Main.main("99", "1"); 31 | String actual = bytes.toString().replace("\n", "").replace("\r", ""); 32 | Assertions.assertEquals("99 + 1 = 100", actual); 33 | } finally { 34 | System.setOut(standard); 35 | } 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /junit-jupiter-extensions/src/main/java/com/example/cartesian/CartesianProductContext.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2025 the original author or authors. 3 | * 4 | * All rights reserved. This program and the accompanying materials are 5 | * made available under the terms of the Eclipse Public License v2.0 which 6 | * accompanies this distribution and is available at 7 | * 8 | * https://www.eclipse.org/legal/epl-v20.html 9 | */ 10 | 11 | package com.example.cartesian; 12 | 13 | import java.util.Collections; 14 | import java.util.List; 15 | import org.junit.jupiter.api.extension.Extension; 16 | import org.junit.jupiter.api.extension.TestTemplateInvocationContext; 17 | 18 | class CartesianProductContext implements TestTemplateInvocationContext { 19 | 20 | private final List parameters; 21 | 22 | CartesianProductContext(List parameters) { 23 | this.parameters = parameters; 24 | } 25 | 26 | @Override 27 | public String getDisplayName(int invocationIndex) { 28 | return invocationIndex + ": " + parameters; 29 | } 30 | 31 | @Override 32 | public List getAdditionalExtensions() { 33 | return Collections.singletonList(new CartesianProductResolver(parameters)); 34 | } 35 | 36 | } 37 | -------------------------------------------------------------------------------- /junit-jupiter-starter-ant/build.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | set -e 3 | 4 | # 5 | # Set constants. 6 | # 7 | junit_version='6.0.1' 8 | ant_version='1.10.15' 9 | ant_folder="apache-ant-${ant_version}" 10 | ant_archive="${ant_folder}-bin.tar.gz" 11 | standalone_jar="${ant_folder}/lib/junit-platform-console-standalone-${junit_version}.jar" 12 | 13 | # 14 | # Load and extract Apache Ant. 15 | # 16 | if [ ! -d "${ant_folder}" ]; then 17 | echo "Downloading Ant $ant_version..." 18 | curl --silent --show-error --fail --remote-name "https://archive.apache.org/dist/ant/binaries/${ant_archive}" 19 | tar --extract -z --exclude "${ant_folder}/manual" --file "${ant_archive}" 20 | fi 21 | 22 | # 23 | # Load and store junit-platform-console-standalone jar into ${ANT_HOME}/lib. 24 | # 25 | if [ ! -f "${standalone_jar}" ]; then 26 | echo "Downloading junit-platform-console-standalone $junit_version..." 27 | curl --silent --show-error --fail "https://repo1.maven.org/maven2/org/junit/platform/junit-platform-console-standalone/${junit_version}/junit-platform-console-standalone-${junit_version}.jar" \ 28 | --output "${standalone_jar}" 29 | fi 30 | 31 | # 32 | # Finally, let Ant do its work... 33 | # 34 | ANT_HOME=${ant_folder} "./${ant_folder}/bin/ant" "$@" 35 | -------------------------------------------------------------------------------- /junit-jupiter-starter-maven-kotlin/src/test/kotlin/com/example/project/CalculatorTests.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2025 the original author or authors. 3 | * 4 | * All rights reserved. This program and the accompanying materials are 5 | * made available under the terms of the Eclipse Public License v2.0 which 6 | * accompanies this distribution and is available at 7 | * 8 | * https://www.eclipse.org/legal/epl-v20.html 9 | */ 10 | 11 | package com.example.project 12 | 13 | import org.junit.jupiter.api.Assertions.assertEquals 14 | 15 | import org.junit.jupiter.api.Test 16 | import org.junit.jupiter.params.ParameterizedTest 17 | import org.junit.jupiter.params.provider.CsvSource 18 | 19 | internal class CalculatorTests { 20 | 21 | @Test 22 | internal fun `1 + 1 = 2`() = assertEquals(2, Calculator().add(1, 1), "1 + 1 should equal 2") 23 | 24 | @ParameterizedTest(name = "{0} + {1} = {2}") 25 | @CsvSource( 26 | "0 , 1, 1", 27 | "1 , 2, 3", 28 | "49, 51, 100", 29 | "1 , 100, 101" 30 | ) 31 | internal fun add(first: Int, second: Int, expectedResult: Int) { 32 | val calculator = Calculator() 33 | assertEquals(expectedResult, calculator.add(first, second)) { 34 | "$first + $second should equal $expectedResult" 35 | } 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /junit-multiple-engines/README.md: -------------------------------------------------------------------------------- 1 | # junit-multiple-engines 2 | 3 | The `junit-multiple-engines` example demonstrates how to set up a Gradle project 4 | using the JUnit Platform with various [TestEngine][guide-custom-engine] implementations. 5 | 6 | ## Provided by junit.org 7 | 8 | * [JUnit Jupiter](https://docs.junit.org/current/user-guide) 9 | * [JUnit Vintage](https://docs.junit.org/current/user-guide) 10 | * [JUnit Platform Suite Engine](https://docs.junit.org/current/user-guide/#junit-platform-suite-engine) 11 | * [TestNG](https://github.com/junit-team/testng-engine) 12 | 13 | ## 3rd-party test engines 14 | 15 | * [JQwik Test Engine](https://jqwik.net) 16 | * [KotlinTest](https://github.com/kotlintest/kotlintest) 17 | * [MAINRUNNER](https://github.com/sormuras/mainrunner) 18 | * [Spek](https://spekframework.org) 19 | * [Spock](https://spockframework.org/) 20 | 21 | ## More engines 22 | 23 | See https://github.com/junit-team/junit-framework/wiki/Third-party-Extensions#junit-platform-test-engines 24 | for even more test engine implementations and feel free to add minimal working examples of other 25 | engines to this project and the wiki page. 26 | 27 | [guide-custom-engine]: https://docs.junit.org/current/user-guide/#launcher-api-engines-custom "Plugging in Your Own Test Engine" 28 | -------------------------------------------------------------------------------- /junit-jupiter-extensions/src/main/java/com/example/cartesian/CartesianProductResolver.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2025 the original author or authors. 3 | * 4 | * All rights reserved. This program and the accompanying materials are 5 | * made available under the terms of the Eclipse Public License v2.0 which 6 | * accompanies this distribution and is available at 7 | * 8 | * https://www.eclipse.org/legal/epl-v20.html 9 | */ 10 | 11 | package com.example.cartesian; 12 | 13 | import java.util.List; 14 | import org.junit.jupiter.api.extension.ExtensionContext; 15 | import org.junit.jupiter.api.extension.ParameterContext; 16 | import org.junit.jupiter.api.extension.ParameterResolver; 17 | 18 | class CartesianProductResolver implements ParameterResolver { 19 | 20 | private final List parameters; 21 | 22 | CartesianProductResolver(List parameters) { 23 | this.parameters = parameters; 24 | } 25 | 26 | @Override 27 | public boolean supportsParameter(ParameterContext parameterContext, ExtensionContext extensionContext) { 28 | return parameterContext.getIndex() < parameters.size(); 29 | } 30 | 31 | @Override 32 | public Object resolveParameter(ParameterContext parameterContext, ExtensionContext extensionContext) { 33 | return parameters.get(parameterContext.getIndex()); 34 | } 35 | 36 | } 37 | -------------------------------------------------------------------------------- /.github/workflows/build-all-examples.yml: -------------------------------------------------------------------------------- 1 | name: Build all examples 2 | on: 3 | push: 4 | branches: 5 | - main 6 | - 'r5.*' 7 | - 'r6.*' 8 | - 'releases/**' 9 | pull_request: 10 | branches: 11 | - '*' 12 | 13 | permissions: 14 | contents: read 15 | 16 | jobs: 17 | linux: 18 | name: Linux 19 | runs-on: ubuntu-latest 20 | steps: 21 | - uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1 22 | - name: 'Set up JDK 25' 23 | uses: actions/setup-java@f2beeb24e141e01a676f977032f5a29d81c9e27e # v5.1.0 24 | with: 25 | java-version: 25 26 | distribution: liberica 27 | - uses: sbt/setup-sbt@3e125ece5c3e5248e18da9ed8d2cce3d335ec8dd # v1.1.14 28 | - name: 'Build all examples' 29 | run: java src/Builder.java 30 | - name: 'Check automation for updating versions' 31 | run: java src/Updater.java 42 32 | if: github.repository == 'junit-team/junit-examples' && github.ref == 'refs/heads/main' 33 | - name: 'Check automation for injecting a staging repository' 34 | run: java src/StagingRepoInjector.java https://example.org/service/local/repositories/orgjunit-1234/content 35 | if: github.repository == 'junit-team/junit-examples' && github.ref == 'refs/heads/main' 36 | -------------------------------------------------------------------------------- /junit-jupiter-starter-gradle-groovy/src/test/groovy/com/example/project/CalculatorTests.groovy: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2025 the original author or authors. 3 | * 4 | * All rights reserved. This program and the accompanying materials are 5 | * made available under the terms of the Eclipse Public License v2.0 which 6 | * accompanies this distribution and is available at 7 | * 8 | * https://www.eclipse.org/legal/epl-v20.html 9 | */ 10 | 11 | package com.example.project 12 | 13 | import static org.junit.jupiter.api.Assertions.assertEquals 14 | 15 | import org.junit.jupiter.api.Test 16 | import org.junit.jupiter.params.ParameterizedTest 17 | import org.junit.jupiter.params.provider.CsvSource 18 | 19 | class CalculatorTests { 20 | 21 | @Test 22 | void "1 + 1 = 2"() { 23 | def calculator = new Calculator() 24 | assertEquals(2, calculator.add(1, 1), "1 + 1 should equal 2") 25 | } 26 | 27 | @ParameterizedTest(name = "{0} + {1} = {2}") 28 | @CsvSource([ 29 | "0, 1, 1", 30 | "1, 2, 3", 31 | "49, 51, 100", 32 | "1, 100, 101" 33 | ]) 34 | void add(int first, int second, int expectedResult) { 35 | def calculator = new Calculator() 36 | assertEquals(expectedResult, calculator.add(first, second)) { 37 | first + " + " + second + " should equal " + expectedResult 38 | } 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /junit-jupiter-starter-sbt/src/test/scala/com/example/project/CalculatorTests.scala: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2025 the original author or authors. 3 | * 4 | * All rights reserved. This program and the accompanying materials are 5 | * made available under the terms of the Eclipse Public License v2.0 which 6 | * accompanies this distribution and is available at 7 | * 8 | * https://www.eclipse.org/legal/epl-v20.html 9 | */ 10 | 11 | package com.example.project 12 | 13 | import org.junit.jupiter.api.Assertions.assertEquals 14 | import org.junit.jupiter.api.DisplayName 15 | import org.junit.jupiter.api.Test 16 | import org.junit.jupiter.params.ParameterizedTest 17 | import org.junit.jupiter.params.provider.CsvSource 18 | 19 | class CalculatorTests { 20 | 21 | @Test 22 | @DisplayName("1 + 1 = 2") 23 | def addsTwoNumbers(): Unit = 24 | assertEquals(2, Calculator.add(1, 1), "1 + 1 should equal 2") 25 | 26 | @ParameterizedTest(name = "{0} + {1} = {2}", quoteTextArguments = false) 27 | @CsvSource(textBlock = 28 | """0, 1, 1 29 | 1, 2, 3 30 | 49, 51, 100 31 | 1, 100, 101""") 32 | def add(first: Int, second: Int, expectedResult: Int): Unit = 33 | assertEquals(expectedResult, Calculator.add(first, second), () => s"$first + $second should equal $expectedResult") 34 | 35 | } 36 | -------------------------------------------------------------------------------- /junit-jupiter-starter-maven/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | com.example 7 | junit-jupiter-starter-maven 8 | 1.0-SNAPSHOT 9 | 10 | 11 | UTF-8 12 | 17 13 | 14 | 15 | 16 | 17 | 18 | org.junit 19 | junit-bom 20 | 6.0.1 21 | pom 22 | import 23 | 24 | 25 | 26 | 27 | 28 | 29 | org.junit.jupiter 30 | junit-jupiter 31 | test 32 | 33 | 34 | 35 | 36 | 37 | 38 | maven-surefire-plugin 39 | 3.5.4 40 | 41 | 42 | 43 | 44 | 45 | -------------------------------------------------------------------------------- /junit-jupiter-extensions/src/main/java/com/example/cartesian/CartesianProductTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2025 the original author or authors. 3 | * 4 | * All rights reserved. This program and the accompanying materials are 5 | * made available under the terms of the Eclipse Public License v2.0 which 6 | * accompanies this distribution and is available at 7 | * 8 | * https://www.eclipse.org/legal/epl-v20.html 9 | */ 10 | 11 | package com.example.cartesian; 12 | 13 | import java.lang.annotation.ElementType; 14 | import java.lang.annotation.Retention; 15 | import java.lang.annotation.RetentionPolicy; 16 | import java.lang.annotation.Target; 17 | import java.util.ArrayList; 18 | import java.util.Arrays; 19 | import java.util.List; 20 | import org.junit.jupiter.api.TestTemplate; 21 | import org.junit.jupiter.api.extension.ExtendWith; 22 | 23 | @TestTemplate 24 | @ExtendWith(CartesianProductProvider.class) 25 | @Target(ElementType.METHOD) 26 | @Retention(RetentionPolicy.RUNTIME) 27 | public @interface CartesianProductTest { 28 | 29 | String[] value() default {}; 30 | 31 | class Sets { 32 | 33 | private final List> sets = new ArrayList<>(); 34 | 35 | public Sets add(Object... entries) { 36 | sets.add(new ArrayList<>(Arrays.asList(entries))); 37 | return this; 38 | } 39 | 40 | List> getSets() { 41 | return sets; 42 | } 43 | } 44 | 45 | } 46 | -------------------------------------------------------------------------------- /junit-modular-world/src/test/com.example.tool/com/example/tool/internal/MathHelperTests.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2025 the original author or authors. 3 | * 4 | * All rights reserved. This program and the accompanying materials are 5 | * made available under the terms of the Eclipse Public License v2.0 which 6 | * accompanies this distribution and is available at 7 | * 8 | * https://www.eclipse.org/legal/epl-v20.html 9 | */ 10 | 11 | package com.example.tool.internal; 12 | 13 | import org.junit.jupiter.api.*; 14 | import org.junit.jupiter.params.*; 15 | import org.junit.jupiter.params.provider.*; 16 | 17 | @DisplayName("com.example.tool/com.example.tool.internal.MathHelperTests") 18 | class MathHelperTests { 19 | 20 | @Test 21 | void pow() { 22 | Assertions.assertEquals(8, MathHelper.pow(2, 3), "2 ^ 3 should equal 8"); 23 | } 24 | 25 | @ParameterizedTest(name = "{0} ^ {1} = {2}") 26 | @CsvSource({ 27 | "0, 0, 1", 28 | "1, 0, 1", 29 | "2, 2, 4", 30 | "2, 3, 8", 31 | "2, 8, 256", 32 | "2, 9, 512" 33 | }) 34 | void pow(int first, int second, int expectedResult) { 35 | Assertions.assertEquals(expectedResult, MathHelper.pow(first, second), 36 | () -> first + " ^ " + second + " should equal " + expectedResult); 37 | } 38 | 39 | } 40 | -------------------------------------------------------------------------------- /junit-jupiter-starter-bazel/src/test/java/com/example/project/CalculatorTests.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2025 the original author or authors. 3 | * 4 | * All rights reserved. This program and the accompanying materials are 5 | * made available under the terms of the Eclipse Public License v2.0 which 6 | * accompanies this distribution and is available at 7 | * 8 | * https://www.eclipse.org/legal/epl-v20.html 9 | */ 10 | 11 | package com.example.project; 12 | 13 | import static org.junit.jupiter.api.Assertions.assertEquals; 14 | 15 | import org.junit.jupiter.api.DisplayName; 16 | import org.junit.jupiter.api.Test; 17 | import org.junit.jupiter.params.ParameterizedTest; 18 | import org.junit.jupiter.params.provider.CsvSource; 19 | 20 | class CalculatorTests { 21 | 22 | @Test 23 | @DisplayName("1 + 1 = 2") 24 | void addsTwoNumbers() { 25 | Calculator calculator = new Calculator(); 26 | assertEquals(2, calculator.add(1, 1), "1 + 1 should equal 2"); 27 | } 28 | 29 | @ParameterizedTest(name = "{0} + {1} = {2}", quoteTextArguments = false) 30 | @CsvSource(textBlock = """ 31 | 0, 1, 1 32 | 1, 2, 3 33 | 49, 51, 100 34 | 1, 100, 101 35 | """) 36 | void add(int first, int second, int expectedResult) { 37 | Calculator calculator = new Calculator(); 38 | assertEquals(expectedResult, calculator.add(first, second), 39 | () -> first + " + " + second + " should equal " + expectedResult); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /junit-jupiter-starter-gradle/src/test/java/com/example/project/CalculatorTests.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2025 the original author or authors. 3 | * 4 | * All rights reserved. This program and the accompanying materials are 5 | * made available under the terms of the Eclipse Public License v2.0 which 6 | * accompanies this distribution and is available at 7 | * 8 | * https://www.eclipse.org/legal/epl-v20.html 9 | */ 10 | 11 | package com.example.project; 12 | 13 | import static org.junit.jupiter.api.Assertions.assertEquals; 14 | 15 | import org.junit.jupiter.api.DisplayName; 16 | import org.junit.jupiter.api.Test; 17 | import org.junit.jupiter.params.ParameterizedTest; 18 | import org.junit.jupiter.params.provider.CsvSource; 19 | 20 | class CalculatorTests { 21 | 22 | @Test 23 | @DisplayName("1 + 1 = 2") 24 | void addsTwoNumbers() { 25 | Calculator calculator = new Calculator(); 26 | assertEquals(2, calculator.add(1, 1), "1 + 1 should equal 2"); 27 | } 28 | 29 | @ParameterizedTest(name = "{0} + {1} = {2}", quoteTextArguments = false) 30 | @CsvSource(textBlock = """ 31 | 0, 1, 1 32 | 1, 2, 3 33 | 49, 51, 100 34 | 1, 100, 101 35 | """) 36 | void add(int first, int second, int expectedResult) { 37 | Calculator calculator = new Calculator(); 38 | assertEquals(expectedResult, calculator.add(first, second), 39 | () -> first + " + " + second + " should equal " + expectedResult); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /junit-jupiter-starter-maven/src/test/java/com/example/project/CalculatorTests.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2025 the original author or authors. 3 | * 4 | * All rights reserved. This program and the accompanying materials are 5 | * made available under the terms of the Eclipse Public License v2.0 which 6 | * accompanies this distribution and is available at 7 | * 8 | * https://www.eclipse.org/legal/epl-v20.html 9 | */ 10 | 11 | package com.example.project; 12 | 13 | import static org.junit.jupiter.api.Assertions.assertEquals; 14 | 15 | import org.junit.jupiter.api.DisplayName; 16 | import org.junit.jupiter.api.Test; 17 | import org.junit.jupiter.params.ParameterizedTest; 18 | import org.junit.jupiter.params.provider.CsvSource; 19 | 20 | class CalculatorTests { 21 | 22 | @Test 23 | @DisplayName("1 + 1 = 2") 24 | void addsTwoNumbers() { 25 | Calculator calculator = new Calculator(); 26 | assertEquals(2, calculator.add(1, 1), "1 + 1 should equal 2"); 27 | } 28 | 29 | @ParameterizedTest(name = "{0} + {1} = {2}", quoteTextArguments = false) 30 | @CsvSource(textBlock = """ 31 | 0, 1, 1 32 | 1, 2, 3 33 | 49, 51, 100 34 | 1, 100, 101 35 | """) 36 | void add(int first, int second, int expectedResult) { 37 | Calculator calculator = new Calculator(); 38 | assertEquals(expectedResult, calculator.add(first, second), 39 | () -> first + " + " + second + " should equal " + expectedResult); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /junit-jupiter-starter-ant/src/test/java/com/example/project/CalculatorTests.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2025 the original author or authors. 3 | * 4 | * All rights reserved. This program and the accompanying materials are 5 | * made available under the terms of the Eclipse Public License v2.0 which 6 | * accompanies this distribution and is available at 7 | * 8 | * https://www.eclipse.org/legal/epl-v20.html 9 | */ 10 | 11 | package com.example.project; 12 | 13 | import static org.junit.jupiter.api.Assertions.assertEquals; 14 | 15 | import org.junit.jupiter.api.DisplayName; 16 | import org.junit.jupiter.api.Test; 17 | import org.junit.jupiter.params.ParameterizedTest; 18 | import org.junit.jupiter.params.provider.CsvSource; 19 | 20 | class CalculatorTests { 21 | 22 | @Test 23 | @DisplayName("1 + 1 = 2") 24 | void addsTwoNumbers() { 25 | Calculator calculator = new Calculator(); 26 | assertEquals(2, calculator.add(1, 1), "1 + 1 should equal 2"); 27 | } 28 | 29 | @ParameterizedTest(name = "{0} + {1} = {2}", quoteTextArguments = false) 30 | @CsvSource(textBlock = """ 31 | 0, 1, 1 32 | 1, 2, 3 33 | 49, 51, 100 34 | 1, 100, 101 35 | """) 36 | void add(int first, int second, int expectedResult) { 37 | Calculator calculator = new Calculator(); 38 | assertEquals(expectedResult, calculator.add(first, second), 39 | () -> first + " + " + second + " should equal " + expectedResult); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /junit-jupiter-extensions/src/test/java/com/example/cartesian/CartesianProductTests.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2025 the original author or authors. 3 | * 4 | * All rights reserved. This program and the accompanying materials are 5 | * made available under the terms of the Eclipse Public License v2.0 which 6 | * accompanies this distribution and is available at 7 | * 8 | * https://www.eclipse.org/legal/epl-v20.html 9 | */ 10 | 11 | package com.example.cartesian; 12 | 13 | import static org.junit.jupiter.api.Assertions.assertTrue; 14 | 15 | import java.util.concurrent.TimeUnit; 16 | import org.junit.jupiter.api.DisplayName; 17 | import org.junit.jupiter.api.TestInfo; 18 | 19 | class CartesianProductTests { 20 | 21 | @CartesianProductTest({"0", "1"}) 22 | void threeBits(String a, String b, String c) { 23 | int value = Integer.parseUnsignedInt(a + b + c, 2); 24 | assertTrue((0b000 <= value) && (value <= 0b111)); 25 | } 26 | 27 | @CartesianProductTest 28 | @DisplayName("S ⨯ T ⨯ U") 29 | void nFold(String string, Class type, TimeUnit unit, TestInfo info) { 30 | assertTrue(string.endsWith("a")); 31 | assertTrue(type.isInterface()); 32 | assertTrue(unit.name().endsWith("S")); 33 | assertTrue(info.getTags().isEmpty()); 34 | } 35 | 36 | static CartesianProductTest.Sets nFold() { 37 | return new CartesianProductTest.Sets() 38 | .add("Alpha", "Omega") 39 | .add(Runnable.class, Comparable.class, TestInfo.class) 40 | .add(TimeUnit.DAYS, TimeUnit.HOURS); 41 | } 42 | 43 | } 44 | -------------------------------------------------------------------------------- /.github/workflows/codeql.yml: -------------------------------------------------------------------------------- 1 | name: "CodeQL" 2 | 3 | on: 4 | push: 5 | branches: 6 | - main 7 | - 'r5.*' 8 | - 'r6.*' 9 | - 'releases/**' 10 | schedule: 11 | - cron: '23 2 * * 4' 12 | 13 | permissions: 14 | contents: read 15 | 16 | jobs: 17 | analyze: 18 | name: Analyze (${{ matrix.language }}) 19 | runs-on: 'ubuntu-latest' 20 | permissions: 21 | security-events: write 22 | strategy: 23 | fail-fast: false 24 | matrix: 25 | include: 26 | - language: actions 27 | build-mode: none 28 | - language: java-kotlin 29 | build-mode: manual 30 | steps: 31 | - uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1 32 | - name: 'Set up JDK 25' 33 | uses: actions/setup-java@f2beeb24e141e01a676f977032f5a29d81c9e27e # v5.1.0 34 | with: 35 | java-version: 25 36 | distribution: liberica 37 | - uses: sbt/setup-sbt@3e125ece5c3e5248e18da9ed8d2cce3d335ec8dd # v1.1.14 38 | - name: Initialize CodeQL 39 | uses: github/codeql-action/init@1b168cd39490f61582a9beae412bb7057a6b2c4e # v4.31.8 40 | with: 41 | languages: ${{ matrix.language }} 42 | build-mode: ${{ matrix.build-mode }} 43 | - if: matrix.build-mode == 'manual' 44 | run: java src/Builder.java --target=compile 45 | - name: Perform CodeQL Analysis 46 | uses: github/codeql-action/analyze@1b168cd39490f61582a9beae412bb7057a6b2c4e # v4.31.8 47 | with: 48 | category: "/language:${{matrix.language}}" 49 | -------------------------------------------------------------------------------- /junit-jupiter-starter-gradle-kotlin/src/test/kotlin/com/example/project/CalculatorTests.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2025 the original author or authors. 3 | * 4 | * All rights reserved. This program and the accompanying materials are 5 | * made available under the terms of the Eclipse Public License v2.0 which 6 | * accompanies this distribution and is available at 7 | * 8 | * https://www.eclipse.org/legal/epl-v20.html 9 | */ 10 | 11 | package com.example.project 12 | 13 | import org.junit.jupiter.api.Assertions.assertEquals 14 | 15 | import org.junit.jupiter.api.Test 16 | import org.junit.jupiter.api.assertThrows 17 | import org.junit.jupiter.params.ParameterizedTest 18 | import org.junit.jupiter.params.provider.CsvSource 19 | 20 | class CalculatorTests { 21 | 22 | @Test 23 | fun `1 + 1 = 2`() { 24 | val calculator = Calculator() 25 | assertEquals(2, calculator.add(1, 1), "1 + 1 should equal 2") 26 | } 27 | 28 | @ParameterizedTest(name = "{0} + {1} = {2}") 29 | @CsvSource( 30 | "0, 1, 1", 31 | "1, 2, 3", 32 | "49, 51, 100", 33 | "1, 100, 101" 34 | ) 35 | fun add(first: Int, second: Int, expectedResult: Int) { 36 | val calculator = Calculator() 37 | assertEquals(expectedResult, calculator.add(first, second)) { 38 | "$first + $second should equal $expectedResult" 39 | } 40 | } 41 | 42 | @Test 43 | fun divisionByZeroError() { 44 | val calculator = Calculator() 45 | val exception = assertThrows { 46 | calculator.div(1, 0) 47 | } 48 | assertEquals("Division by Zero", exception.message) 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /junit-modular-world/src/test/extra.modular/extra/modular/ExtraModularTests.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2025 the original author or authors. 3 | * 4 | * All rights reserved. This program and the accompanying materials are 5 | * made available under the terms of the Eclipse Public License v2.0 which 6 | * accompanies this distribution and is available at 7 | * 8 | * https://www.eclipse.org/legal/epl-v20.html 9 | */ 10 | 11 | package black.box; 12 | 13 | // import com.example.application.*; "package is declared in module com.example.application, which does not export it" 14 | // import com.example.tool.internal.*; "package is declared in module com.example.tool, which does not export it" 15 | 16 | import com.example.tool.*; 17 | import org.junit.jupiter.api.*; 18 | import org.junit.jupiter.api.condition.*; 19 | 20 | @DisplayName("extra.modular/extra.modular.ExtraModularTests") 21 | class ExtraModularTests { 22 | 23 | @Test 24 | void packageName() { 25 | Assertions.assertEquals("com.example.tool", Calculator.class.getPackage().getName()); 26 | } 27 | 28 | @Test 29 | // @EnabledIf("com.example.tool.Calculator.class.getModule().isNamed()") 30 | void moduleName() { 31 | Assumptions.assumeTrue(Calculator.class.getModule().isNamed(), "Calculator resides in a named module"); 32 | Assertions.assertEquals("com.example.tool", Calculator.class.getModule().getName()); 33 | } 34 | 35 | @RepeatedTest(value = 5, name = "{currentRepetition} + {totalRepetitions}") 36 | void add(RepetitionInfo info) { 37 | int a = info.getCurrentRepetition(); 38 | int b = info.getTotalRepetitions(); 39 | int actual = new Calculator().add(a, b); 40 | int expected = a + b; 41 | Assertions.assertEquals(expected, actual); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /junit-migration-maven/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | com.example 7 | junit-migration-maven 8 | 1.0-SNAPSHOT 9 | 10 | 11 | UTF-8 12 | 17 13 | 4.13.2 14 | 15 | 16 | 17 | 18 | 19 | org.junit 20 | junit-bom 21 | 6.0.1 22 | pom 23 | import 24 | 25 | 26 | 27 | 28 | 29 | 30 | org.junit.jupiter 31 | junit-jupiter-api 32 | test 33 | 34 | 35 | junit 36 | junit 37 | ${junit.version} 38 | test 39 | 40 | 41 | org.junit.jupiter 42 | junit-jupiter-engine 43 | test 44 | 45 | 46 | org.junit.vintage 47 | junit-vintage-engine 48 | test 49 | 50 | 51 | 52 | 53 | 54 | 55 | maven-surefire-plugin 56 | 3.5.4 57 | 58 | 59 | slow 60 | 61 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | -------------------------------------------------------------------------------- /junit-jupiter-starter-maven-kotlin/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | 7 | com.example 8 | junit-jupiter-starter-maven-kotlin 9 | 1.0-SNAPSHOT 10 | 11 | 12 | UTF-8 13 | 2.2.21 14 | 17 15 | ${maven.compiler.release} 16 | 17 | 18 | 19 | 20 | 21 | org.junit 22 | junit-bom 23 | 6.0.1 24 | pom 25 | import 26 | 27 | 28 | 29 | 30 | 31 | 32 | org.jetbrains.kotlin 33 | kotlin-stdlib 34 | ${kotlin.version} 35 | 36 | 37 | 38 | org.junit.jupiter 39 | junit-jupiter 40 | test 41 | 42 | 43 | org.jetbrains.kotlin 44 | kotlin-test-junit5 45 | ${kotlin.version} 46 | test 47 | 48 | 49 | 50 | 51 | ${project.basedir}/src/main/kotlin 52 | ${project.basedir}/src/test/kotlin 53 | 54 | 55 | 56 | org.jetbrains.kotlin 57 | kotlin-maven-plugin 58 | ${kotlin.version} 59 | 60 | 61 | compile 62 | compile 63 | 64 | compile 65 | 66 | 67 | 68 | test-compile 69 | test-compile 70 | 71 | test-compile 72 | 73 | 74 | 75 | 76 | 77 | 78 | org.apache.maven.plugins 79 | maven-surefire-plugin 80 | 3.5.4 81 | 82 | 83 | 84 | 85 | 86 | -------------------------------------------------------------------------------- /junit-jupiter-starter-ant/build.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | -------------------------------------------------------------------------------- /junit-jupiter-extensions/src/main/java/com/example/random/RandomParametersExtension.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2025 the original author or authors. 3 | * 4 | * All rights reserved. This program and the accompanying materials are 5 | * made available under the terms of the Eclipse Public License v2.0 which 6 | * accompanies this distribution and is available at 7 | * 8 | * https://www.eclipse.org/legal/epl-v20.html 9 | */ 10 | 11 | package com.example.random; 12 | 13 | import java.lang.annotation.ElementType; 14 | import java.lang.annotation.Retention; 15 | import java.lang.annotation.RetentionPolicy; 16 | import java.lang.annotation.Target; 17 | import java.lang.reflect.Parameter; 18 | 19 | import org.junit.jupiter.api.extension.ExtensionContext; 20 | import org.junit.jupiter.api.extension.ExtensionContext.Namespace; 21 | import org.junit.jupiter.api.extension.ParameterContext; 22 | import org.junit.jupiter.api.extension.ParameterResolutionException; 23 | import org.junit.jupiter.api.extension.ParameterResolver; 24 | 25 | /** 26 | * {@code RandomParametersExtension} showcases the {@link ParameterResolver} 27 | * extension API of JUnit 5 by providing injection support for random values at the 28 | * method parameter level. 29 | * 30 | *

For real world use cases for this and other extension points, check out 31 | * the extensions provided by the Spring and Mockito projects among others. 32 | * 33 | *

Please refer to the 34 | * 35 | * Third-party Extensions wiki page for additional references. 36 | * 37 | * @since 5.2 38 | */ 39 | public class RandomParametersExtension implements ParameterResolver { 40 | 41 | @Retention(RetentionPolicy.RUNTIME) 42 | @Target(ElementType.PARAMETER) 43 | public @interface Random { 44 | } 45 | 46 | @Override 47 | public boolean supportsParameter(ParameterContext parameterContext, ExtensionContext extensionContext) { 48 | return parameterContext.isAnnotated(Random.class); 49 | } 50 | 51 | @Override 52 | public Object resolveParameter(ParameterContext parameterContext, ExtensionContext extensionContext) { 53 | return getRandomValue(parameterContext.getParameter(), extensionContext); 54 | } 55 | 56 | private Object getRandomValue(Parameter parameter, ExtensionContext extensionContext) { 57 | Class type = parameter.getType(); 58 | java.util.Random random = extensionContext.getRoot().getStore(Namespace.GLOBAL)// 59 | .getOrComputeIfAbsent(java.util.Random.class); 60 | if (int.class.equals(type)) { 61 | return random.nextInt(); 62 | } 63 | if (double.class.equals(type)) { 64 | return random.nextDouble(); 65 | } 66 | throw new ParameterResolutionException("No random generator implemented for " + type); 67 | } 68 | 69 | } 70 | -------------------------------------------------------------------------------- /junit-modular-world/src/main/ice.cream/ice/cream/Machine.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2025 the original author or authors. 3 | * 4 | * All rights reserved. This program and the accompanying materials are 5 | * made available under the terms of the Eclipse Public License v2.0 which 6 | * accompanies this distribution and is available at 7 | * 8 | * https://www.eclipse.org/legal/epl-v20.html 9 | */ 10 | 11 | package ice.cream; 12 | 13 | import org.junit.platform.engine.ConfigurationParameters; 14 | import org.junit.platform.engine.EngineDiscoveryRequest; 15 | import org.junit.platform.engine.EngineExecutionListener; 16 | import org.junit.platform.engine.ExecutionRequest; 17 | import org.junit.platform.engine.TestDescriptor; 18 | import org.junit.platform.engine.TestEngine; 19 | import org.junit.platform.engine.TestExecutionResult; 20 | import org.junit.platform.engine.UniqueId; 21 | import org.junit.platform.engine.support.descriptor.EngineDescriptor; 22 | 23 | /** 24 | * Simple test engine implementation. 25 | */ 26 | public class Machine implements TestEngine { 27 | 28 | @Override 29 | public String getId() { 30 | return "ice-cream-machine"; 31 | } 32 | 33 | /** 34 | * Build caption used as the engine's display name. 35 | */ 36 | String getCaption() { 37 | StringBuilder builder = new StringBuilder(); 38 | builder.append("Ice Cream Machine"); 39 | if (getVersion().isPresent()) { 40 | builder.append(" ").append(getVersion().get()); 41 | } 42 | if (getArtifactId().isPresent()) { 43 | builder.append(" (").append(getArtifactId().get()).append(")"); 44 | } 45 | return builder.toString(); 46 | } 47 | 48 | /** 49 | * Extract amount of scoops to generate. 50 | */ 51 | int getScoops(EngineDiscoveryRequest discoveryRequest, int defaultScoops) { 52 | ConfigurationParameters parameters = discoveryRequest.getConfigurationParameters(); 53 | String scoops = parameters.get("scoops").orElse(Integer.toString(defaultScoops)); 54 | return Integer.valueOf(scoops); 55 | } 56 | 57 | @Override 58 | public TestDescriptor discover(EngineDiscoveryRequest discoveryRequest, UniqueId uniqueId) { 59 | TestDescriptor engine = new EngineDescriptor(uniqueId, getCaption()); 60 | for (int i = 0; i < getScoops(discoveryRequest, 5); i++) { 61 | engine.addChild(new Scoop(engine.getUniqueId(), i, Flavor.random())); 62 | } 63 | return engine; 64 | } 65 | 66 | @Override 67 | public void execute(ExecutionRequest request) { 68 | TestDescriptor engine = request.getRootTestDescriptor(); 69 | EngineExecutionListener listener = request.getEngineExecutionListener(); 70 | listener.executionStarted(engine); 71 | for (TestDescriptor child : engine.getChildren()) { 72 | listener.executionStarted(child); 73 | listener.executionFinished(child, TestExecutionResult.successful()); 74 | } 75 | listener.executionFinished(engine, TestExecutionResult.successful()); 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /junit-jupiter-extensions/gradlew.bat: -------------------------------------------------------------------------------- 1 | @rem 2 | @rem Copyright 2015 the original author or authors. 3 | @rem 4 | @rem Licensed under the Apache License, Version 2.0 (the "License"); 5 | @rem you may not use this file except in compliance with the License. 6 | @rem You may obtain a copy of the License at 7 | @rem 8 | @rem https://www.apache.org/licenses/LICENSE-2.0 9 | @rem 10 | @rem Unless required by applicable law or agreed to in writing, software 11 | @rem distributed under the License is distributed on an "AS IS" BASIS, 12 | @rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | @rem See the License for the specific language governing permissions and 14 | @rem limitations under the License. 15 | @rem 16 | @rem SPDX-License-Identifier: Apache-2.0 17 | @rem 18 | 19 | @if "%DEBUG%"=="" @echo off 20 | @rem ########################################################################## 21 | @rem 22 | @rem Gradle startup script for Windows 23 | @rem 24 | @rem ########################################################################## 25 | 26 | @rem Set local scope for the variables with windows NT shell 27 | if "%OS%"=="Windows_NT" setlocal 28 | 29 | set DIRNAME=%~dp0 30 | if "%DIRNAME%"=="" set DIRNAME=. 31 | @rem This is normally unused 32 | set APP_BASE_NAME=%~n0 33 | set APP_HOME=%DIRNAME% 34 | 35 | @rem Resolve any "." and ".." in APP_HOME to make it shorter. 36 | for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi 37 | 38 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 39 | set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" 40 | 41 | @rem Find java.exe 42 | if defined JAVA_HOME goto findJavaFromJavaHome 43 | 44 | set JAVA_EXE=java.exe 45 | %JAVA_EXE% -version >NUL 2>&1 46 | if %ERRORLEVEL% equ 0 goto execute 47 | 48 | echo. 1>&2 49 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2 50 | echo. 1>&2 51 | echo Please set the JAVA_HOME variable in your environment to match the 1>&2 52 | echo location of your Java installation. 1>&2 53 | 54 | goto fail 55 | 56 | :findJavaFromJavaHome 57 | set JAVA_HOME=%JAVA_HOME:"=% 58 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 59 | 60 | if exist "%JAVA_EXE%" goto execute 61 | 62 | echo. 1>&2 63 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 1>&2 64 | echo. 1>&2 65 | echo Please set the JAVA_HOME variable in your environment to match the 1>&2 66 | echo location of your Java installation. 1>&2 67 | 68 | goto fail 69 | 70 | :execute 71 | @rem Setup the command line 72 | 73 | 74 | 75 | @rem Execute Gradle 76 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -jar "%APP_HOME%\gradle\wrapper\gradle-wrapper.jar" %* 77 | 78 | :end 79 | @rem End local scope for the variables with windows NT shell 80 | if %ERRORLEVEL% equ 0 goto mainEnd 81 | 82 | :fail 83 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 84 | rem the _cmd.exe /c_ return code! 85 | set EXIT_CODE=%ERRORLEVEL% 86 | if %EXIT_CODE% equ 0 set EXIT_CODE=1 87 | if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE% 88 | exit /b %EXIT_CODE% 89 | 90 | :mainEnd 91 | if "%OS%"=="Windows_NT" endlocal 92 | 93 | :omega 94 | -------------------------------------------------------------------------------- /junit-migration-gradle/gradlew.bat: -------------------------------------------------------------------------------- 1 | @rem 2 | @rem Copyright 2015 the original author or authors. 3 | @rem 4 | @rem Licensed under the Apache License, Version 2.0 (the "License"); 5 | @rem you may not use this file except in compliance with the License. 6 | @rem You may obtain a copy of the License at 7 | @rem 8 | @rem https://www.apache.org/licenses/LICENSE-2.0 9 | @rem 10 | @rem Unless required by applicable law or agreed to in writing, software 11 | @rem distributed under the License is distributed on an "AS IS" BASIS, 12 | @rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | @rem See the License for the specific language governing permissions and 14 | @rem limitations under the License. 15 | @rem 16 | @rem SPDX-License-Identifier: Apache-2.0 17 | @rem 18 | 19 | @if "%DEBUG%"=="" @echo off 20 | @rem ########################################################################## 21 | @rem 22 | @rem Gradle startup script for Windows 23 | @rem 24 | @rem ########################################################################## 25 | 26 | @rem Set local scope for the variables with windows NT shell 27 | if "%OS%"=="Windows_NT" setlocal 28 | 29 | set DIRNAME=%~dp0 30 | if "%DIRNAME%"=="" set DIRNAME=. 31 | @rem This is normally unused 32 | set APP_BASE_NAME=%~n0 33 | set APP_HOME=%DIRNAME% 34 | 35 | @rem Resolve any "." and ".." in APP_HOME to make it shorter. 36 | for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi 37 | 38 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 39 | set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" 40 | 41 | @rem Find java.exe 42 | if defined JAVA_HOME goto findJavaFromJavaHome 43 | 44 | set JAVA_EXE=java.exe 45 | %JAVA_EXE% -version >NUL 2>&1 46 | if %ERRORLEVEL% equ 0 goto execute 47 | 48 | echo. 1>&2 49 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2 50 | echo. 1>&2 51 | echo Please set the JAVA_HOME variable in your environment to match the 1>&2 52 | echo location of your Java installation. 1>&2 53 | 54 | goto fail 55 | 56 | :findJavaFromJavaHome 57 | set JAVA_HOME=%JAVA_HOME:"=% 58 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 59 | 60 | if exist "%JAVA_EXE%" goto execute 61 | 62 | echo. 1>&2 63 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 1>&2 64 | echo. 1>&2 65 | echo Please set the JAVA_HOME variable in your environment to match the 1>&2 66 | echo location of your Java installation. 1>&2 67 | 68 | goto fail 69 | 70 | :execute 71 | @rem Setup the command line 72 | 73 | 74 | 75 | @rem Execute Gradle 76 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -jar "%APP_HOME%\gradle\wrapper\gradle-wrapper.jar" %* 77 | 78 | :end 79 | @rem End local scope for the variables with windows NT shell 80 | if %ERRORLEVEL% equ 0 goto mainEnd 81 | 82 | :fail 83 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 84 | rem the _cmd.exe /c_ return code! 85 | set EXIT_CODE=%ERRORLEVEL% 86 | if %EXIT_CODE% equ 0 set EXIT_CODE=1 87 | if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE% 88 | exit /b %EXIT_CODE% 89 | 90 | :mainEnd 91 | if "%OS%"=="Windows_NT" endlocal 92 | 93 | :omega 94 | -------------------------------------------------------------------------------- /junit-multiple-engines/gradlew.bat: -------------------------------------------------------------------------------- 1 | @rem 2 | @rem Copyright 2015 the original author or authors. 3 | @rem 4 | @rem Licensed under the Apache License, Version 2.0 (the "License"); 5 | @rem you may not use this file except in compliance with the License. 6 | @rem You may obtain a copy of the License at 7 | @rem 8 | @rem https://www.apache.org/licenses/LICENSE-2.0 9 | @rem 10 | @rem Unless required by applicable law or agreed to in writing, software 11 | @rem distributed under the License is distributed on an "AS IS" BASIS, 12 | @rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | @rem See the License for the specific language governing permissions and 14 | @rem limitations under the License. 15 | @rem 16 | @rem SPDX-License-Identifier: Apache-2.0 17 | @rem 18 | 19 | @if "%DEBUG%"=="" @echo off 20 | @rem ########################################################################## 21 | @rem 22 | @rem Gradle startup script for Windows 23 | @rem 24 | @rem ########################################################################## 25 | 26 | @rem Set local scope for the variables with windows NT shell 27 | if "%OS%"=="Windows_NT" setlocal 28 | 29 | set DIRNAME=%~dp0 30 | if "%DIRNAME%"=="" set DIRNAME=. 31 | @rem This is normally unused 32 | set APP_BASE_NAME=%~n0 33 | set APP_HOME=%DIRNAME% 34 | 35 | @rem Resolve any "." and ".." in APP_HOME to make it shorter. 36 | for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi 37 | 38 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 39 | set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" 40 | 41 | @rem Find java.exe 42 | if defined JAVA_HOME goto findJavaFromJavaHome 43 | 44 | set JAVA_EXE=java.exe 45 | %JAVA_EXE% -version >NUL 2>&1 46 | if %ERRORLEVEL% equ 0 goto execute 47 | 48 | echo. 1>&2 49 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2 50 | echo. 1>&2 51 | echo Please set the JAVA_HOME variable in your environment to match the 1>&2 52 | echo location of your Java installation. 1>&2 53 | 54 | goto fail 55 | 56 | :findJavaFromJavaHome 57 | set JAVA_HOME=%JAVA_HOME:"=% 58 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 59 | 60 | if exist "%JAVA_EXE%" goto execute 61 | 62 | echo. 1>&2 63 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 1>&2 64 | echo. 1>&2 65 | echo Please set the JAVA_HOME variable in your environment to match the 1>&2 66 | echo location of your Java installation. 1>&2 67 | 68 | goto fail 69 | 70 | :execute 71 | @rem Setup the command line 72 | 73 | 74 | 75 | @rem Execute Gradle 76 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -jar "%APP_HOME%\gradle\wrapper\gradle-wrapper.jar" %* 77 | 78 | :end 79 | @rem End local scope for the variables with windows NT shell 80 | if %ERRORLEVEL% equ 0 goto mainEnd 81 | 82 | :fail 83 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 84 | rem the _cmd.exe /c_ return code! 85 | set EXIT_CODE=%ERRORLEVEL% 86 | if %EXIT_CODE% equ 0 set EXIT_CODE=1 87 | if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE% 88 | exit /b %EXIT_CODE% 89 | 90 | :mainEnd 91 | if "%OS%"=="Windows_NT" endlocal 92 | 93 | :omega 94 | -------------------------------------------------------------------------------- /junit-jupiter-starter-gradle/gradlew.bat: -------------------------------------------------------------------------------- 1 | @rem 2 | @rem Copyright 2015 the original author or authors. 3 | @rem 4 | @rem Licensed under the Apache License, Version 2.0 (the "License"); 5 | @rem you may not use this file except in compliance with the License. 6 | @rem You may obtain a copy of the License at 7 | @rem 8 | @rem https://www.apache.org/licenses/LICENSE-2.0 9 | @rem 10 | @rem Unless required by applicable law or agreed to in writing, software 11 | @rem distributed under the License is distributed on an "AS IS" BASIS, 12 | @rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | @rem See the License for the specific language governing permissions and 14 | @rem limitations under the License. 15 | @rem 16 | @rem SPDX-License-Identifier: Apache-2.0 17 | @rem 18 | 19 | @if "%DEBUG%"=="" @echo off 20 | @rem ########################################################################## 21 | @rem 22 | @rem Gradle startup script for Windows 23 | @rem 24 | @rem ########################################################################## 25 | 26 | @rem Set local scope for the variables with windows NT shell 27 | if "%OS%"=="Windows_NT" setlocal 28 | 29 | set DIRNAME=%~dp0 30 | if "%DIRNAME%"=="" set DIRNAME=. 31 | @rem This is normally unused 32 | set APP_BASE_NAME=%~n0 33 | set APP_HOME=%DIRNAME% 34 | 35 | @rem Resolve any "." and ".." in APP_HOME to make it shorter. 36 | for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi 37 | 38 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 39 | set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" 40 | 41 | @rem Find java.exe 42 | if defined JAVA_HOME goto findJavaFromJavaHome 43 | 44 | set JAVA_EXE=java.exe 45 | %JAVA_EXE% -version >NUL 2>&1 46 | if %ERRORLEVEL% equ 0 goto execute 47 | 48 | echo. 1>&2 49 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2 50 | echo. 1>&2 51 | echo Please set the JAVA_HOME variable in your environment to match the 1>&2 52 | echo location of your Java installation. 1>&2 53 | 54 | goto fail 55 | 56 | :findJavaFromJavaHome 57 | set JAVA_HOME=%JAVA_HOME:"=% 58 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 59 | 60 | if exist "%JAVA_EXE%" goto execute 61 | 62 | echo. 1>&2 63 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 1>&2 64 | echo. 1>&2 65 | echo Please set the JAVA_HOME variable in your environment to match the 1>&2 66 | echo location of your Java installation. 1>&2 67 | 68 | goto fail 69 | 70 | :execute 71 | @rem Setup the command line 72 | 73 | 74 | 75 | @rem Execute Gradle 76 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -jar "%APP_HOME%\gradle\wrapper\gradle-wrapper.jar" %* 77 | 78 | :end 79 | @rem End local scope for the variables with windows NT shell 80 | if %ERRORLEVEL% equ 0 goto mainEnd 81 | 82 | :fail 83 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 84 | rem the _cmd.exe /c_ return code! 85 | set EXIT_CODE=%ERRORLEVEL% 86 | if %EXIT_CODE% equ 0 set EXIT_CODE=1 87 | if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE% 88 | exit /b %EXIT_CODE% 89 | 90 | :mainEnd 91 | if "%OS%"=="Windows_NT" endlocal 92 | 93 | :omega 94 | -------------------------------------------------------------------------------- /junit-jupiter-starter-gradle-groovy/gradlew.bat: -------------------------------------------------------------------------------- 1 | @rem 2 | @rem Copyright 2015 the original author or authors. 3 | @rem 4 | @rem Licensed under the Apache License, Version 2.0 (the "License"); 5 | @rem you may not use this file except in compliance with the License. 6 | @rem You may obtain a copy of the License at 7 | @rem 8 | @rem https://www.apache.org/licenses/LICENSE-2.0 9 | @rem 10 | @rem Unless required by applicable law or agreed to in writing, software 11 | @rem distributed under the License is distributed on an "AS IS" BASIS, 12 | @rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | @rem See the License for the specific language governing permissions and 14 | @rem limitations under the License. 15 | @rem 16 | @rem SPDX-License-Identifier: Apache-2.0 17 | @rem 18 | 19 | @if "%DEBUG%"=="" @echo off 20 | @rem ########################################################################## 21 | @rem 22 | @rem Gradle startup script for Windows 23 | @rem 24 | @rem ########################################################################## 25 | 26 | @rem Set local scope for the variables with windows NT shell 27 | if "%OS%"=="Windows_NT" setlocal 28 | 29 | set DIRNAME=%~dp0 30 | if "%DIRNAME%"=="" set DIRNAME=. 31 | @rem This is normally unused 32 | set APP_BASE_NAME=%~n0 33 | set APP_HOME=%DIRNAME% 34 | 35 | @rem Resolve any "." and ".." in APP_HOME to make it shorter. 36 | for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi 37 | 38 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 39 | set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" 40 | 41 | @rem Find java.exe 42 | if defined JAVA_HOME goto findJavaFromJavaHome 43 | 44 | set JAVA_EXE=java.exe 45 | %JAVA_EXE% -version >NUL 2>&1 46 | if %ERRORLEVEL% equ 0 goto execute 47 | 48 | echo. 1>&2 49 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2 50 | echo. 1>&2 51 | echo Please set the JAVA_HOME variable in your environment to match the 1>&2 52 | echo location of your Java installation. 1>&2 53 | 54 | goto fail 55 | 56 | :findJavaFromJavaHome 57 | set JAVA_HOME=%JAVA_HOME:"=% 58 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 59 | 60 | if exist "%JAVA_EXE%" goto execute 61 | 62 | echo. 1>&2 63 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 1>&2 64 | echo. 1>&2 65 | echo Please set the JAVA_HOME variable in your environment to match the 1>&2 66 | echo location of your Java installation. 1>&2 67 | 68 | goto fail 69 | 70 | :execute 71 | @rem Setup the command line 72 | 73 | 74 | 75 | @rem Execute Gradle 76 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -jar "%APP_HOME%\gradle\wrapper\gradle-wrapper.jar" %* 77 | 78 | :end 79 | @rem End local scope for the variables with windows NT shell 80 | if %ERRORLEVEL% equ 0 goto mainEnd 81 | 82 | :fail 83 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 84 | rem the _cmd.exe /c_ return code! 85 | set EXIT_CODE=%ERRORLEVEL% 86 | if %EXIT_CODE% equ 0 set EXIT_CODE=1 87 | if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE% 88 | exit /b %EXIT_CODE% 89 | 90 | :mainEnd 91 | if "%OS%"=="Windows_NT" endlocal 92 | 93 | :omega 94 | -------------------------------------------------------------------------------- /junit-jupiter-starter-gradle-kotlin/gradlew.bat: -------------------------------------------------------------------------------- 1 | @rem 2 | @rem Copyright 2015 the original author or authors. 3 | @rem 4 | @rem Licensed under the Apache License, Version 2.0 (the "License"); 5 | @rem you may not use this file except in compliance with the License. 6 | @rem You may obtain a copy of the License at 7 | @rem 8 | @rem https://www.apache.org/licenses/LICENSE-2.0 9 | @rem 10 | @rem Unless required by applicable law or agreed to in writing, software 11 | @rem distributed under the License is distributed on an "AS IS" BASIS, 12 | @rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | @rem See the License for the specific language governing permissions and 14 | @rem limitations under the License. 15 | @rem 16 | @rem SPDX-License-Identifier: Apache-2.0 17 | @rem 18 | 19 | @if "%DEBUG%"=="" @echo off 20 | @rem ########################################################################## 21 | @rem 22 | @rem Gradle startup script for Windows 23 | @rem 24 | @rem ########################################################################## 25 | 26 | @rem Set local scope for the variables with windows NT shell 27 | if "%OS%"=="Windows_NT" setlocal 28 | 29 | set DIRNAME=%~dp0 30 | if "%DIRNAME%"=="" set DIRNAME=. 31 | @rem This is normally unused 32 | set APP_BASE_NAME=%~n0 33 | set APP_HOME=%DIRNAME% 34 | 35 | @rem Resolve any "." and ".." in APP_HOME to make it shorter. 36 | for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi 37 | 38 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 39 | set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" 40 | 41 | @rem Find java.exe 42 | if defined JAVA_HOME goto findJavaFromJavaHome 43 | 44 | set JAVA_EXE=java.exe 45 | %JAVA_EXE% -version >NUL 2>&1 46 | if %ERRORLEVEL% equ 0 goto execute 47 | 48 | echo. 1>&2 49 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2 50 | echo. 1>&2 51 | echo Please set the JAVA_HOME variable in your environment to match the 1>&2 52 | echo location of your Java installation. 1>&2 53 | 54 | goto fail 55 | 56 | :findJavaFromJavaHome 57 | set JAVA_HOME=%JAVA_HOME:"=% 58 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 59 | 60 | if exist "%JAVA_EXE%" goto execute 61 | 62 | echo. 1>&2 63 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 1>&2 64 | echo. 1>&2 65 | echo Please set the JAVA_HOME variable in your environment to match the 1>&2 66 | echo location of your Java installation. 1>&2 67 | 68 | goto fail 69 | 70 | :execute 71 | @rem Setup the command line 72 | 73 | 74 | 75 | @rem Execute Gradle 76 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -jar "%APP_HOME%\gradle\wrapper\gradle-wrapper.jar" %* 77 | 78 | :end 79 | @rem End local scope for the variables with windows NT shell 80 | if %ERRORLEVEL% equ 0 goto mainEnd 81 | 82 | :fail 83 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 84 | rem the _cmd.exe /c_ return code! 85 | set EXIT_CODE=%ERRORLEVEL% 86 | if %EXIT_CODE% equ 0 set EXIT_CODE=1 87 | if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE% 88 | exit /b %EXIT_CODE% 89 | 90 | :mainEnd 91 | if "%OS%"=="Windows_NT" endlocal 92 | 93 | :omega 94 | -------------------------------------------------------------------------------- /junit-jupiter-extensions/src/main/java/com/example/cartesian/CartesianProductProvider.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2025 the original author or authors. 3 | * 4 | * All rights reserved. This program and the accompanying materials are 5 | * made available under the terms of the Eclipse Public License v2.0 which 6 | * accompanies this distribution and is available at 7 | * 8 | * https://www.eclipse.org/legal/epl-v20.html 9 | */ 10 | 11 | package com.example.cartesian; 12 | 13 | import static org.junit.platform.commons.support.AnnotationSupport.findAnnotation; 14 | import static org.junit.platform.commons.support.ReflectionSupport.findMethod; 15 | import static org.junit.platform.commons.support.ReflectionSupport.invokeMethod; 16 | 17 | import java.lang.reflect.Method; 18 | import java.lang.reflect.Modifier; 19 | import java.util.ArrayList; 20 | import java.util.Arrays; 21 | import java.util.Collections; 22 | import java.util.List; 23 | import java.util.stream.Stream; 24 | import org.junit.jupiter.api.extension.ExtensionContext; 25 | import org.junit.jupiter.api.extension.TestTemplateInvocationContext; 26 | import org.junit.jupiter.api.extension.TestTemplateInvocationContextProvider; 27 | 28 | class CartesianProductProvider implements TestTemplateInvocationContextProvider { 29 | 30 | @Override 31 | public boolean supportsTestTemplate(ExtensionContext context) { 32 | return findAnnotation(context.getTestMethod(), CartesianProductTest.class).isPresent(); 33 | } 34 | 35 | @Override 36 | public Stream provideTestTemplateInvocationContexts(ExtensionContext context) { 37 | List> sets = computeSets(context.getRequiredTestMethod()); 38 | return cartesianProduct(sets).stream().map(CartesianProductContext::new); 39 | } 40 | 41 | private List> computeSets(Method testMethod) { 42 | String[] value = findAnnotation(testMethod, CartesianProductTest.class) 43 | .orElseThrow(() -> new AssertionError("@CartesianProductTest not found")) 44 | .value(); 45 | // Compute A ⨯ A ⨯ ... ⨯ A from single source "set" 46 | if (value.length > 0) { 47 | List strings = Arrays.asList(value); 48 | List> sets = new ArrayList<>(); 49 | for (int i = 0; i < testMethod.getParameterTypes().length; i++) { 50 | sets.add(strings); 51 | } 52 | return sets; 53 | } 54 | // No single entry supplied? Try the sets factory method instead... 55 | return invokeSetsFactory(testMethod).getSets(); 56 | } 57 | 58 | private CartesianProductTest.Sets invokeSetsFactory(Method testMethod) { 59 | Class declaringClass = testMethod.getDeclaringClass(); 60 | String name = testMethod.getName(); 61 | Method factory = findMethod(declaringClass, name) 62 | .orElseThrow(() -> new AssertionError("Method `CartesianProductTest.Sets " 63 | + name + "()` not found in " + declaringClass)); 64 | if (!Modifier.isStatic(factory.getModifiers())) { 65 | throw new AssertionError("Method `" + factory + "` must be static"); 66 | } 67 | if (!CartesianProductTest.Sets.class.isAssignableFrom(factory.getReturnType())) { 68 | throw new AssertionError("Method `" + factory + "` must return `CartesianProductTest.Sets`"); 69 | } 70 | if (factory.getParameterCount() != 0) { 71 | throw new AssertionError("Method `" + factory + "` must not have parameters"); 72 | } 73 | return (CartesianProductTest.Sets) invokeMethod(factory, null); 74 | } 75 | 76 | private static List> cartesianProduct(List> lists) { 77 | List> resultLists = new ArrayList<>(); 78 | if (lists.isEmpty()) { 79 | resultLists.add(Collections.emptyList()); 80 | return resultLists; 81 | } 82 | List firstList = lists.get(0); 83 | List> remainingLists = cartesianProduct(lists.subList(1, lists.size())); 84 | for (Object item : firstList) { 85 | for (List remainingList : remainingLists) { 86 | ArrayList resultList = new ArrayList<>(); 87 | resultList.add(item); 88 | resultList.addAll(remainingList); 89 | resultLists.add(resultList); 90 | } 91 | } 92 | return resultLists; 93 | } 94 | 95 | } 96 | -------------------------------------------------------------------------------- /junit-multiple-engines/build.gradle.kts: -------------------------------------------------------------------------------- 1 | import org.jetbrains.kotlin.gradle.dsl.JvmTarget.JVM_17 2 | import org.jetbrains.kotlin.gradle.tasks.KotlinCompile 3 | 4 | plugins { 5 | java 6 | groovy 7 | eclipse // optional (to generate Eclipse project files) 8 | idea // optional (to generate IntelliJ IDEA project files) 9 | kotlin("jvm") version "2.2.21" 10 | } 11 | 12 | repositories { 13 | mavenCentral() 14 | } 15 | 16 | dependencies { 17 | val junit4Version = "4.13.2" 18 | val junitBomVersion = "6.0.1" 19 | 20 | // Use junit-bom to align versions 21 | // https://docs.gradle.org/current/userguide/managing_transitive_dependencies.html#sec:bom_import 22 | implementation(platform("org.junit:junit-bom:$junitBomVersion")) { 23 | because("Platform, Jupiter, and Vintage versions should match") 24 | } 25 | 26 | // JUnit Jupiter 27 | testImplementation("org.junit.jupiter:junit-jupiter") 28 | 29 | // JUnit Vintage 30 | testImplementation("junit:junit:$junit4Version") 31 | testRuntimeOnly("org.junit.vintage:junit-vintage-engine") { 32 | because("allows JUnit 3 and JUnit 4 tests to run") 33 | } 34 | 35 | // JUnit Suites 36 | testImplementation("org.junit.platform:junit-platform-suite") 37 | 38 | // JUnit Platform Launcher + Console 39 | testRuntimeOnly("org.junit.platform:junit-platform-launcher") { 40 | because("allows tests to run from IDEs that bundle older version of launcher") 41 | } 42 | testRuntimeOnly("org.junit.platform:junit-platform-console") { 43 | because("needed to launch the JUnit Platform Console program") 44 | } 45 | 46 | // Mainrunner 47 | testImplementation("de.sormuras.mainrunner:de.sormuras.mainrunner.engine:2.1.4") { 48 | because("executes Java programs as tests") 49 | } 50 | 51 | // jqwik 52 | testImplementation("net.jqwik:jqwik:1.9.3") { 53 | because("allows jqwik properties to run") 54 | } 55 | 56 | // Spek2 57 | val spekVersion = "2.0.19" 58 | testImplementation("org.spekframework.spek2:spek-dsl-jvm:$spekVersion") 59 | testRuntimeOnly("org.spekframework.spek2:spek-runner-junit5:$spekVersion") 60 | 61 | // Spock2 62 | testImplementation("org.spockframework:spock-core:2.4-groovy-5.0") { 63 | because("allows Spock specifications to run") 64 | } 65 | testImplementation(platform("org.apache.groovy:groovy-bom:5.0.3")) { 66 | because("use latest 5.x version of Groovy for maximum compatibility with new JDKs") 67 | } 68 | 69 | // Kotest 70 | testImplementation("io.kotest:kotest-runner-junit5:6.0.7") 71 | testRuntimeOnly("org.slf4j:slf4j-nop:2.0.17") { 72 | because("defaulting to no-operation (NOP) logger implementation") 73 | } 74 | 75 | // TestNG 76 | testImplementation("org.testng:testng:7.11.0") { 77 | because("allows writing TestNG tests") 78 | } 79 | testRuntimeOnly("org.junit.support:testng-engine:1.1.0") { 80 | because("allows running TestNG tests on the JUnit Platform") 81 | } 82 | } 83 | 84 | tasks { 85 | 86 | withType().configureEach { 87 | options.release = 17 88 | } 89 | 90 | withType().configureEach { 91 | compilerOptions.jvmTarget = JVM_17 92 | } 93 | 94 | val consoleLauncherTest by registering(JavaExec::class) { 95 | dependsOn(testClasses) 96 | classpath = sourceSets.test.get().runtimeClasspath 97 | mainClass.set("org.junit.platform.console.ConsoleLauncher") 98 | args("execute") 99 | args("--scan-classpath") 100 | args("--include-classname", ".*((Tests?)|(Spec))$") 101 | args("--details", "tree") 102 | argumentProviders += objects.newInstance(ReportsDirArgumentProvider::class).apply { 103 | reportsDir.set(layout.buildDirectory.dir("test-results")) 104 | } 105 | } 106 | 107 | test { 108 | // useJUnitPlatform() ... https://github.com/gradle/gradle/issues/4912 109 | dependsOn(consoleLauncherTest) 110 | exclude("**/*") 111 | } 112 | } 113 | -------------------------------------------------------------------------------- /junit-migration-maven/README.md: -------------------------------------------------------------------------------- 1 | # junit-migration-maven 2 | 3 | The `junit-migration-maven` project demonstrates how to execute tests based on JUnit 5 4 | using Maven. In addition, it showcases that existing JUnit 4 based tests can be executed 5 | in the same test suite as JUnit Jupiter based tests or any other tests supported on 6 | the JUnit Platform. 7 | 8 | This example project does not aim to demonstrate how to use the JUnit Jupiter APIs. 9 | For detailed information on the JUnit Jupiter programming and extension models, 10 | please consult the [User Guide](https://docs.junit.org/current/user-guide/). 11 | 12 | Please note that this project uses the [Maven Wrapper](https://github.com/takari/maven-wrapper). 13 | Thus, to ensure that the correct version of Maven is used, invoke `mvnw` instead of `mvn`. 14 | 15 | ## Executing JUnit 4 and JUnit Jupiter Tests 16 | 17 | Invoking `mvnw clean test` from the command line will execute all tests in the test source 18 | folder that follow one of following patterns: `Test*`, `*Test`, `*Tests`, or `*TestCase`. 19 | Note that [Surefire's default naming patterns](https://maven.apache.org/surefire/maven-surefire-plugin/examples/inclusion-exclusion.html) 20 | have been overridden in the `pom.xml` file. Surefire's execution of 21 | the example tests should result in output similar to the following: 22 | 23 | ``` 24 | ------------------------------------------------------- 25 | T E S T S 26 | ------------------------------------------------------- 27 | Jan 07, 2017 11:49:00 PM org.junit.platform.launcher.core.ServiceLoaderTestEngineRegistry loadTestEngines 28 | INFO: Discovered TestEngines with IDs: [junit-jupiter, junit-vintage] 29 | Running com.example.project.FirstTest 30 | Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.038 sec - in com.example.project.FirstTest 31 | Running com.example.project.JUnit4Test 32 | Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0 sec - in com.example.project.JUnit4Test 33 | Running com.example.project.OtherTests 34 | Tests run: 2, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0 sec - in com.example.project.OtherTests 35 | Running com.example.project.SecondTest 36 | Tests run: 1, Failures: 0, Errors: 0, Skipped: 1, Time elapsed: 0.001 sec - in com.example.project.SecondTest 37 | 38 | Results : 39 | 40 | Tests run: 5, Failures: 0, Errors: 0, Skipped: 1 41 | 42 | [INFO] ------------------------------------------------------------------------ 43 | [INFO] BUILD SUCCESS 44 | [INFO] ------------------------------------------------------------------------ 45 | ``` 46 | 47 | If you comment out the `@Disabled` annotation on `SecondTest#mySecondTest()`, you will 48 | then see the build fail with output similar to the following: 49 | 50 | ``` 51 | ------------------------------------------------------- 52 | T E S T S 53 | ------------------------------------------------------- 54 | Jan 07, 2017 11:50:07 PM org.junit.platform.launcher.core.ServiceLoaderTestEngineRegistry loadTestEngines 55 | INFO: Discovered TestEngines with IDs: [junit-jupiter, junit-vintage] 56 | Running com.example.project.FirstTest 57 | Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.049 sec - in com.example.project.FirstTest 58 | Running com.example.project.JUnit4Test 59 | Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.017 sec - in com.example.project.JUnit4Test 60 | Running com.example.project.OtherTests 61 | Tests run: 2, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.006 sec - in com.example.project.OtherTests 62 | Running com.example.project.SecondTest 63 | Tests run: 1, Failures: 1, Errors: 0, Skipped: 0, Time elapsed: 0.032 sec <<< FAILURE! - in com.example.project.SecondTest 64 | mySecondTest() Time elapsed: 0.019 sec <<< FAILURE! 65 | org.opentest4j.AssertionFailedError: 2 is not equal to 1 ==> expected: <2> but was: <1> 66 | at com.example.project.SecondTest.mySecondTest(SecondTest.java:24) 67 | 68 | 69 | Results : 70 | 71 | Failed tests: 72 | SecondTest.mySecondTest:24 2 is not equal to 1 ==> expected: <2> but was: <1> 73 | 74 | Tests run: 5, Failures: 1, Errors: 0, Skipped: 0 75 | 76 | [INFO] ------------------------------------------------------------------------ 77 | [INFO] BUILD FAILURE 78 | [INFO] ------------------------------------------------------------------------ 79 | ``` 80 | 81 | ### Test Reports 82 | 83 | Maven Surefire writes plain text and XML test reports to `target/surefire-reports`. 84 | 85 | ### Limitations 86 | 87 | Advanced Maven Surefire parameters, such as `forkCount` or `parallel`, do not work yet. 88 | -------------------------------------------------------------------------------- /src/Updater.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2025 the original author or authors. 3 | * 4 | * All rights reserved. This program and the accompanying materials are 5 | * made available under the terms of the Eclipse Public License v2.0 which 6 | * accompanies this distribution and is available at 7 | * 8 | * https://www.eclipse.org/legal/epl-v20.html 9 | */ 10 | 11 | // default package 12 | 13 | import java.io.IOException; 14 | import java.nio.file.Files; 15 | import java.nio.file.Path; 16 | import java.util.List; 17 | import java.util.regex.Pattern; 18 | 19 | /** 20 | * Updates the versions of JUnit Framework artifacts in all example projects. 21 | */ 22 | @SuppressWarnings({"WeakerAccess", "SameParameterValue"}) 23 | class Updater { 24 | 25 | private static final String VERSION_REGEX = "([0-9.]+(?:-[A-Z]+[0-9]*)?)"; 26 | 27 | public static void main(String[] args) throws Exception { 28 | new Updater(args[0]).update(); 29 | } 30 | 31 | private final String newVersion; 32 | 33 | public Updater(String newVersion) { 34 | this.newVersion = newVersion; 35 | } 36 | 37 | void update() throws IOException { 38 | var gradleBomReplacement = Pattern.compile("org.junit:junit-bom:" + VERSION_REGEX); 39 | var mavenBomReplacement = Pattern.compile( 40 | """ 41 | \\s*org.junit 42 | \\s*junit-bom 43 | \\s*""" + VERSION_REGEX + "", 44 | Pattern.MULTILINE 45 | ); 46 | 47 | update(Path.of("junit-jupiter-extensions/build.gradle"), List.of(gradleBomReplacement)); 48 | update(Path.of("junit-jupiter-starter-ant/build.sh"), List.of( 49 | Pattern.compile("junit_version='" + VERSION_REGEX + "'") 50 | )); 51 | update(Path.of("junit-jupiter-starter-bazel/MODULE.bazel"), List.of( 52 | Pattern.compile("JUNIT_VERSION = \"" + VERSION_REGEX + '"') 53 | )); 54 | update(Path.of("junit-jupiter-starter-gradle/build.gradle"), List.of(gradleBomReplacement)); 55 | update(Path.of("junit-jupiter-starter-gradle-groovy/build.gradle"), List.of(gradleBomReplacement)); 56 | update(Path.of("junit-jupiter-starter-gradle-kotlin/build.gradle.kts"), List.of(gradleBomReplacement)); 57 | update(Path.of("junit-jupiter-starter-maven/pom.xml"), List.of(mavenBomReplacement)); 58 | update(Path.of("junit-jupiter-starter-maven-kotlin/pom.xml"), List.of(mavenBomReplacement)); 59 | update(Path.of("junit-jupiter-starter-sbt/build.sbt"), List.of( 60 | Pattern.compile("\"org.junit.jupiter\" % \"junit-jupiter\" % \"" + VERSION_REGEX + '"'), 61 | Pattern.compile("\"org.junit.platform\" % \"junit-platform-launcher\" % \"" + VERSION_REGEX + '"') 62 | )); 63 | update(Path.of("junit-migration-gradle/build.gradle"), List.of(gradleBomReplacement)); 64 | update(Path.of("junit-migration-gradle/README.md"), List.of( 65 | Pattern.compile("org.junit.jupiter:junit-jupiter:" + VERSION_REGEX), 66 | Pattern.compile("org.junit.vintage:junit-vintage-engine:" + VERSION_REGEX) 67 | )); 68 | update(Path.of("junit-migration-maven/pom.xml"), List.of(mavenBomReplacement)); 69 | update(Path.of("junit-modular-world/src/build/Project.java"), List.of( 70 | Pattern.compile("junitVersion = \"" + VERSION_REGEX + '"') 71 | )); 72 | update(Path.of("junit-multiple-engines/build.gradle.kts"), List.of( 73 | Pattern.compile("junitBomVersion = \"" + VERSION_REGEX + '"') 74 | )); 75 | update(Path.of("junit-source-launcher/lib/DownloadRequiredModules.java"), List.of( 76 | Pattern.compile("final String version = \"" + VERSION_REGEX + '\"') 77 | )); 78 | } 79 | 80 | void update(Path path, List patterns) throws IOException { 81 | System.out.printf("Updating %s...", path); 82 | System.out.flush(); 83 | int matches = 0; 84 | var content = new StringBuilder(Files.readString(path)); 85 | for (var pattern : patterns) { 86 | var minIndex = 0; 87 | var matcher = pattern.matcher(content); 88 | while (matcher.find(minIndex)) { 89 | matches++; 90 | int start = matcher.start(1); 91 | int end = matcher.end(1); 92 | int oldLength = end - start; 93 | content.replace(start, end, newVersion); 94 | minIndex = end + newVersion.length() - oldLength; 95 | } 96 | } 97 | Files.writeString(path, content); 98 | System.out.printf(" %d%n", matches); 99 | if (matches == 0) { 100 | throw new IllegalStateException("No matches found in " + path); 101 | } 102 | } 103 | } 104 | -------------------------------------------------------------------------------- /junit-migration-gradle/README.md: -------------------------------------------------------------------------------- 1 | # junit-migration-gradle 2 | 3 | The `junit-migration-gradle` project demonstrates how to execute tests based on JUnit 5 4 | using Gradle. In addition, it showcases that existing JUnit 4 based tests can be executed 5 | in the same test suite as JUnit Jupiter based tests or any other tests supported on 6 | the JUnit Platform. 7 | 8 | This example project does not aim to demonstrate how to use the JUnit Jupiter APIs. 9 | For detailed information on the JUnit Jupiter programming and extension models, 10 | please consult the [User Guide](https://docs.junit.org/current/user-guide/). 11 | 12 | ## Enabling the JUnit Platform 13 | 14 | To use the JUnit Platform with Gradle, you need to configure `build.gradle` as follows. 15 | 16 | ```groovy 17 | test { 18 | useJUnitPlatform() 19 | } 20 | ``` 21 | 22 | ## Configuring the Test task 23 | 24 | Optionally, you can configure the `test` task as follows. 25 | 26 | ```groovy 27 | test { 28 | useJUnitPlatform { 29 | // includeEngines("junit-jupiter", "junit-vintage") 30 | // excludeEngines("custom-engine") 31 | 32 | // includeTags("fast") 33 | excludeTags("slow") 34 | } 35 | testLogging { 36 | events("passed", "skipped", "failed") 37 | } 38 | } 39 | ``` 40 | 41 | By default all engines and tags are included in the test plan. 42 | 43 | If you supply a _Test Engine ID_ via `includeEngines(...)` or `excludeEngines(...)`, 44 | Gradle will only run tests for the desired test engines. 45 | 46 | If you supply a _tag_ via `includeTags(...)`, Gradle will only 47 | run tests that are _tagged_ accordingly (e.g., via the `@Tag` annotation for 48 | JUnit Jupiter based tests). Similarly, if you supply a _tag_ via `excludeTags(...)`, 49 | Gradle will not run tests that are _tagged_ accordingly. 50 | 51 | ## Configuring Test Engines 52 | 53 | In order to have Gradle's `test` task run any tests at all, a `TestEngine` 54 | implementation must be on the classpath. 55 | 56 | To configure support for JUnit Jupiter based tests, configure a `testImplementation` 57 | dependency on the `junit-jupiter` artifact. That will cause `testImplementation` 58 | dependency on the JUnit Jupiter API and a `testRuntimeOnly` dependency on the JUnit 59 | Jupiter TestEngine. 60 | 61 | ```groovy 62 | dependencies { 63 | testImplementation("org.junit.jupiter:junit-jupiter:6.0.1") 64 | } 65 | ``` 66 | 67 | Gradle can also run JUnit 3 and JUnit 4 based tests as long as you 68 | configure a `testImplementation` dependency on JUnit 4 and a `testRuntimeOnly` dependency 69 | on the JUnit Vintage TestEngine implementation similar to the following. 70 | 71 | ```groovy 72 | dependencies { 73 | testImplementation("junit:junit:4.13.2") 74 | testRuntimeOnly("org.junit.vintage:junit-vintage-engine:6.0.1") 75 | } 76 | ``` 77 | 78 | ## Executing Tests on the JUnit Platform 79 | 80 | Once the JUnit Platform Gradle plugin has been applied and configured, you can use the 81 | standard `test` task as usual. 82 | 83 | Invoking `gradlew clean test` from the command line will execute all tests within the 84 | project. This will result in output similar to the following: 85 | 86 | ``` 87 | > Task :test 88 | 89 | com.example.project.SecondTest > mySecondTest() SKIPPED 90 | 91 | com.example.project.OtherTests > testThisThing() PASSED 92 | 93 | com.example.project.OtherTests > testThisOtherThing() PASSED 94 | 95 | com.example.project.FirstTest > myFirstTest(TestInfo) PASSED 96 | 97 | com.example.project.JUnit4Test > test PASSED 98 | 99 | BUILD SUCCESSFUL in 2s 100 | 4 actionable tasks: 3 executed, 1 up-to-date 101 | ``` 102 | 103 | If you comment out the `@Disabled` annotation on `SecondTest#mySecondTest()`, you will 104 | then see the build fail with output similar to the following: 105 | 106 | ``` 107 | > Task :test FAILED 108 | 109 | com.example.project.OtherTests > testThisThing() PASSED 110 | 111 | com.example.project.OtherTests > testThisOtherThing() PASSED 112 | 113 | com.example.project.FirstTest > myFirstTest(TestInfo) PASSED 114 | 115 | com.example.project.SecondTest > mySecondTest() FAILED 116 | org.opentest4j.AssertionFailedError at SecondTest.java:24 117 | 118 | com.example.project.JUnit4Test > test PASSED 119 | 120 | 5 tests completed, 1 failed 121 | 122 | FAILURE: Build failed with an exception. 123 | 124 | * What went wrong: 125 | Execution failed for task ':test'. 126 | > There were failing tests. See the report at: file:///Users/junit-team/junit-examples/junit-migration-gradle/build/reports/tests/test/index.html 127 | 128 | * Try: 129 | Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights. 130 | 131 | * Get more help at https://help.gradle.org 132 | 133 | BUILD FAILED in 2s 134 | 4 actionable tasks: 3 executed, 1 up-to-date 135 | ``` 136 | 137 | ### Test Reports 138 | 139 | Gradle writes XML test reports to `build/test-results/test` and HTML test reports to `build/reports/tests/test`. 140 | -------------------------------------------------------------------------------- /src/StagingRepoInjector.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2025 the original author or authors. 3 | * 4 | * All rights reserved. This program and the accompanying materials are 5 | * made available under the terms of the Eclipse Public License v2.0 which 6 | * accompanies this distribution and is available at 7 | * 8 | * https://www.eclipse.org/legal/epl-v20.html 9 | */ 10 | 11 | // default package 12 | 13 | import java.io.IOException; 14 | import java.nio.file.Files; 15 | import java.nio.file.Path; 16 | import java.util.function.Consumer; 17 | 18 | public class StagingRepoInjector { 19 | 20 | public static void main(String[] args) throws Exception { 21 | new StagingRepoInjector(args[0]).inject(); 22 | } 23 | 24 | private final String stagingRepoUrl; 25 | 26 | private StagingRepoInjector(String stagingRepoUrl) { 27 | this.stagingRepoUrl = stagingRepoUrl; 28 | } 29 | 30 | private void inject() throws Exception { 31 | 32 | var gradleGroovyDslSnippet = """ 33 | 34 | maven { 35 | url = '%s' 36 | credentials(HttpHeaderCredentials) { 37 | name = 'Authorization' 38 | value = "Bearer ${System.getenv('MAVEN_CENTRAL_USER_TOKEN')}" 39 | } 40 | authentication { 41 | header(HttpHeaderAuthentication) 42 | } 43 | } 44 | """ 45 | .formatted(stagingRepoUrl); 46 | 47 | var gradleKotlinDslSnippet = """ 48 | 49 | maven { 50 | url = uri("%s") 51 | credentials(HttpHeaderCredentials::class) { 52 | name = "Authorization" 53 | value = "Bearer ${System.getenv("MAVEN_CENTRAL_USER_TOKEN")}" 54 | } 55 | authentication { 56 | create("header") 57 | } 58 | } 59 | """ 60 | .formatted(stagingRepoUrl); 61 | 62 | appendAfter("junit-jupiter-extensions/build.gradle", "mavenCentral()", 63 | gradleGroovyDslSnippet); 64 | 65 | replace("junit-jupiter-starter-ant/build.sh", "\"https://repo1.maven.org/maven2", 66 | "--header \"Authorization: Bearer $MAVEN_CENTRAL_USER_TOKEN\" \"%s".formatted(stagingRepoUrl)); 67 | 68 | appendAfter("junit-jupiter-starter-gradle/build.gradle", "mavenCentral()", 69 | gradleGroovyDslSnippet); 70 | 71 | appendAfter("junit-jupiter-starter-gradle-groovy/build.gradle", "mavenCentral()", 72 | gradleGroovyDslSnippet); 73 | 74 | appendAfter("junit-jupiter-starter-gradle-kotlin/build.gradle.kts", "mavenCentral()", 75 | gradleKotlinDslSnippet); 76 | 77 | appendAfter("junit-migration-gradle/build.gradle", "mavenCentral()", 78 | gradleGroovyDslSnippet); 79 | 80 | replace("junit-modular-world/src/build/Project.java", "\"https://repo1.maven.org/maven2\"", 81 | "group.startsWith(\"org.junit\") ? \"%s\" : \"https://repo1.maven.org/maven2\"".formatted(stagingRepoUrl)); 82 | 83 | appendAfter("junit-multiple-engines/build.gradle.kts", "mavenCentral()", 84 | gradleKotlinDslSnippet); 85 | 86 | replace("junit-source-launcher/lib/DownloadRequiredModules.java", 87 | "final String repository = \"https://repo.maven.apache.org/maven2\"", 88 | "final String repository = \"%s\"".formatted(stagingRepoUrl)); 89 | } 90 | 91 | void appendAfter(String path, String token, String addedContent) throws IOException { 92 | process(path, content -> { 93 | if (content.indexOf(token) == -1) { 94 | throw new IllegalStateException("Token not found in " + path); 95 | } 96 | content.insert(content.indexOf(token) + token.length(), addedContent); 97 | }); 98 | } 99 | 100 | void replace(String path, String token, String replacement) throws IOException { 101 | process(path, content -> { 102 | if (content.indexOf(token) == -1) { 103 | throw new IllegalStateException("Token not found in " + path); 104 | } 105 | content.replace(content.indexOf(token), content.indexOf(token) + token.length(), replacement); 106 | }); 107 | } 108 | 109 | void process(String path, Consumer modification) throws IOException { 110 | System.out.printf("Processing %s...", path); 111 | System.out.flush(); 112 | var file = Path.of(path); 113 | var content = new StringBuilder(Files.readString(file)); 114 | modification.accept(content); 115 | Files.writeString(file, content); 116 | System.out.println(" OK"); 117 | } 118 | } 119 | -------------------------------------------------------------------------------- /junit-modular-world/README.md: -------------------------------------------------------------------------------- 1 | # junit-modular-world 2 | 3 | The project layout structure and command line tools usages are based on proposals 4 | introduced by the [**Module System Quick-Start Guide**](https://openjdk.java.net/projects/jigsaw/quick-start). 5 | Invoke [java](https://openjdk.org/jeps/458)'s source launcher 6 | `java src/build/Build.java` to build this example project. 7 | 8 | This example project does not aim to demonstrate how to use the JUnit Framework APIs. 9 | For detailed information on the JUnit Framework programming and extension models, 10 | please consult the [User Guide](https://docs.junit.org/current/user-guide/). 11 | 12 | ## Source Layout 13 | 14 | This project hosts three main modules with their associated test modules. 15 | Their names are `com.example.application`, `com.example.tool` and `ice.cream`. 16 | 17 | In addition to the main modules there's a test module named `extra.modular`. 18 | It tests the exported packages and types of the main modules. 19 | 20 | ![junit-modular-world/src](doc/screenshot-src.png) 21 | 22 | 23 | ## Binary Layout 24 | 25 | Main binaries are compiled and packaged using `java src/build/Compile.java`. 26 | 27 | For example, here are the commands to compile and package the `com.example.tool` module. 28 | This and the `com.example.application` module don't need external module dependencies. 29 | ``` 30 | javac 31 | -d bin/main 32 | --module-source-path src/main 33 | --module com.example.tool 34 | ``` 35 | ``` 36 | jar 37 | --create 38 | --file bin/main-jars/com.example.tool.jar 39 | -C bin/main/com.example.tool 40 | . 41 | ``` 42 | 43 | The `ice.cream` modules needs external modules to compile and is packaged with an explicit module version: 44 | ``` 45 | javac 46 | -d bin/main 47 | --module-path lib 48 | --module-source-path src/main 49 | --module ice.cream 50 | ``` 51 | ``` 52 | jar 53 | --create 54 | --file bin/main-jars/ice.cream.jar 55 | --module-version 47.11 56 | -C bin/main/ice.cream 57 | . 58 | ``` 59 | 60 | Here is the partly expanded tree of the `bin/` directory after running `java src/build/Compile.java`: 61 | 62 | ![junit-modular-world/bin](doc/screenshot-bin.png) 63 | 64 | 65 | ## Running Tests 66 | 67 | Compiling and running tests is achieved by calling the following Java program: 68 | 69 | - `java src/build/Build.java` 70 | 71 | ``` 72 | ╷ 73 | ├─ JQwik Test Engine ✔ 74 | │ └─ JQwikTests ✔ 75 | │ ├─ exampleFor1And3Equals4 ✔ 76 | │ └─ propertyAdd ✔ 77 | │ 2018-03-06T09:39:40.606157 78 | │ tries = `1000` 79 | │ checks = `1000` 80 | │ seed = `-3387297467304298077` 81 | ├─ JUnit Vintage ✔ 82 | │ └─ extra.modular.GoodOldTest ✔ 83 | │ └─ eighteenEqualsNineAndNine ✔ 84 | ├─ JUnit Jupiter ✔ 85 | │ ├─ extra.modular/extra.modular.ExtraModularTests ✔ 86 | │ │ ├─ moduleName() ✔ 87 | │ │ ├─ add(RepetitionInfo) ✔ 88 | │ │ │ ├─ 1 + 5 ✔ 89 | │ │ │ ├─ 2 + 5 ✔ 90 | │ │ │ ├─ 3 + 5 ✔ 91 | │ │ │ ├─ 4 + 5 ✔ 92 | │ │ │ └─ 5 + 5 ✔ 93 | │ │ └─ packageName() ✔ 94 | │ ├─ com.example.application/com.example.application.MainTests ✔ 95 | │ │ ├─ simpleName() ✔ 96 | │ │ └─ main() ✔ 97 | │ ├─ com.example.tool/com.example.tool.CalculatorTests ✔ 98 | │ │ ├─ add() ✔ 99 | │ │ ├─ mul() ✔ 100 | │ │ └─ pow() ✔ 101 | │ ├─ FlavorTests ✔ 102 | │ │ └─ random() ✔ 103 | │ └─ MachineTests ✔ 104 | │ ├─ id() ✔ 105 | │ └─ caption() ✔ 106 | └─ Ice Cream Machine 47.11 (ice.cream) ✔ 107 | ├─ Stracciatella ✔ 108 | ├─ Stracciatella ✔ 109 | ├─ Chocolate ✔ 110 | ├─ Vanilla ✔ 111 | └─ Stracciatella ✔ 112 | ``` 113 | 114 | ## Ice Cream Test Engine 115 | 116 | The `ice.cream` module demonstrates how to write and register your own `TestEngine` 117 | implementation using a Java module descriptor. 118 | This engine does not find any tests in containers, but _discovers_ a configurable 119 | amount of ice cream scoops. 120 | 121 | ### Module Descriptor of the Ice-Cream-Machine 122 | 123 | Let's start with the `ice.cream` module descriptor [module-info.java](src/main/ice.cream/module-info.java): 124 | 125 | ``` 126 | module ice.cream { 127 | requires org.junit.platform.engine; 128 | 129 | provides org.junit.platform.engine.TestEngine with ice.cream.Machine; 130 | } 131 | ``` 132 | 133 | ### Implementation of the Ice-Cream-Machine 134 | 135 | Here's the outline of the `TestEngine` implementation: 136 | 137 | ``` 138 | package ice.cream; 139 | 140 | public class Machine implements TestEngine { 141 | 142 | @Override 143 | public String getId() { 144 | return "ice-cream-machine"; 145 | } 146 | 147 | @Override 148 | public TestDescriptor discover(EngineDiscoveryRequest discoveryRequest, UniqueId uniqueId) { 149 | ...generate Scoops, i.e. TestDescriptors. 150 | } 151 | 152 | @Override 153 | public void execute(ExecutionRequest request) { 154 | ..."run" Scoops. Tell engine execution listener what we're doing. 155 | } 156 | } 157 | ``` 158 | 159 | See classes in package [ice.cream](src/main/ice.cream/ice/cream) for implementation details. 160 | 161 | ### Running the Ice-Cream-Machine 162 | 163 | Sample command line to register and execute the ice.cream machine: 164 | 165 | ``` 166 | java 167 | -Dscoops=3 168 | --module-path ... 169 | --add-modules ALL-MODULE-PATH 170 | --module org.junit.platform.console 171 | execute 172 | --scan-modules 173 | ``` 174 | 175 | The standard output could read like this: 176 | ``` 177 | ╷ 178 | └─ Ice Cream Machine 47.11 (ice.cream) ✔ 179 | ├─ Stracciatella ✔ 180 | ├─ Stracciatella ✔ 181 | └─ Vanilla ✔ 182 | ``` 183 | -------------------------------------------------------------------------------- /junit-jupiter-starter-bazel/.gitignore: -------------------------------------------------------------------------------- 1 | 2 | # Created by https://www.gitignore.io/api/vim,java,linux,macos,maven,bazel,eclipse,windows,intellij+all,visualstudiocode 3 | 4 | ### Bazel ### 5 | /bazel-* 6 | 7 | ### Eclipse ### 8 | 9 | .metadata 10 | bin/ 11 | tmp/ 12 | *.tmp 13 | *.bak 14 | *.swp 15 | *~.nib 16 | local.properties 17 | .settings/ 18 | .loadpath 19 | .recommenders 20 | 21 | # External tool builders 22 | .externalToolBuilders/ 23 | 24 | # Locally stored "Eclipse launch configurations" 25 | *.launch 26 | 27 | # PyDev specific (Python IDE for Eclipse) 28 | *.pydevproject 29 | 30 | # CDT-specific (C/C++ Development Tooling) 31 | .cproject 32 | 33 | # CDT- autotools 34 | .autotools 35 | 36 | # Java annotation processor (APT) 37 | .factorypath 38 | 39 | # PDT-specific (PHP Development Tools) 40 | .buildpath 41 | 42 | # sbteclipse plugin 43 | .target 44 | 45 | # Tern plugin 46 | .tern-project 47 | 48 | # TeXlipse plugin 49 | .texlipse 50 | 51 | # STS (Spring Tool Suite) 52 | .springBeans 53 | 54 | # Code Recommenders 55 | .recommenders/ 56 | 57 | # Annotation Processing 58 | .apt_generated/ 59 | 60 | # Scala IDE specific (Scala & Java development for Eclipse) 61 | .cache-main 62 | .scala_dependencies 63 | .worksheet 64 | 65 | ### Eclipse Patch ### 66 | # Eclipse Core 67 | .project 68 | 69 | # JDT-specific (Eclipse Java Development Tools) 70 | .classpath 71 | 72 | # Annotation Processing 73 | .apt_generated 74 | 75 | ### Intellij+all ### 76 | # Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and WebStorm 77 | # Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839 78 | 79 | # User-specific stuff 80 | .idea/**/workspace.xml 81 | .idea/**/tasks.xml 82 | .idea/**/usage.statistics.xml 83 | .idea/**/dictionaries 84 | .idea/**/shelf 85 | 86 | # Sensitive or high-churn files 87 | .idea/**/dataSources/ 88 | .idea/**/dataSources.ids 89 | .idea/**/dataSources.local.xml 90 | .idea/**/sqlDataSources.xml 91 | .idea/**/dynamic.xml 92 | .idea/**/uiDesigner.xml 93 | .idea/**/dbnavigator.xml 94 | 95 | # Gradle 96 | .idea/**/gradle.xml 97 | .idea/**/libraries 98 | 99 | # Gradle and Maven with auto-import 100 | # When using Gradle or Maven with auto-import, you should exclude module files, 101 | # since they will be recreated, and may cause churn. Uncomment if using 102 | # auto-import. 103 | # .idea/modules.xml 104 | # .idea/*.iml 105 | # .idea/modules 106 | 107 | # CMake 108 | cmake-build-*/ 109 | 110 | # Mongo Explorer plugin 111 | .idea/**/mongoSettings.xml 112 | 113 | # File-based project format 114 | *.iws 115 | 116 | # IntelliJ 117 | out/ 118 | 119 | # mpeltonen/sbt-idea plugin 120 | .idea_modules/ 121 | 122 | # JIRA plugin 123 | atlassian-ide-plugin.xml 124 | 125 | # Cursive Clojure plugin 126 | .idea/replstate.xml 127 | 128 | # Crashlytics plugin (for Android Studio and IntelliJ) 129 | com_crashlytics_export_strings.xml 130 | crashlytics.properties 131 | crashlytics-build.properties 132 | fabric.properties 133 | 134 | # Editor-based Rest Client 135 | .idea/httpRequests 136 | 137 | ### Intellij+all Patch ### 138 | # Ignores the whole .idea folder and all .iml files 139 | # See https://github.com/joeblau/gitignore.io/issues/186 and https://github.com/joeblau/gitignore.io/issues/360 140 | 141 | .idea/ 142 | 143 | # Reason: https://github.com/joeblau/gitignore.io/issues/186#issuecomment-249601023 144 | 145 | *.iml 146 | modules.xml 147 | .idea/misc.xml 148 | *.ipr 149 | 150 | ### Java ### 151 | # Compiled class file 152 | *.class 153 | 154 | # Log file 155 | *.log 156 | 157 | # BlueJ files 158 | *.ctxt 159 | 160 | # Mobile Tools for Java (J2ME) 161 | .mtj.tmp/ 162 | 163 | # Package Files # 164 | *.jar 165 | *.war 166 | *.nar 167 | *.ear 168 | *.zip 169 | *.tar.gz 170 | *.rar 171 | 172 | # virtual machine crash logs, see https://www.java.com/en/download/help/error_hotspot.xml 173 | hs_err_pid* 174 | 175 | ### Linux ### 176 | *~ 177 | 178 | # temporary files which can be created if a process still has a handle open of a deleted file 179 | .fuse_hidden* 180 | 181 | # KDE directory preferences 182 | .directory 183 | 184 | # Linux trash folder which might appear on any partition or disk 185 | .Trash-* 186 | 187 | # .nfs files are created when an open file is removed but is still being accessed 188 | .nfs* 189 | 190 | ### macOS ### 191 | # General 192 | .DS_Store 193 | .AppleDouble 194 | .LSOverride 195 | 196 | # Icon must end with two \r 197 | Icon 198 | 199 | # Thumbnails 200 | ._* 201 | 202 | # Files that might appear in the root of a volume 203 | .DocumentRevisions-V100 204 | .fseventsd 205 | .Spotlight-V100 206 | .TemporaryItems 207 | .Trashes 208 | .VolumeIcon.icns 209 | .com.apple.timemachine.donotpresent 210 | 211 | # Directories potentially created on remote AFP share 212 | .AppleDB 213 | .AppleDesktop 214 | Network Trash Folder 215 | Temporary Items 216 | .apdisk 217 | 218 | ### Maven ### 219 | target/ 220 | pom.xml.tag 221 | pom.xml.releaseBackup 222 | pom.xml.versionsBackup 223 | pom.xml.next 224 | release.properties 225 | dependency-reduced-pom.xml 226 | buildNumber.properties 227 | .mvn/timing.properties 228 | .mvn/wrapper/maven-wrapper.jar 229 | 230 | ### Vim ### 231 | # Swap 232 | [._]*.s[a-v][a-z] 233 | [._]*.sw[a-p] 234 | [._]s[a-rt-v][a-z] 235 | [._]ss[a-gi-z] 236 | [._]sw[a-p] 237 | 238 | # Session 239 | Session.vim 240 | 241 | # Temporary 242 | .netrwhist 243 | # Auto-generated tag files 244 | tags 245 | # Persistent undo 246 | [._]*.un~ 247 | 248 | ### VisualStudioCode ### 249 | .vscode/* 250 | !.vscode/settings.json 251 | !.vscode/tasks.json 252 | !.vscode/launch.json 253 | !.vscode/extensions.json 254 | 255 | ### Windows ### 256 | # Windows thumbnail cache files 257 | Thumbs.db 258 | ehthumbs.db 259 | ehthumbs_vista.db 260 | 261 | # Dump file 262 | *.stackdump 263 | 264 | # Folder config file 265 | [Dd]esktop.ini 266 | 267 | # Recycle Bin used on file shares 268 | $RECYCLE.BIN/ 269 | 270 | # Windows Installer files 271 | *.cab 272 | *.msi 273 | *.msix 274 | *.msm 275 | *.msp 276 | 277 | # Windows shortcuts 278 | *.lnk 279 | 280 | 281 | # End of https://www.gitignore.io/api/vim,java,linux,macos,maven,bazel,eclipse,windows,intellij+all,visualstudiocode 282 | -------------------------------------------------------------------------------- /junit-source-launcher/lib/DownloadRequiredModules.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2025 the original author or authors. 3 | * 4 | * All rights reserved. This program and the accompanying materials are 5 | * made available under the terms of the Eclipse Public License v2.0 which 6 | * accompanies this distribution and is available at 7 | * 8 | * https://www.eclipse.org/legal/epl-v20.html 9 | */ 10 | 11 | final Path lib = Path.of("lib"); // local directory to be used in module path 12 | final Set roots = Set.of("org.junit.start"); // single root module to lookup 13 | final String version = "6.1.0-M1"; // of JUnit Framework 14 | final String repository = "https://repo.maven.apache.org/maven2"; // of JUnit Framework 15 | final String lookup = 16 | //language=Properties 17 | """ 18 | org.apiguardian.api=https://repo.maven.apache.org/maven2/org/apiguardian/apiguardian-api/1.1.2/apiguardian-api-1.1.2.jar 19 | org.jspecify=https://repo.maven.apache.org/maven2/org/jspecify/jspecify/1.0.0/jspecify-1.0.0.jar 20 | org.junit.jupiter.api={{repository}}/org/junit/jupiter/junit-jupiter-api/{{version}}/junit-jupiter-api-{{version}}.jar 21 | org.junit.jupiter.engine={{repository}}/org/junit/jupiter/junit-jupiter-engine/{{version}}/junit-jupiter-engine-{{version}}.jar 22 | org.junit.jupiter.params={{repository}}/org/junit/jupiter/junit-jupiter-params/{{version}}/junit-jupiter-params-{{version}}.jar 23 | org.junit.jupiter={{repository}}/org/junit/jupiter/junit-jupiter/{{version}}/junit-jupiter-{{version}}.jar 24 | org.junit.platform.commons={{repository}}/org/junit/platform/junit-platform-commons/{{version}}/junit-platform-commons-{{version}}.jar 25 | org.junit.platform.console={{repository}}/org/junit/platform/junit-platform-console/{{version}}/junit-platform-console-{{version}}.jar 26 | org.junit.platform.engine={{repository}}/org/junit/platform/junit-platform-engine/{{version}}/junit-platform-engine-{{version}}.jar 27 | org.junit.platform.launcher={{repository}}/org/junit/platform/junit-platform-launcher/{{version}}/junit-platform-launcher-{{version}}.jar 28 | org.junit.platform.reporting={{repository}}/org/junit/platform/junit-platform-reporting/{{version}}/junit-platform-reporting-{{version}}.jar 29 | org.junit.platform.suite.api={{repository}}/org/junit/platform/junit-platform-suite-api/{{version}}/junit-platform-suite-api-{{version}}.jar 30 | org.junit.platform.suite.engine={{repository}}/org/junit/platform/junit-platform-suite-engine/{{version}}/junit-platform-suite-engine-{{version}}.jar 31 | org.junit.platform.suite={{repository}}/org/junit/platform/junit-platform-suite/{{version}}/junit-platform-suite-{{version}}.jar 32 | org.junit.start={{repository}}/org/junit/junit-start/{{version}}/junit-start-{{version}}.jar 33 | org.opentest4j.reporting.tooling.spi=https://repo.maven.apache.org/maven2/org/opentest4j/reporting/open-test-reporting-tooling-spi/0.2.5/open-test-reporting-tooling-spi-0.2.5.jar 34 | org.opentest4j=https://repo.maven.apache.org/maven2/org/opentest4j/opentest4j/1.3.0/opentest4j-1.3.0.jar 35 | """ 36 | .replace("{{repository}}", repository) 37 | .replace("{{version}}", version); 38 | 39 | void main() throws Exception { 40 | // Ensure being launched inside expected working directory 41 | var program = Path.of("src", "HelloTests.java"); 42 | if (!Files.exists(program)) { 43 | throw new AssertionError("Expected %s in current working directory".formatted(program)); 44 | } 45 | 46 | // Read mapping file to locate remote modules 47 | var properties = new Properties(); 48 | properties.load(new StringReader(lookup)); 49 | 50 | // Create and initialize lib directory with root module(s) 51 | Files.createDirectories(lib); 52 | downloadModules(roots, properties); 53 | 54 | // Compute missing modules and download them transitively 55 | var missing = computeMissingModuleNames(); 56 | while (!missing.isEmpty()) { 57 | downloadModules(missing, properties); 58 | missing = computeMissingModuleNames(); 59 | } 60 | 61 | IO.println("%nList modules of %s directory".formatted(lib)); 62 | listModules(); 63 | } 64 | 65 | void downloadModules(Set names, Properties properties) { 66 | IO.println("Downloading %d module%s".formatted(names.size(), names.size() == 1 ? "" : "s")); 67 | names.stream().parallel().forEach(name -> { 68 | var target = lib.resolve(name + ".jar"); 69 | if (Files.exists(target)) return; // Don't overwrite existing JAR file 70 | var source = URI.create(properties.getProperty(name)); 71 | try (var stream = source.toURL().openStream()) { 72 | IO.println(name + " <- " + source + "..."); 73 | Files.copy(stream, target); 74 | } catch (IOException cause) { 75 | throw new UncheckedIOException(cause); 76 | } 77 | }); 78 | // Ensure that every name can be found to avoid eternal loops 79 | var finder = ModuleFinder.of(lib); 80 | var remainder = new TreeSet<>(names); 81 | remainder.removeIf(name -> finder.find(name).isPresent()); 82 | if (remainder.isEmpty()) return; 83 | throw new AssertionError("Modules not downloaded: " + remainder); 84 | } 85 | 86 | Set computeMissingModuleNames() { 87 | var system = ModuleFinder.ofSystem(); 88 | var finder = ModuleFinder.of(lib); 89 | var names = 90 | finder.findAll().stream() 91 | .parallel() 92 | .map(ModuleReference::descriptor) 93 | .map(ModuleDescriptor::requires) 94 | .flatMap(Collection::stream) 95 | .filter(this::mustBePresentAtCompileTime) 96 | .map(ModuleDescriptor.Requires::name) 97 | .filter(name -> finder.find(name).isEmpty()) 98 | .filter(name -> system.find(name).isEmpty()) 99 | .toList(); 100 | return new TreeSet<>(names); 101 | } 102 | 103 | boolean mustBePresentAtCompileTime(ModuleDescriptor.Requires requires) { 104 | var isStatic = requires.modifiers().contains(ModuleDescriptor.Requires.Modifier.STATIC); 105 | var isTransitive = requires.modifiers().contains(ModuleDescriptor.Requires.Modifier.TRANSITIVE); 106 | return !isStatic || isTransitive; 107 | } 108 | 109 | void listModules() { 110 | var finder = ModuleFinder.of(lib); 111 | var modules = finder.findAll(); 112 | modules.stream() 113 | .map(ModuleReference::descriptor) 114 | .map(ModuleDescriptor::toNameAndVersion) 115 | .sorted() 116 | .forEach(IO::println); 117 | IO.println(" %d modules".formatted(modules.size())); 118 | } 119 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # JUnit Examples [![ci-badge]][ci-actions] 2 | 3 | Welcome to _JUnit Examples_, a collection of example applications and extensions 4 | using JUnit Jupiter, JUnit Vintage, and the JUnit Platform on various build systems. 5 | 6 | CI builds for example projects are performed by [GitHub Actions][ci-actions]. Using JDK 24+'s 7 | `java` multi-file source-code launcher feature, you may build all examples by running 8 | `java src/Builder.java` in the main directory of this project. 9 | 10 | ## Jupiter Starter Examples 11 | 12 | _Basic setups showing how to get started with JUnit Jupiter._ 13 | 14 | ### Jupiter on Ant ![badge-jdk-17] ![badge-tool-ant] ![badge-junit-jupiter] 15 | 16 | The [junit-jupiter-starter-ant] example demonstrates the bare minimum configuration for 17 | getting started with JUnit Jupiter using the Ant build system. 18 | 19 | ### Jupiter on Gradle ![badge-jdk-17] ![badge-tool-gradle] ![badge-junit-jupiter] 20 | 21 | The [junit-jupiter-starter-gradle] example demonstrates the bare minimum configuration for 22 | getting started with JUnit Jupiter using the Gradle build system. 23 | 24 | ### Jupiter on Gradle using Kotlin ![badge-jdk-17] ![badge-tool-gradle] ![badge-junit-jupiter] 25 | 26 | The [junit-jupiter-starter-gradle-kotlin] example demonstrates the bare minimum 27 | configuration for getting started with JUnit Jupiter using the Gradle build system and the 28 | Kotlin programming language. 29 | 30 | ### Jupiter on Gradle using Groovy ![badge-jdk-17] ![badge-tool-gradle] ![badge-junit-jupiter] 31 | 32 | The [junit-jupiter-starter-gradle-groovy] example demonstrates the bare minimum 33 | configuration for getting started with JUnit Jupiter using the Gradle build system and the 34 | Groovy programming language. 35 | 36 | ### Jupiter on Maven ![badge-jdk-17] ![badge-tool-maven] ![badge-junit-jupiter] 37 | 38 | The [junit-jupiter-starter-maven] example demonstrates the bare minimum configuration for 39 | getting started with JUnit Jupiter using the Maven build system. 40 | 41 | ### Jupiter on Maven using Kotlin ![badge-jdk-17] ![badge-tool-maven] ![badge-junit-jupiter] 42 | 43 | The [junit-jupiter-starter-maven-kotlin] example demonstrates the bare minimum configuration for 44 | getting started with JUnit Jupiter project using Maven build system and Kotlin programming language. 45 | 46 | ### Jupiter on Bazel ![badge-jdk-17] ![badge-tool-bazel] ![badge-junit-jupiter] 47 | 48 | The [junit-jupiter-starter-bazel] example demonstrates the bare minimum configuration for 49 | getting started with JUnit Jupiter using the Bazel build system. 50 | 51 | ### Jupiter on sbt ![badge-jdk-17] ![badge-tool-sbt] ![badge-junit-jupiter] 52 | 53 | The [junit-jupiter-starter-sbt] example demonstrates the bare minimum configuration for 54 | getting started with JUnit Jupiter using sbt and the Scala programming language. 55 | 56 | ## Jupiter Feature Examples 57 | 58 | _Extending JUnit Jupiter using its `Extension` API._ 59 | 60 | ### Sample Extensions ![badge-jdk-17] ![badge-tool-gradle] ![badge-junit-jupiter] 61 | 62 | The [junit-jupiter-extensions] example demonstrates how one can implement custom 63 | JUnit Jupiter extensions and use them in tests. 64 | 65 | 66 | ## Migration Examples 67 | 68 | _More complex setups how to integrate various parts of "JUnit 5" including a 69 | possible migration path for JUnit 3 or 4 based projects._ 70 | 71 | ### Gradle Migration ![badge-jdk-17] ![badge-tool-gradle] ![badge-junit-platform] ![badge-junit-jupiter] ![badge-junit-vintage] 72 | 73 | The [junit-migration-gradle] example demonstrates how to set up a Gradle project 74 | using the JUnit Platform, JUnit Jupiter, and JUnit Vintage. 75 | 76 | ### Maven Migration ![badge-jdk-17] ![badge-tool-maven] ![badge-junit-platform] ![badge-junit-jupiter] ![badge-junit-vintage] 77 | 78 | The [junit-migration-maven] example demonstrates how to set up a Maven project 79 | using the JUnit Platform, JUnit Jupiter, and JUnit Vintage. 80 | 81 | 82 | ## Platform Samples 83 | _Showing basic features of the JUnit Platform._ 84 | 85 | ### Multiple Engines ![badge-jdk-17] ![badge-tool-gradle] ![badge-junit-platform] ![badge-junit-jupiter] ![badge-junit-vintage] ... 86 | 87 | The [junit-multiple-engines] example demonstrates how to set up a Gradle project 88 | using the JUnit Platform with various [TestEngine][guide-custom-engine] implementations. 89 | 90 | ### Living in the Modular World ![badge-jdk-17] ![badge-tool-console] ![badge-junit-platform] 91 | 92 | The [junit-modular-world] example demonstrates how to test code organized in modules. 93 | This example also demonstrates how to implement a custom [TestEngine][guide-custom-engine] 94 | for the JUnit Platform using the Java Platform Module System. 95 | 96 | [junit-jupiter-extensions]: junit-jupiter-extensions 97 | [junit-jupiter-starter-ant]: junit-jupiter-starter-ant 98 | [junit-jupiter-starter-gradle]: junit-jupiter-starter-gradle 99 | [junit-jupiter-starter-gradle-groovy]: junit-jupiter-starter-gradle-groovy 100 | [junit-jupiter-starter-gradle-kotlin]: junit-jupiter-starter-gradle-kotlin 101 | [junit-jupiter-starter-maven]: junit-jupiter-starter-maven 102 | [junit-jupiter-starter-maven-kotlin]: junit-jupiter-starter-maven-kotlin 103 | [junit-jupiter-starter-bazel]: junit-jupiter-starter-bazel 104 | [junit-jupiter-starter-sbt]: junit-jupiter-starter-sbt 105 | [junit-migration-gradle]: junit-migration-gradle 106 | [junit-migration-maven]: junit-migration-maven 107 | [junit-multiple-engines]: junit-multiple-engines 108 | [junit-modular-world]: junit-modular-world 109 | 110 | [badge-jdk-17]: https://img.shields.io/badge/jdk-17-orange.svg "JDK-17" 111 | [badge-tool-ant]: https://img.shields.io/badge/tool-ant-aa167e.svg "Ant" 112 | [badge-tool-gradle]: https://img.shields.io/badge/tool-gradle-209bc4.svg "Gradle wrapper included" 113 | [badge-tool-maven]: https://img.shields.io/badge/tool-maven-0440af.svg "Maven wrapper included" 114 | [badge-tool-bazel]: https://img.shields.io/badge/tool-bazel-43a047.svg "Bazel" 115 | [badge-tool-sbt]: https://img.shields.io/badge/tool-sbt-4A34BC.svg "SBT" 116 | [badge-tool-console]: https://img.shields.io/badge/tool-console-022077.svg "Command line tools" 117 | [badge-junit-platform]: https://img.shields.io/badge/junit-platform-brightgreen.svg "JUnit Platform" 118 | [badge-junit-jupiter]: https://img.shields.io/badge/junit-jupiter-green.svg "JUnit Jupiter Engine" 119 | [badge-junit-vintage]: https://img.shields.io/badge/junit-vintage-yellowgreen.svg "JUnit Vintage Engine" 120 | 121 | [ci-badge]:https://github.com/junit-team/junit-examples/workflows/Build%20all%20examples/badge.svg "CI build status" 122 | [ci-actions]: https://github.com/junit-team/junit-examples/actions 123 | 124 | [guide-custom-engine]: https://docs.junit.org/current/user-guide/#launcher-api-engines-custom "Plugging in Your Own Test Engine" 125 | -------------------------------------------------------------------------------- /src/Builder.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2025 the original author or authors. 3 | * 4 | * All rights reserved. This program and the accompanying materials are 5 | * made available under the terms of the Eclipse Public License v2.0 which 6 | * accompanies this distribution and is available at 7 | * 8 | * https://www.eclipse.org/legal/epl-v20.html 9 | */ 10 | 11 | // default package 12 | 13 | import java.nio.file.Files; 14 | import java.nio.file.Path; 15 | import java.nio.file.Paths; 16 | import java.util.Arrays; 17 | import java.util.HashSet; 18 | import java.util.List; 19 | import java.util.Locale; 20 | import java.util.Set; 21 | 22 | /** 23 | * Platform-agnostic builder 24 | */ 25 | @SuppressWarnings({ "WeakerAccess", "SameParameterValue" }) 26 | class Builder { 27 | 28 | private static final String TARGET_OPTION = "--target="; 29 | private static final String EXCLUDE_OPTION = "--exclude="; 30 | 31 | public static void main(String[] args) { 32 | var target = determineTarget(args); 33 | var excludedProjects = determineExcludedProjects(args); 34 | var status = new Builder().build(target, excludedProjects); 35 | if (status != 0) { 36 | throw new AssertionError("Expected exit status of zero, but got: " + status); 37 | } 38 | } 39 | 40 | int status = 0; 41 | 42 | int build(Target target, Set excludedProjects) { 43 | System.out.printf("|%n| Building all samples (%s)...%n|%n", target); 44 | run(".", "java", "--version"); 45 | if (target == Target.TEST) { 46 | checkLicense("src/eclipse-public-license-2.0.java", ".java", ".kt", ".scala", ".groovy"); 47 | } 48 | 49 | var antTarget = target == Target.TEST ? "test" : "compile"; 50 | var gradleTask = target == Target.TEST ? "test" : "testClasses"; 51 | var mavenLifecycle = target == Target.TEST ? "test" : "test-compile"; 52 | var bazelTarget = target == Target.TEST ? "test" : "build"; 53 | var sbtTask = target == Target.TEST ? "test" : "Test / compile"; 54 | var modularAction = target == Target.TEST ? "src/build/Build.java" : "src/build/Compile.java"; 55 | 56 | // jupiter-starter 57 | if (!isWindows()) { // TODO https://github.com/junit-team/junit-examples/issues/66 58 | runProject(excludedProjects, "junit-jupiter-starter-ant", "build.sh", "clean", antTarget); 59 | } 60 | 61 | runProject(excludedProjects, "junit-jupiter-starter-gradle", "gradlew", gradleTask); 62 | runProject(excludedProjects, "junit-jupiter-starter-gradle-groovy", "gradlew", gradleTask); 63 | runProject(excludedProjects, "junit-jupiter-starter-gradle-kotlin", "gradlew", gradleTask); 64 | runProject(excludedProjects, "junit-jupiter-starter-maven", "mvnw", "--batch-mode", "clean", mavenLifecycle); 65 | runProject(excludedProjects, "junit-jupiter-starter-maven-kotlin", "mvnw", "--batch-mode", "clean", mavenLifecycle); 66 | runProject(excludedProjects, "junit-jupiter-starter-bazel", "bazel", bazelTarget, "//..."); 67 | runProject(excludedProjects, "junit-jupiter-starter-sbt", "sbt", sbtTask); 68 | 69 | // jupiter-extensions 70 | runProject(excludedProjects, "junit-jupiter-extensions", "gradlew", gradleTask); 71 | 72 | // migration 73 | runProject(excludedProjects, "junit-migration-gradle", "gradlew", gradleTask); 74 | runProject(excludedProjects, "junit-migration-maven", "mvnw", "--batch-mode", "clean", mavenLifecycle); 75 | runProject(excludedProjects, "junit-multiple-engines", "gradlew", gradleTask); 76 | 77 | // modular 78 | runProject(excludedProjects, "junit-modular-world", "java", modularAction); 79 | 80 | // source launcher 81 | runProject(excludedProjects, "junit-source-launcher", "java", "lib/DownloadRequiredModules.java"); 82 | runProject(excludedProjects, "junit-source-launcher", 83 | "java", 84 | "--module-path", "lib", 85 | "--add-modules", "org.junit.start", 86 | "src/HelloTests.java"); 87 | System.out.printf("%n%n%n|%n| Done. Build exits with status = %d.%n|%n", status); 88 | return status; 89 | } 90 | 91 | private static Target determineTarget(String[] args) { 92 | for (var arg : args) { 93 | if (arg.startsWith(TARGET_OPTION)) { 94 | return Target.valueOf(arg.substring(TARGET_OPTION.length()).toUpperCase(Locale.ROOT)); 95 | } 96 | } 97 | return Target.TEST; 98 | } 99 | 100 | private static Set determineExcludedProjects(String[] args) { 101 | Set excludedProjects = new HashSet<>(); 102 | for (var arg : args) { 103 | if (arg.startsWith(EXCLUDE_OPTION)) { 104 | excludedProjects.addAll(Set.of(arg.substring(EXCLUDE_OPTION.length()).split(","))); 105 | } 106 | } 107 | return Set.copyOf(excludedProjects); 108 | } 109 | 110 | void runProject(Set excludedProjects, String project, String executable, String... args) { 111 | if (excludedProjects.contains(project)) { 112 | System.out.printf("%n%n%n|%n| %s is excluded.%n|%n", project); 113 | return; 114 | } 115 | run(project, executable, args); 116 | } 117 | 118 | void run(String directory, String executable, String... args) { 119 | if (status != 0) { 120 | return; 121 | } 122 | System.out.printf("%n%n%n|%n| %s%n|%n", directory); 123 | System.out.printf("| %s %s%n|%n", executable, String.join(" ", args)); 124 | var path = Paths.get(directory); 125 | var isWindows = isWindows(); 126 | if (!isWindows) { 127 | if (Files.isExecutable(path.resolve(executable))) { 128 | executable = "./" + executable; 129 | } 130 | } 131 | var processBuilder = new ProcessBuilder(isWindows ? "cmd.exe" : executable); 132 | if (isWindows) { 133 | processBuilder.command().add("/C"); 134 | processBuilder.command().add(executable); 135 | } 136 | Arrays.stream(args).forEach(processBuilder.command()::add); 137 | processBuilder.directory(path.toFile()); 138 | processBuilder.redirectErrorStream(true); 139 | try { 140 | var process = processBuilder.start(); 141 | process.getInputStream().transferTo(System.out); 142 | status = process.waitFor(); 143 | } catch (Exception exception) { 144 | System.out.printf("%n%n%n| %s failed to build!%n", directory); 145 | exception.printStackTrace(System.err); 146 | status = 1; 147 | } 148 | } 149 | 150 | boolean isWindows() { 151 | return System.getProperty("os.name").toLowerCase(Locale.ROOT).startsWith("win"); 152 | } 153 | 154 | void checkLicense(String blueprint, String... extensions) { 155 | if (status != 0) { 156 | return; 157 | } 158 | System.out.printf("%n%n%n|%n| check license: %s%n|%n", blueprint); 159 | try { 160 | var expected = Files.readAllLines(Paths.get(blueprint)); 161 | var errors = 0; 162 | try (var paths = Files.walk(Paths.get(".")) 163 | .filter(path -> Arrays.stream(extensions).anyMatch(extension -> path.getFileName().toString().endsWith(extension))) 164 | .filter(path -> !path.getFileName().toString().equals("MavenWrapperDownloader.java"))) { 165 | for (var path : paths.toList()) { 166 | if (checkLicense(path, expected)) { 167 | continue; 168 | } 169 | System.out.printf("| %s%n", path); 170 | errors++; 171 | } 172 | } 173 | if (errors > 0) { 174 | System.out.printf("| %d file(s) with no or false license.%n", errors); 175 | status = 1; 176 | } 177 | } 178 | catch (Exception exception) { 179 | System.out.printf("%n%n%n| License `%s` check failed!%n", blueprint); 180 | exception.printStackTrace(System.err); 181 | status = 1; 182 | } 183 | } 184 | 185 | boolean checkLicense(Path path, List expected) throws Exception { 186 | var actual = Files.readAllLines(path); 187 | if (actual.size() >= expected.size()) { 188 | actual = actual.subList(0, expected.size()); 189 | return actual.equals(expected); 190 | } 191 | return false; 192 | } 193 | 194 | enum Target { 195 | COMPILE, TEST 196 | } 197 | } 198 | -------------------------------------------------------------------------------- /junit-migration-maven/mvnw.cmd: -------------------------------------------------------------------------------- 1 | <# : batch portion 2 | @REM ---------------------------------------------------------------------------- 3 | @REM Licensed to the Apache Software Foundation (ASF) under one 4 | @REM or more contributor license agreements. See the NOTICE file 5 | @REM distributed with this work for additional information 6 | @REM regarding copyright ownership. The ASF licenses this file 7 | @REM to you under the Apache License, Version 2.0 (the 8 | @REM "License"); you may not use this file except in compliance 9 | @REM with the License. You may obtain a copy of the License at 10 | @REM 11 | @REM http://www.apache.org/licenses/LICENSE-2.0 12 | @REM 13 | @REM Unless required by applicable law or agreed to in writing, 14 | @REM software distributed under the License is distributed on an 15 | @REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 | @REM KIND, either express or implied. See the License for the 17 | @REM specific language governing permissions and limitations 18 | @REM under the License. 19 | @REM ---------------------------------------------------------------------------- 20 | 21 | @REM ---------------------------------------------------------------------------- 22 | @REM Apache Maven Wrapper startup batch script, version 3.3.4 23 | @REM 24 | @REM Optional ENV vars 25 | @REM MVNW_REPOURL - repo url base for downloading maven distribution 26 | @REM MVNW_USERNAME/MVNW_PASSWORD - user and password for downloading maven 27 | @REM MVNW_VERBOSE - true: enable verbose log; others: silence the output 28 | @REM ---------------------------------------------------------------------------- 29 | 30 | @IF "%__MVNW_ARG0_NAME__%"=="" (SET __MVNW_ARG0_NAME__=%~nx0) 31 | @SET __MVNW_CMD__= 32 | @SET __MVNW_ERROR__= 33 | @SET __MVNW_PSMODULEP_SAVE=%PSModulePath% 34 | @SET PSModulePath= 35 | @FOR /F "usebackq tokens=1* delims==" %%A IN (`powershell -noprofile "& {$scriptDir='%~dp0'; $script='%__MVNW_ARG0_NAME__%'; icm -ScriptBlock ([Scriptblock]::Create((Get-Content -Raw '%~f0'))) -NoNewScope}"`) DO @( 36 | IF "%%A"=="MVN_CMD" (set __MVNW_CMD__=%%B) ELSE IF "%%B"=="" (echo %%A) ELSE (echo %%A=%%B) 37 | ) 38 | @SET PSModulePath=%__MVNW_PSMODULEP_SAVE% 39 | @SET __MVNW_PSMODULEP_SAVE= 40 | @SET __MVNW_ARG0_NAME__= 41 | @SET MVNW_USERNAME= 42 | @SET MVNW_PASSWORD= 43 | @IF NOT "%__MVNW_CMD__%"=="" ("%__MVNW_CMD__%" %*) 44 | @echo Cannot start maven from wrapper >&2 && exit /b 1 45 | @GOTO :EOF 46 | : end batch / begin powershell #> 47 | 48 | $ErrorActionPreference = "Stop" 49 | if ($env:MVNW_VERBOSE -eq "true") { 50 | $VerbosePreference = "Continue" 51 | } 52 | 53 | # calculate distributionUrl, requires .mvn/wrapper/maven-wrapper.properties 54 | $distributionUrl = (Get-Content -Raw "$scriptDir/.mvn/wrapper/maven-wrapper.properties" | ConvertFrom-StringData).distributionUrl 55 | if (!$distributionUrl) { 56 | Write-Error "cannot read distributionUrl property in $scriptDir/.mvn/wrapper/maven-wrapper.properties" 57 | } 58 | 59 | switch -wildcard -casesensitive ( $($distributionUrl -replace '^.*/','') ) { 60 | "maven-mvnd-*" { 61 | $USE_MVND = $true 62 | $distributionUrl = $distributionUrl -replace '-bin\.[^.]*$',"-windows-amd64.zip" 63 | $MVN_CMD = "mvnd.cmd" 64 | break 65 | } 66 | default { 67 | $USE_MVND = $false 68 | $MVN_CMD = $script -replace '^mvnw','mvn' 69 | break 70 | } 71 | } 72 | 73 | # apply MVNW_REPOURL and calculate MAVEN_HOME 74 | # maven home pattern: ~/.m2/wrapper/dists/{apache-maven-,maven-mvnd--}/ 75 | if ($env:MVNW_REPOURL) { 76 | $MVNW_REPO_PATTERN = if ($USE_MVND -eq $False) { "/org/apache/maven/" } else { "/maven/mvnd/" } 77 | $distributionUrl = "$env:MVNW_REPOURL$MVNW_REPO_PATTERN$($distributionUrl -replace "^.*$MVNW_REPO_PATTERN",'')" 78 | } 79 | $distributionUrlName = $distributionUrl -replace '^.*/','' 80 | $distributionUrlNameMain = $distributionUrlName -replace '\.[^.]*$','' -replace '-bin$','' 81 | 82 | $MAVEN_M2_PATH = "$HOME/.m2" 83 | if ($env:MAVEN_USER_HOME) { 84 | $MAVEN_M2_PATH = "$env:MAVEN_USER_HOME" 85 | } 86 | 87 | if (-not (Test-Path -Path $MAVEN_M2_PATH)) { 88 | New-Item -Path $MAVEN_M2_PATH -ItemType Directory | Out-Null 89 | } 90 | 91 | $MAVEN_WRAPPER_DISTS = $null 92 | if ((Get-Item $MAVEN_M2_PATH).Target[0] -eq $null) { 93 | $MAVEN_WRAPPER_DISTS = "$MAVEN_M2_PATH/wrapper/dists" 94 | } else { 95 | $MAVEN_WRAPPER_DISTS = (Get-Item $MAVEN_M2_PATH).Target[0] + "/wrapper/dists" 96 | } 97 | 98 | $MAVEN_HOME_PARENT = "$MAVEN_WRAPPER_DISTS/$distributionUrlNameMain" 99 | $MAVEN_HOME_NAME = ([System.Security.Cryptography.SHA256]::Create().ComputeHash([byte[]][char[]]$distributionUrl) | ForEach-Object {$_.ToString("x2")}) -join '' 100 | $MAVEN_HOME = "$MAVEN_HOME_PARENT/$MAVEN_HOME_NAME" 101 | 102 | if (Test-Path -Path "$MAVEN_HOME" -PathType Container) { 103 | Write-Verbose "found existing MAVEN_HOME at $MAVEN_HOME" 104 | Write-Output "MVN_CMD=$MAVEN_HOME/bin/$MVN_CMD" 105 | exit $? 106 | } 107 | 108 | if (! $distributionUrlNameMain -or ($distributionUrlName -eq $distributionUrlNameMain)) { 109 | Write-Error "distributionUrl is not valid, must end with *-bin.zip, but found $distributionUrl" 110 | } 111 | 112 | # prepare tmp dir 113 | $TMP_DOWNLOAD_DIR_HOLDER = New-TemporaryFile 114 | $TMP_DOWNLOAD_DIR = New-Item -Itemtype Directory -Path "$TMP_DOWNLOAD_DIR_HOLDER.dir" 115 | $TMP_DOWNLOAD_DIR_HOLDER.Delete() | Out-Null 116 | trap { 117 | if ($TMP_DOWNLOAD_DIR.Exists) { 118 | try { Remove-Item $TMP_DOWNLOAD_DIR -Recurse -Force | Out-Null } 119 | catch { Write-Warning "Cannot remove $TMP_DOWNLOAD_DIR" } 120 | } 121 | } 122 | 123 | New-Item -Itemtype Directory -Path "$MAVEN_HOME_PARENT" -Force | Out-Null 124 | 125 | # Download and Install Apache Maven 126 | Write-Verbose "Couldn't find MAVEN_HOME, downloading and installing it ..." 127 | Write-Verbose "Downloading from: $distributionUrl" 128 | Write-Verbose "Downloading to: $TMP_DOWNLOAD_DIR/$distributionUrlName" 129 | 130 | $webclient = New-Object System.Net.WebClient 131 | if ($env:MVNW_USERNAME -and $env:MVNW_PASSWORD) { 132 | $webclient.Credentials = New-Object System.Net.NetworkCredential($env:MVNW_USERNAME, $env:MVNW_PASSWORD) 133 | } 134 | [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12 135 | $webclient.DownloadFile($distributionUrl, "$TMP_DOWNLOAD_DIR/$distributionUrlName") | Out-Null 136 | 137 | # If specified, validate the SHA-256 sum of the Maven distribution zip file 138 | $distributionSha256Sum = (Get-Content -Raw "$scriptDir/.mvn/wrapper/maven-wrapper.properties" | ConvertFrom-StringData).distributionSha256Sum 139 | if ($distributionSha256Sum) { 140 | if ($USE_MVND) { 141 | Write-Error "Checksum validation is not supported for maven-mvnd. `nPlease disable validation by removing 'distributionSha256Sum' from your maven-wrapper.properties." 142 | } 143 | Import-Module $PSHOME\Modules\Microsoft.PowerShell.Utility -Function Get-FileHash 144 | if ((Get-FileHash "$TMP_DOWNLOAD_DIR/$distributionUrlName" -Algorithm SHA256).Hash.ToLower() -ne $distributionSha256Sum) { 145 | Write-Error "Error: Failed to validate Maven distribution SHA-256, your Maven distribution might be compromised. If you updated your Maven version, you need to update the specified distributionSha256Sum property." 146 | } 147 | } 148 | 149 | # unzip and move 150 | Expand-Archive "$TMP_DOWNLOAD_DIR/$distributionUrlName" -DestinationPath "$TMP_DOWNLOAD_DIR" | Out-Null 151 | 152 | # Find the actual extracted directory name (handles snapshots where filename != directory name) 153 | $actualDistributionDir = "" 154 | 155 | # First try the expected directory name (for regular distributions) 156 | $expectedPath = Join-Path "$TMP_DOWNLOAD_DIR" "$distributionUrlNameMain" 157 | $expectedMvnPath = Join-Path "$expectedPath" "bin/$MVN_CMD" 158 | if ((Test-Path -Path $expectedPath -PathType Container) -and (Test-Path -Path $expectedMvnPath -PathType Leaf)) { 159 | $actualDistributionDir = $distributionUrlNameMain 160 | } 161 | 162 | # If not found, search for any directory with the Maven executable (for snapshots) 163 | if (!$actualDistributionDir) { 164 | Get-ChildItem -Path "$TMP_DOWNLOAD_DIR" -Directory | ForEach-Object { 165 | $testPath = Join-Path $_.FullName "bin/$MVN_CMD" 166 | if (Test-Path -Path $testPath -PathType Leaf) { 167 | $actualDistributionDir = $_.Name 168 | } 169 | } 170 | } 171 | 172 | if (!$actualDistributionDir) { 173 | Write-Error "Could not find Maven distribution directory in extracted archive" 174 | } 175 | 176 | Write-Verbose "Found extracted Maven distribution directory: $actualDistributionDir" 177 | Rename-Item -Path "$TMP_DOWNLOAD_DIR/$actualDistributionDir" -NewName $MAVEN_HOME_NAME | Out-Null 178 | try { 179 | Move-Item -Path "$TMP_DOWNLOAD_DIR/$MAVEN_HOME_NAME" -Destination $MAVEN_HOME_PARENT | Out-Null 180 | } catch { 181 | if (! (Test-Path -Path "$MAVEN_HOME" -PathType Container)) { 182 | Write-Error "fail to move MAVEN_HOME" 183 | } 184 | } finally { 185 | try { Remove-Item $TMP_DOWNLOAD_DIR -Recurse -Force | Out-Null } 186 | catch { Write-Warning "Cannot remove $TMP_DOWNLOAD_DIR" } 187 | } 188 | 189 | Write-Output "MVN_CMD=$MAVEN_HOME/bin/$MVN_CMD" 190 | -------------------------------------------------------------------------------- /junit-jupiter-starter-maven/mvnw.cmd: -------------------------------------------------------------------------------- 1 | <# : batch portion 2 | @REM ---------------------------------------------------------------------------- 3 | @REM Licensed to the Apache Software Foundation (ASF) under one 4 | @REM or more contributor license agreements. See the NOTICE file 5 | @REM distributed with this work for additional information 6 | @REM regarding copyright ownership. The ASF licenses this file 7 | @REM to you under the Apache License, Version 2.0 (the 8 | @REM "License"); you may not use this file except in compliance 9 | @REM with the License. You may obtain a copy of the License at 10 | @REM 11 | @REM http://www.apache.org/licenses/LICENSE-2.0 12 | @REM 13 | @REM Unless required by applicable law or agreed to in writing, 14 | @REM software distributed under the License is distributed on an 15 | @REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 | @REM KIND, either express or implied. See the License for the 17 | @REM specific language governing permissions and limitations 18 | @REM under the License. 19 | @REM ---------------------------------------------------------------------------- 20 | 21 | @REM ---------------------------------------------------------------------------- 22 | @REM Apache Maven Wrapper startup batch script, version 3.3.4 23 | @REM 24 | @REM Optional ENV vars 25 | @REM MVNW_REPOURL - repo url base for downloading maven distribution 26 | @REM MVNW_USERNAME/MVNW_PASSWORD - user and password for downloading maven 27 | @REM MVNW_VERBOSE - true: enable verbose log; others: silence the output 28 | @REM ---------------------------------------------------------------------------- 29 | 30 | @IF "%__MVNW_ARG0_NAME__%"=="" (SET __MVNW_ARG0_NAME__=%~nx0) 31 | @SET __MVNW_CMD__= 32 | @SET __MVNW_ERROR__= 33 | @SET __MVNW_PSMODULEP_SAVE=%PSModulePath% 34 | @SET PSModulePath= 35 | @FOR /F "usebackq tokens=1* delims==" %%A IN (`powershell -noprofile "& {$scriptDir='%~dp0'; $script='%__MVNW_ARG0_NAME__%'; icm -ScriptBlock ([Scriptblock]::Create((Get-Content -Raw '%~f0'))) -NoNewScope}"`) DO @( 36 | IF "%%A"=="MVN_CMD" (set __MVNW_CMD__=%%B) ELSE IF "%%B"=="" (echo %%A) ELSE (echo %%A=%%B) 37 | ) 38 | @SET PSModulePath=%__MVNW_PSMODULEP_SAVE% 39 | @SET __MVNW_PSMODULEP_SAVE= 40 | @SET __MVNW_ARG0_NAME__= 41 | @SET MVNW_USERNAME= 42 | @SET MVNW_PASSWORD= 43 | @IF NOT "%__MVNW_CMD__%"=="" ("%__MVNW_CMD__%" %*) 44 | @echo Cannot start maven from wrapper >&2 && exit /b 1 45 | @GOTO :EOF 46 | : end batch / begin powershell #> 47 | 48 | $ErrorActionPreference = "Stop" 49 | if ($env:MVNW_VERBOSE -eq "true") { 50 | $VerbosePreference = "Continue" 51 | } 52 | 53 | # calculate distributionUrl, requires .mvn/wrapper/maven-wrapper.properties 54 | $distributionUrl = (Get-Content -Raw "$scriptDir/.mvn/wrapper/maven-wrapper.properties" | ConvertFrom-StringData).distributionUrl 55 | if (!$distributionUrl) { 56 | Write-Error "cannot read distributionUrl property in $scriptDir/.mvn/wrapper/maven-wrapper.properties" 57 | } 58 | 59 | switch -wildcard -casesensitive ( $($distributionUrl -replace '^.*/','') ) { 60 | "maven-mvnd-*" { 61 | $USE_MVND = $true 62 | $distributionUrl = $distributionUrl -replace '-bin\.[^.]*$',"-windows-amd64.zip" 63 | $MVN_CMD = "mvnd.cmd" 64 | break 65 | } 66 | default { 67 | $USE_MVND = $false 68 | $MVN_CMD = $script -replace '^mvnw','mvn' 69 | break 70 | } 71 | } 72 | 73 | # apply MVNW_REPOURL and calculate MAVEN_HOME 74 | # maven home pattern: ~/.m2/wrapper/dists/{apache-maven-,maven-mvnd--}/ 75 | if ($env:MVNW_REPOURL) { 76 | $MVNW_REPO_PATTERN = if ($USE_MVND -eq $False) { "/org/apache/maven/" } else { "/maven/mvnd/" } 77 | $distributionUrl = "$env:MVNW_REPOURL$MVNW_REPO_PATTERN$($distributionUrl -replace "^.*$MVNW_REPO_PATTERN",'')" 78 | } 79 | $distributionUrlName = $distributionUrl -replace '^.*/','' 80 | $distributionUrlNameMain = $distributionUrlName -replace '\.[^.]*$','' -replace '-bin$','' 81 | 82 | $MAVEN_M2_PATH = "$HOME/.m2" 83 | if ($env:MAVEN_USER_HOME) { 84 | $MAVEN_M2_PATH = "$env:MAVEN_USER_HOME" 85 | } 86 | 87 | if (-not (Test-Path -Path $MAVEN_M2_PATH)) { 88 | New-Item -Path $MAVEN_M2_PATH -ItemType Directory | Out-Null 89 | } 90 | 91 | $MAVEN_WRAPPER_DISTS = $null 92 | if ((Get-Item $MAVEN_M2_PATH).Target[0] -eq $null) { 93 | $MAVEN_WRAPPER_DISTS = "$MAVEN_M2_PATH/wrapper/dists" 94 | } else { 95 | $MAVEN_WRAPPER_DISTS = (Get-Item $MAVEN_M2_PATH).Target[0] + "/wrapper/dists" 96 | } 97 | 98 | $MAVEN_HOME_PARENT = "$MAVEN_WRAPPER_DISTS/$distributionUrlNameMain" 99 | $MAVEN_HOME_NAME = ([System.Security.Cryptography.SHA256]::Create().ComputeHash([byte[]][char[]]$distributionUrl) | ForEach-Object {$_.ToString("x2")}) -join '' 100 | $MAVEN_HOME = "$MAVEN_HOME_PARENT/$MAVEN_HOME_NAME" 101 | 102 | if (Test-Path -Path "$MAVEN_HOME" -PathType Container) { 103 | Write-Verbose "found existing MAVEN_HOME at $MAVEN_HOME" 104 | Write-Output "MVN_CMD=$MAVEN_HOME/bin/$MVN_CMD" 105 | exit $? 106 | } 107 | 108 | if (! $distributionUrlNameMain -or ($distributionUrlName -eq $distributionUrlNameMain)) { 109 | Write-Error "distributionUrl is not valid, must end with *-bin.zip, but found $distributionUrl" 110 | } 111 | 112 | # prepare tmp dir 113 | $TMP_DOWNLOAD_DIR_HOLDER = New-TemporaryFile 114 | $TMP_DOWNLOAD_DIR = New-Item -Itemtype Directory -Path "$TMP_DOWNLOAD_DIR_HOLDER.dir" 115 | $TMP_DOWNLOAD_DIR_HOLDER.Delete() | Out-Null 116 | trap { 117 | if ($TMP_DOWNLOAD_DIR.Exists) { 118 | try { Remove-Item $TMP_DOWNLOAD_DIR -Recurse -Force | Out-Null } 119 | catch { Write-Warning "Cannot remove $TMP_DOWNLOAD_DIR" } 120 | } 121 | } 122 | 123 | New-Item -Itemtype Directory -Path "$MAVEN_HOME_PARENT" -Force | Out-Null 124 | 125 | # Download and Install Apache Maven 126 | Write-Verbose "Couldn't find MAVEN_HOME, downloading and installing it ..." 127 | Write-Verbose "Downloading from: $distributionUrl" 128 | Write-Verbose "Downloading to: $TMP_DOWNLOAD_DIR/$distributionUrlName" 129 | 130 | $webclient = New-Object System.Net.WebClient 131 | if ($env:MVNW_USERNAME -and $env:MVNW_PASSWORD) { 132 | $webclient.Credentials = New-Object System.Net.NetworkCredential($env:MVNW_USERNAME, $env:MVNW_PASSWORD) 133 | } 134 | [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12 135 | $webclient.DownloadFile($distributionUrl, "$TMP_DOWNLOAD_DIR/$distributionUrlName") | Out-Null 136 | 137 | # If specified, validate the SHA-256 sum of the Maven distribution zip file 138 | $distributionSha256Sum = (Get-Content -Raw "$scriptDir/.mvn/wrapper/maven-wrapper.properties" | ConvertFrom-StringData).distributionSha256Sum 139 | if ($distributionSha256Sum) { 140 | if ($USE_MVND) { 141 | Write-Error "Checksum validation is not supported for maven-mvnd. `nPlease disable validation by removing 'distributionSha256Sum' from your maven-wrapper.properties." 142 | } 143 | Import-Module $PSHOME\Modules\Microsoft.PowerShell.Utility -Function Get-FileHash 144 | if ((Get-FileHash "$TMP_DOWNLOAD_DIR/$distributionUrlName" -Algorithm SHA256).Hash.ToLower() -ne $distributionSha256Sum) { 145 | Write-Error "Error: Failed to validate Maven distribution SHA-256, your Maven distribution might be compromised. If you updated your Maven version, you need to update the specified distributionSha256Sum property." 146 | } 147 | } 148 | 149 | # unzip and move 150 | Expand-Archive "$TMP_DOWNLOAD_DIR/$distributionUrlName" -DestinationPath "$TMP_DOWNLOAD_DIR" | Out-Null 151 | 152 | # Find the actual extracted directory name (handles snapshots where filename != directory name) 153 | $actualDistributionDir = "" 154 | 155 | # First try the expected directory name (for regular distributions) 156 | $expectedPath = Join-Path "$TMP_DOWNLOAD_DIR" "$distributionUrlNameMain" 157 | $expectedMvnPath = Join-Path "$expectedPath" "bin/$MVN_CMD" 158 | if ((Test-Path -Path $expectedPath -PathType Container) -and (Test-Path -Path $expectedMvnPath -PathType Leaf)) { 159 | $actualDistributionDir = $distributionUrlNameMain 160 | } 161 | 162 | # If not found, search for any directory with the Maven executable (for snapshots) 163 | if (!$actualDistributionDir) { 164 | Get-ChildItem -Path "$TMP_DOWNLOAD_DIR" -Directory | ForEach-Object { 165 | $testPath = Join-Path $_.FullName "bin/$MVN_CMD" 166 | if (Test-Path -Path $testPath -PathType Leaf) { 167 | $actualDistributionDir = $_.Name 168 | } 169 | } 170 | } 171 | 172 | if (!$actualDistributionDir) { 173 | Write-Error "Could not find Maven distribution directory in extracted archive" 174 | } 175 | 176 | Write-Verbose "Found extracted Maven distribution directory: $actualDistributionDir" 177 | Rename-Item -Path "$TMP_DOWNLOAD_DIR/$actualDistributionDir" -NewName $MAVEN_HOME_NAME | Out-Null 178 | try { 179 | Move-Item -Path "$TMP_DOWNLOAD_DIR/$MAVEN_HOME_NAME" -Destination $MAVEN_HOME_PARENT | Out-Null 180 | } catch { 181 | if (! (Test-Path -Path "$MAVEN_HOME" -PathType Container)) { 182 | Write-Error "fail to move MAVEN_HOME" 183 | } 184 | } finally { 185 | try { Remove-Item $TMP_DOWNLOAD_DIR -Recurse -Force | Out-Null } 186 | catch { Write-Warning "Cannot remove $TMP_DOWNLOAD_DIR" } 187 | } 188 | 189 | Write-Output "MVN_CMD=$MAVEN_HOME/bin/$MVN_CMD" 190 | -------------------------------------------------------------------------------- /junit-jupiter-starter-maven-kotlin/mvnw.cmd: -------------------------------------------------------------------------------- 1 | <# : batch portion 2 | @REM ---------------------------------------------------------------------------- 3 | @REM Licensed to the Apache Software Foundation (ASF) under one 4 | @REM or more contributor license agreements. See the NOTICE file 5 | @REM distributed with this work for additional information 6 | @REM regarding copyright ownership. The ASF licenses this file 7 | @REM to you under the Apache License, Version 2.0 (the 8 | @REM "License"); you may not use this file except in compliance 9 | @REM with the License. You may obtain a copy of the License at 10 | @REM 11 | @REM http://www.apache.org/licenses/LICENSE-2.0 12 | @REM 13 | @REM Unless required by applicable law or agreed to in writing, 14 | @REM software distributed under the License is distributed on an 15 | @REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 | @REM KIND, either express or implied. See the License for the 17 | @REM specific language governing permissions and limitations 18 | @REM under the License. 19 | @REM ---------------------------------------------------------------------------- 20 | 21 | @REM ---------------------------------------------------------------------------- 22 | @REM Apache Maven Wrapper startup batch script, version 3.3.4 23 | @REM 24 | @REM Optional ENV vars 25 | @REM MVNW_REPOURL - repo url base for downloading maven distribution 26 | @REM MVNW_USERNAME/MVNW_PASSWORD - user and password for downloading maven 27 | @REM MVNW_VERBOSE - true: enable verbose log; others: silence the output 28 | @REM ---------------------------------------------------------------------------- 29 | 30 | @IF "%__MVNW_ARG0_NAME__%"=="" (SET __MVNW_ARG0_NAME__=%~nx0) 31 | @SET __MVNW_CMD__= 32 | @SET __MVNW_ERROR__= 33 | @SET __MVNW_PSMODULEP_SAVE=%PSModulePath% 34 | @SET PSModulePath= 35 | @FOR /F "usebackq tokens=1* delims==" %%A IN (`powershell -noprofile "& {$scriptDir='%~dp0'; $script='%__MVNW_ARG0_NAME__%'; icm -ScriptBlock ([Scriptblock]::Create((Get-Content -Raw '%~f0'))) -NoNewScope}"`) DO @( 36 | IF "%%A"=="MVN_CMD" (set __MVNW_CMD__=%%B) ELSE IF "%%B"=="" (echo %%A) ELSE (echo %%A=%%B) 37 | ) 38 | @SET PSModulePath=%__MVNW_PSMODULEP_SAVE% 39 | @SET __MVNW_PSMODULEP_SAVE= 40 | @SET __MVNW_ARG0_NAME__= 41 | @SET MVNW_USERNAME= 42 | @SET MVNW_PASSWORD= 43 | @IF NOT "%__MVNW_CMD__%"=="" ("%__MVNW_CMD__%" %*) 44 | @echo Cannot start maven from wrapper >&2 && exit /b 1 45 | @GOTO :EOF 46 | : end batch / begin powershell #> 47 | 48 | $ErrorActionPreference = "Stop" 49 | if ($env:MVNW_VERBOSE -eq "true") { 50 | $VerbosePreference = "Continue" 51 | } 52 | 53 | # calculate distributionUrl, requires .mvn/wrapper/maven-wrapper.properties 54 | $distributionUrl = (Get-Content -Raw "$scriptDir/.mvn/wrapper/maven-wrapper.properties" | ConvertFrom-StringData).distributionUrl 55 | if (!$distributionUrl) { 56 | Write-Error "cannot read distributionUrl property in $scriptDir/.mvn/wrapper/maven-wrapper.properties" 57 | } 58 | 59 | switch -wildcard -casesensitive ( $($distributionUrl -replace '^.*/','') ) { 60 | "maven-mvnd-*" { 61 | $USE_MVND = $true 62 | $distributionUrl = $distributionUrl -replace '-bin\.[^.]*$',"-windows-amd64.zip" 63 | $MVN_CMD = "mvnd.cmd" 64 | break 65 | } 66 | default { 67 | $USE_MVND = $false 68 | $MVN_CMD = $script -replace '^mvnw','mvn' 69 | break 70 | } 71 | } 72 | 73 | # apply MVNW_REPOURL and calculate MAVEN_HOME 74 | # maven home pattern: ~/.m2/wrapper/dists/{apache-maven-,maven-mvnd--}/ 75 | if ($env:MVNW_REPOURL) { 76 | $MVNW_REPO_PATTERN = if ($USE_MVND -eq $False) { "/org/apache/maven/" } else { "/maven/mvnd/" } 77 | $distributionUrl = "$env:MVNW_REPOURL$MVNW_REPO_PATTERN$($distributionUrl -replace "^.*$MVNW_REPO_PATTERN",'')" 78 | } 79 | $distributionUrlName = $distributionUrl -replace '^.*/','' 80 | $distributionUrlNameMain = $distributionUrlName -replace '\.[^.]*$','' -replace '-bin$','' 81 | 82 | $MAVEN_M2_PATH = "$HOME/.m2" 83 | if ($env:MAVEN_USER_HOME) { 84 | $MAVEN_M2_PATH = "$env:MAVEN_USER_HOME" 85 | } 86 | 87 | if (-not (Test-Path -Path $MAVEN_M2_PATH)) { 88 | New-Item -Path $MAVEN_M2_PATH -ItemType Directory | Out-Null 89 | } 90 | 91 | $MAVEN_WRAPPER_DISTS = $null 92 | if ((Get-Item $MAVEN_M2_PATH).Target[0] -eq $null) { 93 | $MAVEN_WRAPPER_DISTS = "$MAVEN_M2_PATH/wrapper/dists" 94 | } else { 95 | $MAVEN_WRAPPER_DISTS = (Get-Item $MAVEN_M2_PATH).Target[0] + "/wrapper/dists" 96 | } 97 | 98 | $MAVEN_HOME_PARENT = "$MAVEN_WRAPPER_DISTS/$distributionUrlNameMain" 99 | $MAVEN_HOME_NAME = ([System.Security.Cryptography.SHA256]::Create().ComputeHash([byte[]][char[]]$distributionUrl) | ForEach-Object {$_.ToString("x2")}) -join '' 100 | $MAVEN_HOME = "$MAVEN_HOME_PARENT/$MAVEN_HOME_NAME" 101 | 102 | if (Test-Path -Path "$MAVEN_HOME" -PathType Container) { 103 | Write-Verbose "found existing MAVEN_HOME at $MAVEN_HOME" 104 | Write-Output "MVN_CMD=$MAVEN_HOME/bin/$MVN_CMD" 105 | exit $? 106 | } 107 | 108 | if (! $distributionUrlNameMain -or ($distributionUrlName -eq $distributionUrlNameMain)) { 109 | Write-Error "distributionUrl is not valid, must end with *-bin.zip, but found $distributionUrl" 110 | } 111 | 112 | # prepare tmp dir 113 | $TMP_DOWNLOAD_DIR_HOLDER = New-TemporaryFile 114 | $TMP_DOWNLOAD_DIR = New-Item -Itemtype Directory -Path "$TMP_DOWNLOAD_DIR_HOLDER.dir" 115 | $TMP_DOWNLOAD_DIR_HOLDER.Delete() | Out-Null 116 | trap { 117 | if ($TMP_DOWNLOAD_DIR.Exists) { 118 | try { Remove-Item $TMP_DOWNLOAD_DIR -Recurse -Force | Out-Null } 119 | catch { Write-Warning "Cannot remove $TMP_DOWNLOAD_DIR" } 120 | } 121 | } 122 | 123 | New-Item -Itemtype Directory -Path "$MAVEN_HOME_PARENT" -Force | Out-Null 124 | 125 | # Download and Install Apache Maven 126 | Write-Verbose "Couldn't find MAVEN_HOME, downloading and installing it ..." 127 | Write-Verbose "Downloading from: $distributionUrl" 128 | Write-Verbose "Downloading to: $TMP_DOWNLOAD_DIR/$distributionUrlName" 129 | 130 | $webclient = New-Object System.Net.WebClient 131 | if ($env:MVNW_USERNAME -and $env:MVNW_PASSWORD) { 132 | $webclient.Credentials = New-Object System.Net.NetworkCredential($env:MVNW_USERNAME, $env:MVNW_PASSWORD) 133 | } 134 | [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12 135 | $webclient.DownloadFile($distributionUrl, "$TMP_DOWNLOAD_DIR/$distributionUrlName") | Out-Null 136 | 137 | # If specified, validate the SHA-256 sum of the Maven distribution zip file 138 | $distributionSha256Sum = (Get-Content -Raw "$scriptDir/.mvn/wrapper/maven-wrapper.properties" | ConvertFrom-StringData).distributionSha256Sum 139 | if ($distributionSha256Sum) { 140 | if ($USE_MVND) { 141 | Write-Error "Checksum validation is not supported for maven-mvnd. `nPlease disable validation by removing 'distributionSha256Sum' from your maven-wrapper.properties." 142 | } 143 | Import-Module $PSHOME\Modules\Microsoft.PowerShell.Utility -Function Get-FileHash 144 | if ((Get-FileHash "$TMP_DOWNLOAD_DIR/$distributionUrlName" -Algorithm SHA256).Hash.ToLower() -ne $distributionSha256Sum) { 145 | Write-Error "Error: Failed to validate Maven distribution SHA-256, your Maven distribution might be compromised. If you updated your Maven version, you need to update the specified distributionSha256Sum property." 146 | } 147 | } 148 | 149 | # unzip and move 150 | Expand-Archive "$TMP_DOWNLOAD_DIR/$distributionUrlName" -DestinationPath "$TMP_DOWNLOAD_DIR" | Out-Null 151 | 152 | # Find the actual extracted directory name (handles snapshots where filename != directory name) 153 | $actualDistributionDir = "" 154 | 155 | # First try the expected directory name (for regular distributions) 156 | $expectedPath = Join-Path "$TMP_DOWNLOAD_DIR" "$distributionUrlNameMain" 157 | $expectedMvnPath = Join-Path "$expectedPath" "bin/$MVN_CMD" 158 | if ((Test-Path -Path $expectedPath -PathType Container) -and (Test-Path -Path $expectedMvnPath -PathType Leaf)) { 159 | $actualDistributionDir = $distributionUrlNameMain 160 | } 161 | 162 | # If not found, search for any directory with the Maven executable (for snapshots) 163 | if (!$actualDistributionDir) { 164 | Get-ChildItem -Path "$TMP_DOWNLOAD_DIR" -Directory | ForEach-Object { 165 | $testPath = Join-Path $_.FullName "bin/$MVN_CMD" 166 | if (Test-Path -Path $testPath -PathType Leaf) { 167 | $actualDistributionDir = $_.Name 168 | } 169 | } 170 | } 171 | 172 | if (!$actualDistributionDir) { 173 | Write-Error "Could not find Maven distribution directory in extracted archive" 174 | } 175 | 176 | Write-Verbose "Found extracted Maven distribution directory: $actualDistributionDir" 177 | Rename-Item -Path "$TMP_DOWNLOAD_DIR/$actualDistributionDir" -NewName $MAVEN_HOME_NAME | Out-Null 178 | try { 179 | Move-Item -Path "$TMP_DOWNLOAD_DIR/$MAVEN_HOME_NAME" -Destination $MAVEN_HOME_PARENT | Out-Null 180 | } catch { 181 | if (! (Test-Path -Path "$MAVEN_HOME" -PathType Container)) { 182 | Write-Error "fail to move MAVEN_HOME" 183 | } 184 | } finally { 185 | try { Remove-Item $TMP_DOWNLOAD_DIR -Recurse -Force | Out-Null } 186 | catch { Write-Warning "Cannot remove $TMP_DOWNLOAD_DIR" } 187 | } 188 | 189 | Write-Output "MVN_CMD=$MAVEN_HOME/bin/$MVN_CMD" 190 | --------------------------------------------------------------------------------