├── .github ├── dependabot.yml └── workflows │ ├── auto-merge.yml │ └── build.yml ├── .gitignore ├── LICENSE ├── README.md ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── junit3 ├── pom.xml └── src │ ├── main │ └── resources │ │ └── logback.xml │ └── test │ └── java │ └── io │ └── github │ └── bonigarcia │ ├── TestAll.java │ ├── TestMinimal.java │ └── TestSimple.java ├── junit4-cucumber ├── pom.xml └── src │ ├── main │ ├── java │ │ └── io │ │ │ └── github │ │ │ └── bonigarcia │ │ │ ├── Book.java │ │ │ ├── Calculator.java │ │ │ └── Library.java │ └── resources │ │ └── io │ │ └── github │ │ └── bonigarcia │ │ ├── calculator.feature │ │ └── search.feature │ └── test │ └── java │ └── io │ └── github │ └── bonigarcia │ ├── BookSearchSteps.java │ ├── CalculatorSteps.java │ └── CucumberTest.java ├── junit4-mockito ├── pom.xml └── src │ ├── main │ ├── java │ │ └── io │ │ │ └── github │ │ │ └── bonigarcia │ │ │ ├── LoginController.java │ │ │ ├── LoginException.java │ │ │ ├── LoginRepository.java │ │ │ ├── LoginService.java │ │ │ └── UserForm.java │ └── resources │ │ └── logback.xml │ └── test │ └── java │ └── io │ └── github │ └── bonigarcia │ ├── LoginControllerBDDTest.java │ ├── LoginControllerTest.java │ ├── LoginServiceChaptorTest.java │ ├── LoginServiceSpyTest.java │ └── LoginServiceTest.java ├── junit4-spring-boot ├── pom.xml └── src │ ├── main │ ├── java │ │ └── io │ │ │ └── github │ │ │ └── bonigarcia │ │ │ ├── MessageComponent.java │ │ │ ├── MessageService.java │ │ │ └── MySpringBootApplication.java │ └── resources │ │ └── logback.xml │ └── test │ └── java │ └── io │ └── github │ └── bonigarcia │ └── SimpleSpringBootTest.java ├── junit4-spring ├── pom.xml └── src │ ├── main │ ├── java │ │ └── io │ │ │ └── github │ │ │ └── bonigarcia │ │ │ ├── MessageComponent.java │ │ │ ├── MessageService.java │ │ │ └── MySpringApplication.java │ └── resources │ │ └── logback.xml │ └── test │ └── java │ └── io │ └── github │ └── bonigarcia │ └── SimpleSpringTest.java ├── junit4 ├── pom.xml └── src │ ├── main │ └── resources │ │ └── logback.xml │ └── test │ └── java │ └── io │ └── github │ └── bonigarcia │ ├── FunctionalTests.java │ ├── MySuite.java │ ├── MyTheoryTest.java │ ├── NonFunctionalTests.java │ ├── TestAssumptions.java │ ├── TestCategories.java │ ├── TestCategoriesSuite.java │ ├── TestClassRule.java │ ├── TestIgnore.java │ ├── TestMinimal1.java │ ├── TestMinimal2.java │ ├── TestOrder.java │ ├── TestParameterized.java │ ├── TestParameterizedConstructor.java │ ├── TestRuleChain.java │ ├── TestRuleErrorCollector.java │ ├── TestRuleExpectedException.java │ ├── TestRuleExternalResource.java │ ├── TestRuleName.java │ ├── TestRuleTemporaryFolder.java │ ├── TestRuleTimeout.java │ ├── TestRuleWatcher.java │ ├── TestSimple.java │ ├── TestTimeout.java │ └── TestWithTimeout.java ├── junit5-allure ├── README.md ├── build.gradle ├── pom.xml └── src │ └── test │ └── java │ └── io │ └── github │ └── bonigarcia │ ├── DisplayNameTest.java │ ├── PlayingWithAllureTest.java │ └── SimpleJUnit5Test.java ├── junit5-android ├── app │ ├── .gitignore │ ├── build.gradle │ └── src │ │ ├── androidTest │ │ └── java │ │ │ └── io │ │ │ └── github │ │ │ └── bonigarcia │ │ │ └── myapplication │ │ │ └── InstrumentedTest.java │ │ ├── main │ │ ├── AndroidManifest.xml │ │ ├── java │ │ │ └── io │ │ │ │ └── github │ │ │ │ └── bonigarcia │ │ │ │ └── myapplication │ │ │ │ └── MainActivity.java │ │ └── res │ │ │ ├── layout │ │ │ └── activity_main.xml │ │ │ ├── mipmap-hdpi │ │ │ ├── ic_launcher.png │ │ │ └── ic_launcher_round.png │ │ │ ├── mipmap-mdpi │ │ │ ├── ic_launcher.png │ │ │ └── ic_launcher_round.png │ │ │ ├── mipmap-xhdpi │ │ │ ├── ic_launcher.png │ │ │ └── ic_launcher_round.png │ │ │ ├── mipmap-xxhdpi │ │ │ ├── ic_launcher.png │ │ │ └── ic_launcher_round.png │ │ │ ├── mipmap-xxxhdpi │ │ │ ├── ic_launcher.png │ │ │ └── ic_launcher_round.png │ │ │ └── values │ │ │ ├── colors.xml │ │ │ ├── strings.xml │ │ │ └── styles.xml │ │ └── test │ │ └── java │ │ └── io │ │ └── github │ │ └── bonigarcia │ │ └── myapplication │ │ ├── ExampleJUnit5Test.java │ │ └── JUnit4Test.java ├── build.gradle ├── gradle.properties ├── gradlew ├── gradlew.bat └── settings.gradle ├── junit5-assertions ├── build.gradle ├── pom.xml └── src │ ├── main │ ├── java │ │ └── io │ │ │ └── github │ │ │ └── bonigarcia │ │ │ ├── Address.java │ │ │ └── MySUT.java │ └── resources │ │ └── logback.xml │ └── test │ └── java │ └── io │ └── github │ └── bonigarcia │ ├── AssertJTest.java │ ├── ExceptionTest.java │ ├── GroupedAssertionsTest.java │ ├── HamcrestTest.java │ ├── StandardAssertionsTest.java │ ├── TimeoutExceededTest.java │ ├── TimeoutWithPreemptiveTerminationTest.java │ ├── TimeoutWithResultOrMethodTest.java │ └── TruthTest.java ├── junit5-basic-tests ├── build.gradle ├── pom.xml └── src │ ├── main │ ├── java │ │ └── io │ │ │ └── github │ │ │ └── bonigarcia │ │ │ └── MySUT.java │ └── resources │ │ └── logback.xml │ └── test │ └── java │ └── io │ └── github │ └── bonigarcia │ ├── BasicPerClassTest.java │ ├── BasicTest.java │ ├── DisplayNameTest.java │ ├── LifecyclePerClassTest.java │ └── LifecycleTest.java ├── junit5-console-launcher ├── build.gradle ├── pom.xml └── src │ └── main │ ├── java │ └── io │ │ └── github │ │ └── bonigarcia │ │ └── EmptyTest.java │ └── resources │ └── logback.xml ├── junit5-cucumber-selenium ├── build.gradle ├── pom.xml └── src │ ├── main │ └── resources │ │ └── logback.xml │ └── test │ ├── java │ └── io │ │ └── github │ │ └── bonigarcia │ │ ├── CucumberTest.java │ │ └── LoginSteps.java │ └── resources │ ├── io │ └── github │ │ └── bonigarcia │ │ └── login.feature │ └── junit-platform.properties ├── junit5-cucumber ├── build.gradle ├── pom.xml └── src │ ├── main │ ├── java │ │ └── io │ │ │ └── github │ │ │ └── bonigarcia │ │ │ └── Calculator.java │ └── resources │ │ └── logback.xml │ └── test │ ├── java │ └── io │ │ └── github │ │ └── bonigarcia │ │ ├── CalculatorSteps.java │ │ └── CucumberTest.java │ └── resources │ ├── io │ └── github │ │ └── bonigarcia │ │ └── calculator.feature │ └── junit-platform.properties ├── junit5-dependency-injection ├── build.gradle ├── pom.xml └── src │ ├── main │ └── resources │ │ └── logback.xml │ └── test │ └── java │ └── io │ └── github │ └── bonigarcia │ ├── RepetitionInfoTest.java │ ├── TestInfoTest.java │ ├── TestReporterTest.java │ └── TmpDirTest.java ├── junit5-disabled-tests ├── build.gradle ├── pom.xml └── src │ ├── main │ ├── java │ │ └── io │ │ │ └── github │ │ │ └── bonigarcia │ │ │ └── MySUT.java │ └── resources │ │ └── logback.xml │ └── test │ └── java │ └── io │ └── github │ └── bonigarcia │ ├── AssumptionsTest.java │ ├── DisabledAllTest.java │ ├── DisabledIfTest.java │ ├── DisabledOnJreRangeTest.java │ ├── DisabledOnOsTest.java │ └── DisabledTest.java ├── junit5-docker ├── build.gradle ├── pom.xml └── src │ ├── main │ └── resources │ │ └── logback.xml │ └── test │ └── java │ └── io │ └── github │ └── bonigarcia │ └── DockerTest.java ├── junit5-dynamic-tests ├── build.gradle ├── pom.xml └── src │ ├── main │ └── resources │ │ └── logback.xml │ └── test │ └── java │ └── io │ └── github │ └── bonigarcia │ ├── CollectionTest.java │ ├── DynamicExampleTest.java │ └── StreamExampleTest.java ├── junit5-engine-spi ├── build.gradle ├── pom.xml └── src │ └── main │ └── java │ └── io │ └── github │ └── bonigarcia │ └── MyCustomEngine.java ├── junit5-extension-model-automatic ├── build.gradle ├── pom.xml └── src │ ├── main │ ├── java │ │ └── io │ │ │ └── github │ │ │ └── bonigarcia │ │ │ └── MyExtension.java │ └── resources │ │ ├── META-INF │ │ └── services │ │ │ └── org.junit.jupiter.api.extension.Extension │ │ └── logback.xml │ └── test │ ├── java │ └── io │ │ └── github │ │ └── bonigarcia │ │ └── MyTest.java │ └── resources │ └── junit-platform.properties ├── junit5-extension-model ├── build.gradle ├── pom.xml └── src │ ├── main │ └── resources │ │ └── logback.xml │ └── test │ └── java │ └── io │ └── github │ └── bonigarcia │ ├── DependencyInjectionTest.java │ ├── ExceptionTest.java │ ├── IgnoreIOExceptionExtension.java │ └── MyParameterResolver.java ├── junit5-failsafe ├── pom.xml └── src │ └── test │ └── java │ └── io │ └── github │ └── bonigarcia │ ├── ExecutedByFailsafePluginIT.java │ └── ExecutedBySurefirePluginTest.java ├── junit5-junit4-runner ├── build.gradle ├── pom.xml └── src │ ├── main │ └── resources │ │ └── logback.xml │ └── test │ └── java │ └── io │ └── github │ └── bonigarcia │ └── JUnit5CompatibleTest.java ├── junit5-launcher-api ├── build.gradle ├── pom.xml └── src │ └── test │ └── java │ └── io │ └── github │ └── bonigarcia │ ├── DummyTest.java │ └── LauncherApiExample.java ├── junit5-meta-annotations ├── build.gradle ├── pom.xml └── src │ ├── main │ ├── java │ │ └── io │ │ │ └── github │ │ │ └── bonigarcia │ │ │ ├── Accessibility.java │ │ │ ├── Functional.java │ │ │ ├── Load.java │ │ │ ├── Security.java │ │ │ ├── Stress.java │ │ │ └── Usability.java │ └── resources │ │ └── logback.xml │ └── test │ └── java │ └── io │ └── github │ └── bonigarcia │ ├── FunctionalTest.java │ └── NonFunctionalTest.java ├── junit5-migration-support ├── build.gradle ├── pom.xml └── src │ ├── main │ └── resources │ │ └── logback.xml │ └── test │ └── java │ └── io │ └── github │ └── bonigarcia │ ├── ErrorCollectorRuleTest.java │ ├── ExpectedExceptionRuleTest.java │ └── TemporaryFolderRuleTest.java ├── junit5-mockito ├── build.gradle ├── pom.xml └── src │ ├── main │ ├── java │ │ └── io │ │ │ └── github │ │ │ └── bonigarcia │ │ │ ├── LoginController.java │ │ │ ├── LoginException.java │ │ │ ├── LoginRepository.java │ │ │ ├── LoginService.java │ │ │ └── UserForm.java │ └── resources │ │ └── logback.xml │ └── test │ └── java │ └── io │ └── github │ └── bonigarcia │ ├── LoginControllerBDDTest.java │ ├── LoginControllerErrorTest.java │ ├── LoginControllerLoginTest.java │ ├── LoginServiceChaptorTest.java │ ├── LoginServiceSpyTest.java │ └── LoginServiceTest.java ├── junit5-nested-tests ├── build.gradle ├── pom.xml └── src │ ├── main │ └── resources │ │ └── logback.xml │ └── test │ └── java │ └── io │ └── github │ └── bonigarcia │ ├── NestTest.java │ └── StackTest.java ├── junit5-ordered-tests ├── build.gradle ├── pom.xml └── src │ ├── main │ └── resources │ │ └── logback.xml │ └── test │ └── java │ └── io │ └── github │ └── bonigarcia │ ├── CustomOrderedTest.java │ ├── NameOrderedTest.java │ └── OrderedTest.java ├── junit5-parallel-execution ├── build.gradle ├── pom.xml └── src │ ├── main │ └── resources │ │ └── logback-test.xml │ └── test │ ├── java │ └── io │ │ └── github │ │ └── bonigarcia │ │ ├── IsolatedTest.java │ │ ├── ParallelExecution01Test.java │ │ ├── ParallelExecution02Test.java │ │ └── ParallelExecutionTest.java │ └── resources │ └── junit-platform.properties ├── junit5-parameterized ├── build.gradle ├── pom.xml └── src │ ├── main │ └── resources │ │ └── logback.xml │ └── test │ ├── java │ └── io │ │ └── github │ │ └── bonigarcia │ │ ├── ArgumentSourceParameterizedTest.java │ │ ├── ArgumentSourcesParameterizedTest.java │ │ ├── CsvFileSourceParameterizedTest.java │ │ ├── CsvSourceParameterizedTest.java │ │ ├── CustomArgumentsConverter.java │ │ ├── CustomArgumentsProvider1.java │ │ ├── CustomArgumentsProvider2.java │ │ ├── CustomNamesParameterizedTest.java │ │ ├── EmptySourceParameterizedTest.java │ │ ├── EnumSourceFilteringParameterizedTest.java │ │ ├── EnumSourceParameterizedTest.java │ │ ├── ExplicitConversionParameterizedTest.java │ │ ├── ImplicitConversionParameterizedTest.java │ │ ├── MethodSourceMixedTypesParameterizedTest.java │ │ ├── MethodSourceObjectsParameterizedTest.java │ │ ├── MethodSourcePrimitiveTypesParameterizedTest.java │ │ ├── MethodSourceStringsParameterizedTest.java │ │ ├── NullAndEmptySourceParameterizedTest.java │ │ ├── NullSourceParameterizedTest.java │ │ ├── ValueSourcePrimitiveTypesParameterizedTest.java │ │ └── ValueSourceStringsParameterizedTest.java │ └── resources │ └── input.csv ├── junit5-repeated-tests ├── build.gradle ├── pom.xml └── src │ ├── main │ └── resources │ │ └── logback.xml │ └── test │ └── java │ └── io │ └── github │ └── bonigarcia │ ├── RepetitionInfoInRepeatedTest.java │ ├── SimpleRepeatedTest.java │ └── TunningDisplayInRepeatedTest.java ├── junit5-reporting ├── build.gradle ├── pom.xml └── src │ └── test │ └── java │ └── io │ └── github │ └── bonigarcia │ └── PlayingWithReportingTest.java ├── junit5-rest-assured ├── build.gradle ├── pom.xml └── src │ └── test │ └── java │ └── io │ └── github │ └── bonigarcia │ └── PublicRestServicesTest.java ├── junit5-selenium ├── build.gradle ├── pom.xml └── src │ ├── main │ └── resources │ │ └── logback.xml │ └── test │ └── java │ └── io │ └── github │ └── bonigarcia │ ├── LocalWebDriverTest.java │ └── RemoteWebDriverTest.java ├── junit5-spring-boot-rest ├── build.gradle ├── pom.xml └── src │ ├── main │ ├── java │ │ └── io │ │ │ └── github │ │ │ └── bonigarcia │ │ │ ├── Book.java │ │ │ ├── LibraryService.java │ │ │ ├── MyRestController.java │ │ │ └── SpringBootRestApp.java │ └── resources │ │ ├── logback.xml │ │ └── static │ │ ├── index.html │ │ └── page.html │ └── test │ └── java │ └── io │ └── github │ └── bonigarcia │ └── SpringBootRestTest.java ├── junit5-spring-boot-web ├── build.gradle ├── pom.xml └── src │ ├── main │ ├── java │ │ └── io │ │ │ └── github │ │ │ └── bonigarcia │ │ │ ├── PageService.java │ │ │ ├── SpringBootWebApp.java │ │ │ └── WebController.java │ └── resources │ │ ├── logback.xml │ │ └── static │ │ ├── index.html │ │ └── page.html │ └── test │ └── java │ └── io │ └── github │ └── bonigarcia │ ├── IndexTest.java │ ├── OutOfContainerTest.java │ └── RedirectTest.java ├── junit5-spring-boot ├── build.gradle ├── pom.xml └── src │ ├── main │ ├── java │ │ └── io │ │ │ └── github │ │ │ └── bonigarcia │ │ │ ├── MessageComponent.java │ │ │ ├── MessageService.java │ │ │ └── MySpringBootApplication.java │ └── resources │ │ └── logback.xml │ └── test │ └── java │ └── io │ └── github │ └── bonigarcia │ └── SimpleSpringBootTest.java ├── junit5-spring ├── build.gradle ├── pom.xml └── src │ ├── main │ ├── java │ │ └── io │ │ │ └── github │ │ │ └── bonigarcia │ │ │ ├── MessageComponent.java │ │ │ ├── MessageService.java │ │ │ └── MySpringApplication.java │ └── resources │ │ └── logback.xml │ └── test │ └── java │ └── io │ └── github │ └── bonigarcia │ └── SimpleSpringTest.java ├── junit5-tagging-filtering ├── build.gradle ├── pom.xml └── src │ ├── main │ └── resources │ │ └── logback.xml │ └── test │ └── java │ └── io │ └── github │ └── bonigarcia │ ├── FunctionalTest.java │ └── NonFunctionalTest.java ├── junit5-test-interfaces ├── build.gradle ├── pom.xml └── src │ ├── main │ ├── java │ │ └── io │ │ │ └── github │ │ │ └── bonigarcia │ │ │ ├── TestInterfaceDynamicTestsDemo.java │ │ │ ├── TestLifecycleLogger.java │ │ │ ├── TimeExecutionLogger.java │ │ │ └── TimingExtension.java │ └── resources │ │ └── logback.xml │ └── test │ └── java │ └── io │ └── github │ └── bonigarcia │ └── TestInterfaceTest.java ├── junit5-test-templates ├── build.gradle ├── pom.xml └── src │ ├── main │ └── resources │ │ └── logback.xml │ └── test │ └── java │ └── io │ └── github │ └── bonigarcia │ ├── MyTestTemplateInvocationContextProvider.java │ └── TemplateTest.java ├── junit5-vintage ├── build.gradle ├── pom.xml └── src │ ├── main │ └── resources │ │ └── logback.xml │ └── test │ └── java │ └── io │ └── github │ └── bonigarcia │ └── LegacyJUnit4Test.java ├── junit5-wiremock ├── build.gradle ├── pom.xml └── src │ ├── main │ ├── java │ │ └── io │ │ │ └── github │ │ │ └── bonigarcia │ │ │ ├── RemoteFileApi.java │ │ │ └── RemoteFileService.java │ └── resources │ │ └── logback.xml │ └── test │ └── java │ └── io │ └── github │ └── bonigarcia │ └── RemoteFileTest.java ├── pom.xml └── settings.gradle /.github/dependabot.yml: -------------------------------------------------------------------------------- 1 | version: 2 2 | updates: 3 | - package-ecosystem: maven 4 | directory: "/" 5 | schedule: 6 | interval: daily 7 | time: '06:00' 8 | open-pull-requests-limit: 99 9 | 10 | - package-ecosystem: gradle 11 | directory: "/" 12 | schedule: 13 | interval: daily 14 | time: '06:00' 15 | open-pull-requests-limit: 99 16 | 17 | - package-ecosystem: github-actions 18 | directory: "/" 19 | schedule: 20 | interval: daily 21 | time: '06:00' 22 | open-pull-requests-limit: 99 23 | -------------------------------------------------------------------------------- /.github/workflows/auto-merge.yml: -------------------------------------------------------------------------------- 1 | name: Dependabot auto-merge 2 | on: pull_request 3 | 4 | permissions: 5 | contents: write 6 | pull-requests: write 7 | 8 | jobs: 9 | dependabot: 10 | runs-on: ubuntu-latest 11 | if: ${{ github.actor == 'dependabot[bot]' }} 12 | steps: 13 | - name: Dependabot metadata 14 | id: metadata 15 | uses: dependabot/fetch-metadata@v2.4.0 16 | with: 17 | github-token: "${{ secrets.GITHUB_TOKEN }}" 18 | - name: Enable auto-merge for Dependabot PRs 19 | run: | 20 | max_retries=10 21 | retry_count=0 22 | sleep_duration=1 23 | while ! gh pr merge "$PR_URL" --auto --squash --body="Co-authored-by: Boni Garcia "; do 24 | retry_count=$((retry_count+1)) 25 | if [ $retry_count -ge $max_retries ]; then 26 | echo "Command failed after $retry_count attempts." 27 | exit 1 28 | fi 29 | echo "Command failed. Retrying in $sleep_duration seconds..." 30 | sleep $sleep_duration 31 | sleep_duration=$((sleep_duration * 2)) # Exponential backoff 32 | done 33 | echo "Command succeeded after $retry_count attempts." 34 | env: 35 | PR_URL: ${{github.event.pull_request.html_url}} 36 | GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}} 37 | -------------------------------------------------------------------------------- /.github/workflows/build.yml: -------------------------------------------------------------------------------- 1 | name: build 2 | 3 | on: 4 | push: 5 | branches: [ master ] 6 | pull_request: 7 | branches: [ master ] 8 | 9 | env: 10 | DISPLAY: :99 11 | 12 | jobs: 13 | tests: 14 | strategy: 15 | matrix: 16 | build-tool: [ mvn ] 17 | os: [ ubuntu-latest ] 18 | java: [ 17 ] 19 | runs-on: ${{ matrix.os }} 20 | steps: 21 | - name: Checkout GitHub repo 22 | uses: actions/checkout@v4 23 | - name: Set up Java ${{ matrix.java }} 24 | uses: actions/setup-java@v4 25 | with: 26 | distribution: 'temurin' 27 | java-version: ${{ matrix.java }} 28 | - name: Start Xvfb 29 | run: Xvfb :99 & 30 | - name: Run tests with ${{ matrix.build-tool }} 31 | run: ${{ matrix.build-tool }} test -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *~ 2 | target 3 | .classpath 4 | .project 5 | .settings 6 | .metadata 7 | .gradle 8 | .idea 9 | .allure 10 | *.iml 11 | build 12 | allure-results 13 | bin 14 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bonigarcia/mastering-junit5/e0ccdf96da5699198112869e98f79e41b96ae56f/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionBase=GRADLE_USER_HOME 2 | distributionPath=wrapper/dists 3 | distributionUrl=https\://services.gradle.org/distributions/gradle-7.0.2-bin.zip 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | -------------------------------------------------------------------------------- /junit3/src/main/resources/logback.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | %d{yyyy-MM-dd HH:mm:ss} [%thread] %-5level %logger{36}.%M\(%line\) -- %msg%n 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /junit3/src/test/java/io/github/bonigarcia/TestAll.java: -------------------------------------------------------------------------------- 1 | /* 2 | * (C) Copyright 2017 Boni Garcia (https://bonigarcia.github.io/) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | */ 17 | package io.github.bonigarcia; 18 | 19 | import junit.framework.Test; 20 | import junit.framework.TestSuite; 21 | 22 | public class TestAll { 23 | 24 | public static Test suite() { 25 | TestSuite suite = new TestSuite("All tests"); 26 | suite.addTestSuite(TestSimple.class); 27 | suite.addTestSuite(TestMinimal.class); 28 | return suite; 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /junit3/src/test/java/io/github/bonigarcia/TestMinimal.java: -------------------------------------------------------------------------------- 1 | /* 2 | * (C) Copyright 2017 Boni Garcia (https://bonigarcia.github.io/) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | */ 17 | package io.github.bonigarcia; 18 | 19 | import junit.framework.TestCase; 20 | 21 | public class TestMinimal extends TestCase { 22 | 23 | public void test() { 24 | assertTrue(true); 25 | } 26 | 27 | } 28 | -------------------------------------------------------------------------------- /junit4-cucumber/src/main/resources/io/github/bonigarcia/calculator.feature: -------------------------------------------------------------------------------- 1 | Feature: Basic Arithmetic 2 | 3 | Background: A Calculator 4 | Given a calculator I just turned on 5 | 6 | Scenario: Addition 7 | When I add 4 and 5 8 | Then the result is 9 9 | 10 | Scenario: Substraction 11 | When I substract 7 to 2 12 | Then the result is 5 13 | -------------------------------------------------------------------------------- /junit4-cucumber/src/main/resources/io/github/bonigarcia/search.feature: -------------------------------------------------------------------------------- 1 | Feature: Book search 2 | To allow customers to find books, the library must offer seek methods. 3 | 4 | Scenario: Search books by publication year 5 | Given a book with the title 'The Hobbit', written by 'J. R. R. Tolkien', published in '21-09-1937' 6 | And a book with the title 'A Confederacy of Dunces', written by 'John Kennedy Toole', published in '01-04-1980' 7 | And a book with the title 'A Game of Thrones (A Song of Ice and Fire)', written by 'George R.R. Martin', published in '01-08-1996' 8 | When the customer searches for books published between '1980' and '2000' 9 | Then 2 books should have been found 10 | And Book 1 should have the title 'A Game of Thrones (A Song of Ice and Fire)' 11 | And Book 2 should have the title 'A Confederacy of Dunces' 12 | -------------------------------------------------------------------------------- /junit4-cucumber/src/test/java/io/github/bonigarcia/CalculatorSteps.java: -------------------------------------------------------------------------------- 1 | package io.github.bonigarcia; 2 | 3 | import static org.junit.Assert.assertEquals; 4 | 5 | import io.cucumber.java.en.Given; 6 | import io.cucumber.java.en.Then; 7 | import io.cucumber.java.en.When; 8 | 9 | public class CalculatorSteps { 10 | private Calculator calc; 11 | 12 | @Given("^a calculator I just turned on$") 13 | public void setup() { 14 | calc = new Calculator(); 15 | } 16 | 17 | @When("^I add (\\d+) and (\\d+)$") 18 | public void add(int arg1, int arg2) { 19 | calc.push(arg1); 20 | calc.push(arg2); 21 | calc.push("+"); 22 | } 23 | 24 | @When("^I substract (\\d+) to (\\d+)$") 25 | public void substract(int arg1, int arg2) { 26 | calc.push(arg1); 27 | calc.push(arg2); 28 | calc.push("-"); 29 | } 30 | 31 | @Then("^the result is (\\d+)$") 32 | public void the_result_is(double expected) { 33 | assertEquals(expected, calc.value()); 34 | } 35 | 36 | } 37 | -------------------------------------------------------------------------------- /junit4-cucumber/src/test/java/io/github/bonigarcia/CucumberTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * (C) Copyright 2017 Boni Garcia (https://bonigarcia.github.io/) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | */ 17 | package io.github.bonigarcia; 18 | 19 | import org.junit.runner.RunWith; 20 | 21 | import io.cucumber.junit.Cucumber; 22 | import io.cucumber.junit.CucumberOptions; 23 | 24 | @RunWith(Cucumber.class) 25 | @CucumberOptions(plugin = { "pretty" }) 26 | public class CucumberTest { 27 | } 28 | -------------------------------------------------------------------------------- /junit4-mockito/src/main/java/io/github/bonigarcia/LoginException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * (C) Copyright 2017 Boni Garcia (https://bonigarcia.github.io/) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | */ 17 | package io.github.bonigarcia; 18 | 19 | public class LoginException extends RuntimeException { 20 | 21 | private static final long serialVersionUID = 1L; 22 | 23 | public LoginException(String cause) { 24 | super(cause); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /junit4-mockito/src/main/java/io/github/bonigarcia/UserForm.java: -------------------------------------------------------------------------------- 1 | /* 2 | * (C) Copyright 2017 Boni Garcia (https://bonigarcia.github.io/) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | */ 17 | package io.github.bonigarcia; 18 | 19 | public class UserForm { 20 | 21 | public String password; 22 | public String username; 23 | 24 | public UserForm(String username, String password) { 25 | this.username = username; 26 | this.password = password; 27 | } 28 | 29 | public String getPassword() { 30 | return password; 31 | } 32 | 33 | public void setPassword(String password) { 34 | this.password = password; 35 | } 36 | 37 | public String getUsername() { 38 | return username; 39 | } 40 | 41 | public void setUsername(String username) { 42 | this.username = username; 43 | } 44 | 45 | @Override 46 | public String toString() { 47 | return "UserForm [password=" + password + ", username=" + username 48 | + "]"; 49 | } 50 | 51 | } -------------------------------------------------------------------------------- /junit4-mockito/src/main/resources/logback.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | %d{yyyy-MM-dd HH:mm:ss} [%thread] %-5level %logger{36}.%M\(%line\) -- %msg%n 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /junit4-spring-boot/src/main/java/io/github/bonigarcia/MessageComponent.java: -------------------------------------------------------------------------------- 1 | /* 2 | * (C) Copyright 2017 Boni Garcia (https://bonigarcia.github.io/) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | */ 17 | package io.github.bonigarcia; 18 | 19 | import org.springframework.beans.factory.annotation.Autowired; 20 | import org.springframework.stereotype.Component; 21 | 22 | @Component 23 | public class MessageComponent { 24 | 25 | @Autowired 26 | private MessageService messageService; 27 | 28 | public String getMessage() { 29 | return messageService.getMessage(); 30 | } 31 | } -------------------------------------------------------------------------------- /junit4-spring-boot/src/main/java/io/github/bonigarcia/MessageService.java: -------------------------------------------------------------------------------- 1 | /* 2 | * (C) Copyright 2017 Boni Garcia (https://bonigarcia.github.io/) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | */ 17 | package io.github.bonigarcia; 18 | 19 | import org.springframework.stereotype.Component; 20 | 21 | @Component 22 | public class MessageService { 23 | 24 | public String getMessage() { 25 | return "Hello world!"; 26 | } 27 | 28 | } -------------------------------------------------------------------------------- /junit4-spring-boot/src/main/resources/logback.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /junit4-spring-boot/src/test/java/io/github/bonigarcia/SimpleSpringBootTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * (C) Copyright 2017 Boni Garcia (https://bonigarcia.github.io/) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | */ 17 | package io.github.bonigarcia; 18 | 19 | import static org.junit.Assert.assertEquals; 20 | 21 | import org.junit.Test; 22 | import org.junit.runner.RunWith; 23 | import org.springframework.beans.factory.annotation.Autowired; 24 | import org.springframework.boot.test.context.SpringBootTest; 25 | import org.springframework.test.context.junit4.SpringRunner; 26 | 27 | @RunWith(SpringRunner.class) 28 | @SpringBootTest 29 | public class SimpleSpringBootTest { 30 | 31 | @Autowired 32 | public MessageComponent messageComponent; 33 | 34 | @Test 35 | public void test() { 36 | assertEquals("Hello world!", messageComponent.getMessage()); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /junit4-spring/src/main/java/io/github/bonigarcia/MessageComponent.java: -------------------------------------------------------------------------------- 1 | /* 2 | * (C) Copyright 2017 Boni Garcia (https://bonigarcia.github.io/) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | */ 17 | package io.github.bonigarcia; 18 | 19 | import org.springframework.beans.factory.annotation.Autowired; 20 | import org.springframework.stereotype.Component; 21 | 22 | @Component 23 | public class MessageComponent { 24 | 25 | @Autowired 26 | private MessageService messageService; 27 | 28 | public String getMessage() { 29 | return messageService.getMessage(); 30 | } 31 | } -------------------------------------------------------------------------------- /junit4-spring/src/main/java/io/github/bonigarcia/MessageService.java: -------------------------------------------------------------------------------- 1 | /* 2 | * (C) Copyright 2017 Boni Garcia (https://bonigarcia.github.io/) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | */ 17 | package io.github.bonigarcia; 18 | 19 | import org.springframework.stereotype.Component; 20 | 21 | @Component 22 | public class MessageService { 23 | 24 | public String getMessage() { 25 | return "Hello world!"; 26 | } 27 | 28 | } -------------------------------------------------------------------------------- /junit4-spring/src/main/resources/logback.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | %d{yyyy-MM-dd HH:mm:ss} [%thread] %-5level %logger{36}.%M\(%line\) -- %msg%n 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /junit4-spring/src/test/java/io/github/bonigarcia/SimpleSpringTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * (C) Copyright 2017 Boni Garcia (https://bonigarcia.github.io/) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | */ 17 | package io.github.bonigarcia; 18 | 19 | import static org.junit.Assert.assertEquals; 20 | 21 | import org.junit.Test; 22 | import org.junit.runner.RunWith; 23 | import org.springframework.beans.factory.annotation.Autowired; 24 | import org.springframework.test.context.ContextConfiguration; 25 | import org.springframework.test.context.junit4.SpringRunner; 26 | 27 | @RunWith(SpringRunner.class) 28 | @ContextConfiguration(classes = { MySpringApplication.class }) 29 | public class SimpleSpringTest { 30 | 31 | @Autowired 32 | public MessageComponent messageComponent; 33 | 34 | @Test 35 | public void test() { 36 | assertEquals("Hello world!", messageComponent.getMessage()); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /junit4/src/main/resources/logback.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | %d{yyyy-MM-dd HH:mm:ss} [%thread] %-5level %logger{36}.%M\(%line\) -- %msg%n 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /junit4/src/test/java/io/github/bonigarcia/FunctionalTests.java: -------------------------------------------------------------------------------- 1 | /* 2 | * (C) Copyright 2017 Boni Garcia (https://bonigarcia.github.io/) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | */ 17 | package io.github.bonigarcia; 18 | 19 | public interface FunctionalTests { 20 | 21 | } 22 | -------------------------------------------------------------------------------- /junit4/src/test/java/io/github/bonigarcia/MySuite.java: -------------------------------------------------------------------------------- 1 | /* 2 | * (C) Copyright 2017 Boni Garcia (https://bonigarcia.github.io/) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | */ 17 | package io.github.bonigarcia; 18 | 19 | import org.junit.runner.RunWith; 20 | import org.junit.runners.Suite; 21 | 22 | @RunWith(Suite.class) 23 | @Suite.SuiteClasses({ TestMinimal1.class, TestMinimal2.class }) 24 | public class MySuite { 25 | 26 | } 27 | -------------------------------------------------------------------------------- /junit4/src/test/java/io/github/bonigarcia/NonFunctionalTests.java: -------------------------------------------------------------------------------- 1 | /* 2 | * (C) Copyright 2017 Boni Garcia (https://bonigarcia.github.io/) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | */ 17 | package io.github.bonigarcia; 18 | 19 | public interface NonFunctionalTests { 20 | 21 | } 22 | -------------------------------------------------------------------------------- /junit4/src/test/java/io/github/bonigarcia/TestAssumptions.java: -------------------------------------------------------------------------------- 1 | /* 2 | * (C) Copyright 2017 Boni Garcia (https://bonigarcia.github.io/) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | */ 17 | package io.github.bonigarcia; 18 | 19 | import static org.junit.Assume.assumeFalse; 20 | 21 | import org.junit.Test; 22 | 23 | public class TestAssumptions { 24 | 25 | @Test 26 | public void assumptionTest() { 27 | assumeFalse(true); 28 | // This test will be skipped 29 | } 30 | 31 | } 32 | -------------------------------------------------------------------------------- /junit4/src/test/java/io/github/bonigarcia/TestCategories.java: -------------------------------------------------------------------------------- 1 | /* 2 | * (C) Copyright 2017 Boni Garcia (https://bonigarcia.github.io/) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | */ 17 | package io.github.bonigarcia; 18 | 19 | import org.junit.Test; 20 | import org.junit.experimental.categories.Category; 21 | 22 | public class TestCategories { 23 | 24 | @Category(FunctionalTests.class) 25 | @Test 26 | public void test1() { 27 | } 28 | 29 | @Category(NonFunctionalTests.class) 30 | @Test 31 | public void test2() { 32 | } 33 | 34 | } 35 | -------------------------------------------------------------------------------- /junit4/src/test/java/io/github/bonigarcia/TestCategoriesSuite.java: -------------------------------------------------------------------------------- 1 | /* 2 | * (C) Copyright 2017 Boni Garcia (https://bonigarcia.github.io/) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | */ 17 | package io.github.bonigarcia; 18 | 19 | import org.junit.experimental.categories.Categories; 20 | import org.junit.experimental.categories.Categories.IncludeCategory; 21 | import org.junit.runner.RunWith; 22 | import org.junit.runners.Suite.SuiteClasses; 23 | 24 | @RunWith(Categories.class) 25 | @IncludeCategory(FunctionalTests.class) 26 | @SuiteClasses({ TestCategories.class }) 27 | public class TestCategoriesSuite { 28 | 29 | // This suite will run TestCategories.test1 but not TestCategories.test2 30 | } 31 | -------------------------------------------------------------------------------- /junit4/src/test/java/io/github/bonigarcia/TestIgnore.java: -------------------------------------------------------------------------------- 1 | /* 2 | * (C) Copyright 2017 Boni Garcia (https://bonigarcia.github.io/) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | */ 17 | package io.github.bonigarcia; 18 | 19 | import org.junit.Ignore; 20 | import org.junit.Test; 21 | 22 | public class TestIgnore { 23 | 24 | @Ignore 25 | @Test 26 | public void test2() { 27 | // This test will be skipped 28 | } 29 | 30 | } 31 | -------------------------------------------------------------------------------- /junit4/src/test/java/io/github/bonigarcia/TestMinimal1.java: -------------------------------------------------------------------------------- 1 | /* 2 | * (C) Copyright 2017 Boni Garcia (https://bonigarcia.github.io/) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | */ 17 | package io.github.bonigarcia; 18 | 19 | import static java.lang.invoke.MethodHandles.lookup; 20 | import static org.junit.Assert.assertTrue; 21 | import static org.slf4j.LoggerFactory.getLogger; 22 | 23 | import org.junit.Test; 24 | import org.slf4j.Logger; 25 | 26 | public class TestMinimal1 { 27 | 28 | static final Logger log = getLogger(lookup().lookupClass()); 29 | 30 | @Test 31 | public void test1() { 32 | log.debug("** Test 1 ***"); 33 | 34 | assertTrue(true); 35 | } 36 | 37 | } 38 | -------------------------------------------------------------------------------- /junit4/src/test/java/io/github/bonigarcia/TestMinimal2.java: -------------------------------------------------------------------------------- 1 | /* 2 | * (C) Copyright 2017 Boni Garcia (https://bonigarcia.github.io/) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | */ 17 | package io.github.bonigarcia; 18 | 19 | import static java.lang.invoke.MethodHandles.lookup; 20 | import static org.junit.Assert.assertTrue; 21 | import static org.slf4j.LoggerFactory.getLogger; 22 | 23 | import org.junit.Test; 24 | import org.slf4j.Logger; 25 | 26 | public class TestMinimal2 { 27 | 28 | static final Logger log = getLogger(lookup().lookupClass()); 29 | 30 | @Test 31 | public void test2() { 32 | log.debug("## Test 2 ##"); 33 | 34 | assertTrue(true); 35 | } 36 | 37 | } 38 | -------------------------------------------------------------------------------- /junit4/src/test/java/io/github/bonigarcia/TestOrder.java: -------------------------------------------------------------------------------- 1 | /* 2 | * (C) Copyright 2017 Boni Garcia (https://bonigarcia.github.io/) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | */ 17 | package io.github.bonigarcia; 18 | 19 | import static java.lang.invoke.MethodHandles.lookup; 20 | import static org.slf4j.LoggerFactory.getLogger; 21 | 22 | import org.junit.FixMethodOrder; 23 | import org.junit.Test; 24 | import org.junit.runners.MethodSorters; 25 | import org.slf4j.Logger; 26 | 27 | @FixMethodOrder(MethodSorters.NAME_ASCENDING) 28 | public class TestOrder { 29 | 30 | static final Logger log = getLogger(lookup().lookupClass()); 31 | 32 | @Test 33 | public void testA() { 34 | log.debug("Test 1"); 35 | } 36 | 37 | @Test 38 | public void testB() { 39 | log.debug("Test 2"); 40 | } 41 | 42 | @Test 43 | public void testC() { 44 | log.debug("Test 3"); 45 | } 46 | 47 | } 48 | -------------------------------------------------------------------------------- /junit4/src/test/java/io/github/bonigarcia/TestRuleErrorCollector.java: -------------------------------------------------------------------------------- 1 | /* 2 | * (C) Copyright 2017 Boni Garcia (https://bonigarcia.github.io/) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | */ 17 | package io.github.bonigarcia; 18 | 19 | import static org.hamcrest.CoreMatchers.equalTo; 20 | 21 | import org.junit.Ignore; 22 | import org.junit.Rule; 23 | import org.junit.Test; 24 | import org.junit.rules.ErrorCollector; 25 | 26 | public class TestRuleErrorCollector { 27 | 28 | @Rule 29 | public ErrorCollector collector = new ErrorCollector(); 30 | 31 | @Ignore 32 | @Test 33 | public void test() { 34 | collector.checkThat("a", equalTo("b")); 35 | collector.checkThat(1, equalTo(2)); 36 | collector.checkThat("c", equalTo("c")); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /junit4/src/test/java/io/github/bonigarcia/TestRuleExpectedException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * (C) Copyright 2017 Boni Garcia (https://bonigarcia.github.io/) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | */ 17 | package io.github.bonigarcia; 18 | 19 | import static org.junit.Assert.assertThrows; 20 | 21 | import org.junit.Test; 22 | 23 | public class TestRuleExpectedException { 24 | 25 | @Test 26 | public void throwsNullPointerException() { 27 | assertThrows(NullPointerException.class, () -> { 28 | throw new NullPointerException(); 29 | }); 30 | } 31 | 32 | } 33 | -------------------------------------------------------------------------------- /junit4/src/test/java/io/github/bonigarcia/TestRuleName.java: -------------------------------------------------------------------------------- 1 | /* 2 | * (C) Copyright 2017 Boni Garcia (https://bonigarcia.github.io/) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | */ 17 | package io.github.bonigarcia; 18 | 19 | import static org.junit.Assert.assertEquals; 20 | 21 | import org.junit.Rule; 22 | import org.junit.Test; 23 | import org.junit.rules.TestName; 24 | 25 | public class TestRuleName { 26 | 27 | @Rule 28 | public TestName name = new TestName(); 29 | 30 | @Test 31 | public void testA() { 32 | assertEquals("testA", name.getMethodName()); 33 | } 34 | 35 | @Test 36 | public void testB() { 37 | assertEquals("testB", name.getMethodName()); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /junit4/src/test/java/io/github/bonigarcia/TestRuleTemporaryFolder.java: -------------------------------------------------------------------------------- 1 | /* 2 | * (C) Copyright 2017 Boni Garcia (https://bonigarcia.github.io/) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | */ 17 | package io.github.bonigarcia; 18 | 19 | import static java.lang.invoke.MethodHandles.lookup; 20 | import static org.slf4j.LoggerFactory.getLogger; 21 | 22 | import java.io.File; 23 | import java.io.IOException; 24 | 25 | import org.junit.Rule; 26 | import org.junit.Test; 27 | import org.junit.rules.TemporaryFolder; 28 | import org.slf4j.Logger; 29 | 30 | public class TestRuleTemporaryFolder { 31 | 32 | static final Logger log = getLogger(lookup().lookupClass()); 33 | 34 | @Rule 35 | public TemporaryFolder folder = new TemporaryFolder(); 36 | 37 | @Test 38 | public void testUsingTempFolder() throws IOException { 39 | File fileInTmpFolder = folder.newFile("myfile.txt"); 40 | 41 | log.debug("File in tmp folder: {}", fileInTmpFolder); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /junit4/src/test/java/io/github/bonigarcia/TestRuleTimeout.java: -------------------------------------------------------------------------------- 1 | /* 2 | * (C) Copyright 2017 Boni Garcia (https://bonigarcia.github.io/) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | */ 17 | package io.github.bonigarcia; 18 | 19 | import static java.util.concurrent.TimeUnit.MILLISECONDS; 20 | 21 | import org.junit.Ignore; 22 | import org.junit.Rule; 23 | import org.junit.Test; 24 | import org.junit.rules.Timeout; 25 | 26 | public class TestRuleTimeout { 27 | 28 | @Rule 29 | public Timeout globalTimeout = new Timeout(100, MILLISECONDS); 30 | 31 | @Ignore 32 | @Test 33 | public void testInfiniteLoop() { 34 | while (true) 35 | ; 36 | } 37 | 38 | @Test 39 | public void testDoNothing() { 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /junit4/src/test/java/io/github/bonigarcia/TestTimeout.java: -------------------------------------------------------------------------------- 1 | /* 2 | * (C) Copyright 2017 Boni Garcia (https://bonigarcia.github.io/) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | */ 17 | package io.github.bonigarcia; 18 | 19 | import org.junit.Ignore; 20 | import org.junit.Test; 21 | 22 | public class TestTimeout { 23 | 24 | @Ignore 25 | @Test(timeout = 10) 26 | public void test() { 27 | while (true) 28 | ; 29 | } 30 | 31 | } 32 | -------------------------------------------------------------------------------- /junit4/src/test/java/io/github/bonigarcia/TestWithTimeout.java: -------------------------------------------------------------------------------- 1 | /* 2 | * (C) Copyright 2017 Boni Garcia (https://bonigarcia.github.io/) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | */ 17 | package io.github.bonigarcia; 18 | 19 | import org.junit.Ignore; 20 | import org.junit.Test; 21 | 22 | public class TestWithTimeout { 23 | 24 | @Ignore 25 | @Test(timeout = 1000) 26 | public void test() throws InterruptedException { 27 | Thread.sleep(2000); 28 | } 29 | 30 | } 31 | -------------------------------------------------------------------------------- /junit5-allure/README.md: -------------------------------------------------------------------------------- 1 | # JUnit5 with Allure reports example 2 | 3 | With this example, you can execute the JUnit 5 tests defined in the project and get the Allure report in a easy way. With Maven: 4 | 5 | ``` 6 | mvn test allure:serve 7 | ``` 8 | 9 | ... or with Gradle: 10 | 11 | ``` 12 | gradle test allureServe 13 | ``` 14 | -------------------------------------------------------------------------------- /junit5-allure/build.gradle: -------------------------------------------------------------------------------- 1 | buildscript { 2 | ext { 3 | allureGradleVersion = '2.11.2' 4 | } 5 | repositories { 6 | maven { 7 | url "https://plugins.gradle.org/m2/" 8 | } 9 | } 10 | dependencies { 11 | classpath "io.qameta.allure:io.qameta.allure.gradle.plugin:${allureGradleVersion}" 12 | } 13 | } 14 | 15 | repositories { 16 | mavenCentral() 17 | maven { 18 | url "https://plugins.gradle.org/m2/" 19 | } 20 | } 21 | 22 | ext { 23 | junitJupiterVersion = '5.13.0' 24 | } 25 | 26 | apply plugin: 'java' 27 | apply plugin: 'eclipse' 28 | apply plugin: 'idea' 29 | apply plugin: 'io.qameta.allure' 30 | 31 | allure { 32 | version = '2.16.1' 33 | } 34 | 35 | jar { 36 | archiveBaseName = 'junit5-allure' 37 | archiveVersion = '1.0.0' 38 | } 39 | 40 | test { 41 | useJUnitPlatform() 42 | 43 | testLogging { 44 | events "passed", "skipped", "failed" 45 | showStandardStreams = true 46 | } 47 | } 48 | 49 | compileTestJava { 50 | sourceCompatibility = 17 51 | targetCompatibility = 17 52 | options.compilerArgs += '-parameters' 53 | } 54 | 55 | dependencies { 56 | testImplementation("org.junit.jupiter:junit-jupiter:${junitJupiterVersion}") 57 | } 58 | -------------------------------------------------------------------------------- /junit5-allure/src/test/java/io/github/bonigarcia/DisplayNameTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * (C) Copyright 2017 Boni Garcia (https://bonigarcia.github.io/) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | */ 17 | package io.github.bonigarcia; 18 | 19 | import org.junit.jupiter.api.DisplayName; 20 | import org.junit.jupiter.api.Test; 21 | 22 | @DisplayName("Once upon a time...") 23 | class DisplayNameTest { 24 | 25 | @Test 26 | @DisplayName("Lorem ipsum dolor sit amet") 27 | void testLorem() { 28 | } 29 | 30 | @Test 31 | @DisplayName("This test is ok") 32 | void testOk() { 33 | } 34 | 35 | } 36 | -------------------------------------------------------------------------------- /junit5-allure/src/test/java/io/github/bonigarcia/SimpleJUnit5Test.java: -------------------------------------------------------------------------------- 1 | /* 2 | * (C) Copyright 2017 Boni Garcia (https://bonigarcia.github.io/) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | */ 17 | package io.github.bonigarcia; 18 | 19 | import org.junit.jupiter.api.Test; 20 | 21 | class SimpleJUnit5Test { 22 | 23 | @Test 24 | void voidTest1() { 25 | } 26 | 27 | @Test 28 | void voidTest2() { 29 | } 30 | 31 | @Test 32 | void voidTest3() { 33 | } 34 | 35 | @Test 36 | void voidTest4() { 37 | } 38 | 39 | @Test 40 | void voidTest5() { 41 | } 42 | 43 | } 44 | -------------------------------------------------------------------------------- /junit5-android/app/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /junit5-android/app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: "com.android.application" 2 | apply plugin: "de.mannodermaus.android-junit5" 3 | 4 | android { 5 | compileSdkVersion 26 6 | buildToolsVersion "26.0.0" 7 | defaultConfig { 8 | applicationId "io.github.bonigarcia" 9 | minSdkVersion 15 10 | targetSdkVersion 26 11 | versionCode 1 12 | versionName "1.0" 13 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" 14 | } 15 | buildTypes { 16 | release { 17 | minifyEnabled false 18 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 19 | } 20 | } 21 | } 22 | 23 | dependencies { 24 | testImplementation junit5.unitTests() 25 | testImplementation junit5.parameterized() 26 | androidTestImplementation junit5.instrumentationTests() 27 | } 28 | -------------------------------------------------------------------------------- /junit5-android/app/src/androidTest/java/io/github/bonigarcia/myapplication/InstrumentedTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * (C) Copyright 2017 Boni Garcia (https://bonigarcia.github.io/) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | */ 17 | package io.github.bonigarcia.myapplication; 18 | 19 | import android.content.Context; 20 | import android.support.test.InstrumentationRegistry; 21 | import android.support.test.runner.AndroidJUnit4; 22 | 23 | import org.junit.Test; 24 | import org.junit.runner.RunWith; 25 | 26 | import static org.junit.Assert.*; 27 | 28 | @RunWith(AndroidJUnit4.class) 29 | public class InstrumentedTest { 30 | 31 | @Test 32 | public void useAppContext() throws Exception { 33 | Context appContext = InstrumentationRegistry.getTargetContext(); 34 | 35 | assertEquals("io.github.bonigarcia.myapplication", appContext.getPackageName()); 36 | } 37 | 38 | } 39 | -------------------------------------------------------------------------------- /junit5-android/app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /junit5-android/app/src/main/java/io/github/bonigarcia/myapplication/MainActivity.java: -------------------------------------------------------------------------------- 1 | /* 2 | * (C) Copyright 2017 Boni Garcia (https://bonigarcia.github.io/) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | */ 17 | package io.github.bonigarcia.myapplication; 18 | 19 | import android.support.v7.app.AppCompatActivity; 20 | import android.os.Bundle; 21 | 22 | import io.github.bonigarcia.myapplication.R; 23 | 24 | public class MainActivity extends AppCompatActivity { 25 | 26 | @Override 27 | protected void onCreate(Bundle savedInstanceState) { 28 | super.onCreate(savedInstanceState); 29 | setContentView(R.layout.activity_main); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /junit5-android/app/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /junit5-android/app/src/main/res/mipmap-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bonigarcia/mastering-junit5/e0ccdf96da5699198112869e98f79e41b96ae56f/junit5-android/app/src/main/res/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /junit5-android/app/src/main/res/mipmap-hdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bonigarcia/mastering-junit5/e0ccdf96da5699198112869e98f79e41b96ae56f/junit5-android/app/src/main/res/mipmap-hdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /junit5-android/app/src/main/res/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bonigarcia/mastering-junit5/e0ccdf96da5699198112869e98f79e41b96ae56f/junit5-android/app/src/main/res/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /junit5-android/app/src/main/res/mipmap-mdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bonigarcia/mastering-junit5/e0ccdf96da5699198112869e98f79e41b96ae56f/junit5-android/app/src/main/res/mipmap-mdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /junit5-android/app/src/main/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bonigarcia/mastering-junit5/e0ccdf96da5699198112869e98f79e41b96ae56f/junit5-android/app/src/main/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /junit5-android/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bonigarcia/mastering-junit5/e0ccdf96da5699198112869e98f79e41b96ae56f/junit5-android/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /junit5-android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bonigarcia/mastering-junit5/e0ccdf96da5699198112869e98f79e41b96ae56f/junit5-android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /junit5-android/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bonigarcia/mastering-junit5/e0ccdf96da5699198112869e98f79e41b96ae56f/junit5-android/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /junit5-android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bonigarcia/mastering-junit5/e0ccdf96da5699198112869e98f79e41b96ae56f/junit5-android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /junit5-android/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bonigarcia/mastering-junit5/e0ccdf96da5699198112869e98f79e41b96ae56f/junit5-android/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /junit5-android/app/src/main/res/values/colors.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | #3F51B5 4 | #303F9F 5 | #FF4081 6 | 7 | -------------------------------------------------------------------------------- /junit5-android/app/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | My Application 3 | 4 | -------------------------------------------------------------------------------- /junit5-android/app/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /junit5-android/app/src/test/java/io/github/bonigarcia/myapplication/ExampleJUnit5Test.java: -------------------------------------------------------------------------------- 1 | /* 2 | * (C) Copyright 2017 Boni Garcia (https://bonigarcia.github.io/) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | */ 17 | package io.github.bonigarcia.myapplication; 18 | 19 | import org.junit.jupiter.api.Test; 20 | 21 | import static org.junit.Assert.assertTrue; 22 | 23 | public class ExampleJUnit5Test { 24 | 25 | @Test 26 | public void alwaysTrueTest() { 27 | assertTrue(true); 28 | } 29 | 30 | } 31 | -------------------------------------------------------------------------------- /junit5-android/app/src/test/java/io/github/bonigarcia/myapplication/JUnit4Test.java: -------------------------------------------------------------------------------- 1 | /* 2 | * (C) Copyright 2017 Boni Garcia (https://bonigarcia.github.io/) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | */ 17 | package io.github.bonigarcia.myapplication; 18 | 19 | import org.junit.Test; 20 | 21 | import static org.junit.Assert.*; 22 | 23 | public class JUnit4Test { 24 | 25 | @Test 26 | public void simpleAddition() throws Exception { 27 | assertEquals(4, 2 + 2); 28 | } 29 | 30 | } -------------------------------------------------------------------------------- /junit5-android/build.gradle: -------------------------------------------------------------------------------- 1 | buildscript { 2 | repositories { 3 | google() 4 | mavenCentral() 5 | } 6 | dependencies { 7 | classpath "com.android.tools.build:gradle:8.2.2" 8 | classpath "de.mannodermaus.gradle.plugins:android-junit5:1.12.2.0" 9 | } 10 | } 11 | 12 | allprojects { 13 | repositories { 14 | mavenCentral() 15 | } 16 | } 17 | 18 | task clean(type: Delete) { 19 | delete rootProject.buildDir 20 | } 21 | -------------------------------------------------------------------------------- /junit5-android/gradle.properties: -------------------------------------------------------------------------------- 1 | # Project-wide Gradle settings. 2 | 3 | # IDE (e.g. Android Studio) users: 4 | # Gradle settings configured through the IDE *will override* 5 | # any settings specified in this file. 6 | 7 | # For more details on how to configure your build environment visit 8 | # http://www.gradle.org/docs/current/userguide/build_environment.html 9 | 10 | # Specifies the JVM arguments used for the daemon process. 11 | # The setting is particularly useful for tweaking memory settings. 12 | org.gradle.jvmargs=-Xmx1536m 13 | 14 | # When configured, Gradle will run in incubating parallel mode. 15 | # This option should only be used with decoupled projects. More details, visit 16 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects 17 | # org.gradle.parallel=true 18 | -------------------------------------------------------------------------------- /junit5-android/settings.gradle: -------------------------------------------------------------------------------- 1 | include ':app' 2 | -------------------------------------------------------------------------------- /junit5-assertions/build.gradle: -------------------------------------------------------------------------------- 1 | repositories { 2 | mavenCentral() 3 | } 4 | 5 | ext { 6 | slf4jVersion = '2.0.17' 7 | logbackVersion = '1.5.18' 8 | 9 | junitJupiterVersion = '5.13.0' 10 | hamcrestVersion = '3.0' 11 | assertjVersion = '3.27.3' 12 | truth = '1.4.4' 13 | } 14 | 15 | apply plugin: 'java' 16 | apply plugin: 'eclipse' 17 | apply plugin: 'idea' 18 | 19 | jar { 20 | archiveBaseName = 'junit5-assertions' 21 | archiveVersion = '1.0.0' 22 | } 23 | 24 | test { 25 | useJUnitPlatform() 26 | 27 | testLogging { 28 | events "passed", "skipped", "failed" 29 | showStandardStreams = true 30 | } 31 | } 32 | 33 | compileTestJava { 34 | sourceCompatibility = 17 35 | targetCompatibility = 17 36 | options.compilerArgs += '-parameters' 37 | } 38 | 39 | dependencies { 40 | implementation("org.slf4j:slf4j-api:${slf4jVersion}") 41 | implementation("ch.qos.logback:logback-classic:${logbackVersion}") 42 | 43 | testImplementation("org.junit.jupiter:junit-jupiter:${junitJupiterVersion}") 44 | testImplementation("org.hamcrest:hamcrest-core:${hamcrestVersion}") 45 | testImplementation("org.assertj:assertj-core:${assertjVersion}") 46 | testImplementation("com.google.truth:truth:${truth}") 47 | } 48 | -------------------------------------------------------------------------------- /junit5-assertions/src/main/java/io/github/bonigarcia/Address.java: -------------------------------------------------------------------------------- 1 | /* 2 | * (C) Copyright 2017 Boni Garcia (https://bonigarcia.github.io/) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | */ 17 | package io.github.bonigarcia; 18 | 19 | public class Address { 20 | 21 | public String firstName; 22 | public String lastName; 23 | 24 | public Address(String firstName, String lastName) { 25 | this.firstName = firstName; 26 | this.lastName = lastName; 27 | } 28 | 29 | public String getFirstName() { 30 | return firstName; 31 | } 32 | 33 | public void setFirstName(String firstName) { 34 | this.firstName = firstName; 35 | } 36 | 37 | public String getLastName() { 38 | return lastName; 39 | } 40 | 41 | public void setLastName(String lastName) { 42 | this.lastName = lastName; 43 | } 44 | 45 | } 46 | -------------------------------------------------------------------------------- /junit5-assertions/src/main/resources/logback.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | %d{yyyy-MM-dd HH:mm:ss} [%thread] %-5level %logger{36}.%M\(%line\) -- %msg%n 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /junit5-assertions/src/test/java/io/github/bonigarcia/AssertJTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * (C) Copyright 2020 Boni Garcia (https://bonigarcia.github.io/) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | */ 17 | package io.github.bonigarcia; 18 | 19 | import static java.lang.invoke.MethodHandles.lookup; 20 | import static org.assertj.core.api.Assertions.assertThat; 21 | import static org.slf4j.LoggerFactory.getLogger; 22 | 23 | import org.junit.jupiter.api.Test; 24 | import org.slf4j.Logger; 25 | 26 | public class AssertJTest { 27 | 28 | final Logger log = getLogger(lookup().lookupClass()); 29 | 30 | @Test 31 | void test() { 32 | log.debug("Assertions using AssertJ"); 33 | 34 | int sum = 1 + 1; 35 | 36 | assertThat(sum).isGreaterThan(1).isLessThan(3); 37 | assertThat(sum).isEqualTo(2); 38 | } 39 | 40 | } 41 | -------------------------------------------------------------------------------- /junit5-assertions/src/test/java/io/github/bonigarcia/ExceptionTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * (C) Copyright 2017 Boni Garcia (https://bonigarcia.github.io/) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | */ 17 | package io.github.bonigarcia; 18 | 19 | import static java.lang.invoke.MethodHandles.lookup; 20 | import static org.junit.jupiter.api.Assertions.assertThrows; 21 | import static org.slf4j.LoggerFactory.getLogger; 22 | 23 | import org.junit.jupiter.api.BeforeEach; 24 | import org.junit.jupiter.api.Test; 25 | import org.slf4j.Logger; 26 | 27 | class ExceptionTest { 28 | 29 | static final Logger log = getLogger(lookup().lookupClass()); 30 | 31 | MySUT mySut; 32 | 33 | @BeforeEach 34 | void setup() { 35 | mySut = new MySUT("[Assertions test]"); 36 | } 37 | 38 | @Test 39 | void exceptionTesting() { 40 | log.debug("Testing with assertThrows"); 41 | assertThrows(RuntimeException.class, mySut::releaseId); 42 | log.debug("End of test"); 43 | } 44 | 45 | } 46 | -------------------------------------------------------------------------------- /junit5-assertions/src/test/java/io/github/bonigarcia/GroupedAssertionsTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * (C) Copyright 2017 Boni Garcia (https://bonigarcia.github.io/) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | */ 17 | package io.github.bonigarcia; 18 | 19 | import static org.junit.jupiter.api.Assertions.assertAll; 20 | import static org.junit.jupiter.api.Assertions.assertEquals; 21 | 22 | import org.junit.jupiter.api.Test; 23 | 24 | class GroupedAssertionsTest { 25 | 26 | @Test 27 | void groupedAssertions() { 28 | Address address = new Address("John", "Smith"); 29 | 30 | // In a grouped assertion all assertions are executed, and any 31 | // failures will be reported together. 32 | assertAll("address", () -> assertEquals("John", address.getFirstName()), 33 | () -> assertEquals("Smith", address.getLastName())); 34 | } 35 | 36 | } 37 | -------------------------------------------------------------------------------- /junit5-assertions/src/test/java/io/github/bonigarcia/HamcrestTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * (C) Copyright 2017 Boni Garcia (https://bonigarcia.github.io/) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | */ 17 | package io.github.bonigarcia; 18 | 19 | import static org.hamcrest.CoreMatchers.containsString; 20 | import static org.hamcrest.CoreMatchers.equalTo; 21 | import static org.hamcrest.CoreMatchers.notNullValue; 22 | import static org.hamcrest.MatcherAssert.assertThat; 23 | 24 | import org.junit.jupiter.api.Test; 25 | 26 | class HamcrestTest { 27 | 28 | @Test 29 | void assertWithHamcrestMatcher() { 30 | assertThat(2 + 1, equalTo(3)); 31 | assertThat("Foo", notNullValue()); 32 | assertThat("Hello world", containsString("world")); 33 | } 34 | 35 | } 36 | -------------------------------------------------------------------------------- /junit5-assertions/src/test/java/io/github/bonigarcia/StandardAssertionsTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * (C) Copyright 2017 Boni Garcia (https://bonigarcia.github.io/) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | */ 17 | package io.github.bonigarcia; 18 | 19 | import static org.junit.jupiter.api.Assertions.assertEquals; 20 | import static org.junit.jupiter.api.Assertions.assertFalse; 21 | import static org.junit.jupiter.api.Assertions.assertTrue; 22 | 23 | import org.junit.jupiter.api.Test; 24 | 25 | class StandardAssertionsTest { 26 | 27 | @Test 28 | void standardAssertions() { 29 | assertEquals(2, 2); 30 | assertTrue(true, 31 | "The optional assertion message is now the last parameter"); 32 | assertFalse(false, () -> "Really " + "expensive " + "message" + "."); 33 | } 34 | 35 | } 36 | -------------------------------------------------------------------------------- /junit5-assertions/src/test/java/io/github/bonigarcia/TimeoutExceededTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * (C) Copyright 2017 Boni Garcia (https://bonigarcia.github.io/) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | */ 17 | package io.github.bonigarcia; 18 | 19 | import static java.time.Duration.ofMillis; 20 | import static java.time.Duration.ofMinutes; 21 | import static org.junit.jupiter.api.Assertions.assertTimeout; 22 | 23 | import org.junit.jupiter.api.Disabled; 24 | import org.junit.jupiter.api.Test; 25 | 26 | class TimeoutExceededTest { 27 | 28 | @Test 29 | void timeoutNotExceeded() { 30 | assertTimeout(ofMinutes(2), () -> { 31 | // Perform task that takes less than 2 minutes 32 | }); 33 | } 34 | 35 | @Disabled("Skipped for not breaking buld in Travis CI") 36 | @Test 37 | void timeoutExceeded() { 38 | assertTimeout(ofMillis(10), () -> { 39 | Thread.sleep(100); 40 | }); 41 | } 42 | 43 | } 44 | -------------------------------------------------------------------------------- /junit5-assertions/src/test/java/io/github/bonigarcia/TimeoutWithPreemptiveTerminationTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * (C) Copyright 2017 Boni Garcia (https://bonigarcia.github.io/) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | */ 17 | package io.github.bonigarcia; 18 | 19 | import static java.time.Duration.ofMillis; 20 | import static org.junit.jupiter.api.Assertions.assertTimeoutPreemptively; 21 | 22 | import org.junit.jupiter.api.Disabled; 23 | import org.junit.jupiter.api.Test; 24 | 25 | class TimeoutWithPreemptiveTerminationTest { 26 | 27 | @Disabled 28 | @Test 29 | void timeoutExceededWithPreemptiveTermination() { 30 | assertTimeoutPreemptively(ofMillis(10), () -> { 31 | Thread.sleep(100); 32 | }); 33 | } 34 | 35 | } -------------------------------------------------------------------------------- /junit5-assertions/src/test/java/io/github/bonigarcia/TruthTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * (C) Copyright 2020 Boni Garcia (https://bonigarcia.github.io/) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | */ 17 | package io.github.bonigarcia; 18 | 19 | import static com.google.common.truth.Truth.assertThat; 20 | import static java.lang.invoke.MethodHandles.lookup; 21 | import static org.slf4j.LoggerFactory.getLogger; 22 | 23 | import org.junit.jupiter.api.Test; 24 | import org.slf4j.Logger; 25 | 26 | public class TruthTest { 27 | 28 | final Logger log = getLogger(lookup().lookupClass()); 29 | 30 | @Test 31 | void test() { 32 | log.debug("Assertion using Truth"); 33 | 34 | int sum = 1 + 1; 35 | 36 | assertThat(sum).isEqualTo(2); 37 | } 38 | 39 | } 40 | -------------------------------------------------------------------------------- /junit5-basic-tests/build.gradle: -------------------------------------------------------------------------------- 1 | repositories { 2 | mavenCentral() 3 | } 4 | 5 | ext { 6 | slf4jVersion = '2.0.17' 7 | logbackVersion = '1.5.18' 8 | 9 | junitJupiterVersion = '5.13.0' 10 | } 11 | 12 | apply plugin: 'java' 13 | apply plugin: 'eclipse' 14 | apply plugin: 'idea' 15 | 16 | jar { 17 | archiveBaseName = 'junit5-basic-tests' 18 | archiveVersion = '1.0.0' 19 | } 20 | 21 | test { 22 | useJUnitPlatform() 23 | 24 | testLogging { 25 | events "passed", "skipped", "failed" 26 | showStandardStreams = true 27 | } 28 | } 29 | 30 | compileTestJava { 31 | sourceCompatibility = 17 32 | targetCompatibility = 17 33 | options.compilerArgs += '-parameters' 34 | } 35 | 36 | dependencies { 37 | implementation("org.slf4j:slf4j-api:${slf4jVersion}") 38 | implementation("ch.qos.logback:logback-classic:${logbackVersion}") 39 | 40 | testImplementation("org.junit.jupiter:junit-jupiter:${junitJupiterVersion}") 41 | } 42 | -------------------------------------------------------------------------------- /junit5-basic-tests/src/main/resources/logback.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | %d{yyyy-MM-dd HH:mm:ss} [%thread] %-5level %logger{36}.%M\(%line\) -- %msg%n 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /junit5-basic-tests/src/test/java/io/github/bonigarcia/DisplayNameTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * (C) Copyright 2017 Boni Garcia (https://bonigarcia.github.io/) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | */ 17 | package io.github.bonigarcia; 18 | 19 | import org.junit.jupiter.api.DisplayName; 20 | import org.junit.jupiter.api.Test; 21 | 22 | @DisplayName("A special test case") 23 | class DisplayNameTest { 24 | 25 | @Test 26 | @DisplayName("Custom test name containing spaces") 27 | void testWithDisplayNameContainingSpaces() { 28 | // TODO 29 | } 30 | 31 | @Test 32 | @DisplayName("╯°□°)╯") 33 | void testWithDisplayNameContainingSpecialCharacters() { 34 | // TODO 35 | } 36 | 37 | @Test 38 | @DisplayName("😱") 39 | void testWithDisplayNameContainingEmoji() { 40 | // TODO 41 | } 42 | 43 | } -------------------------------------------------------------------------------- /junit5-console-launcher/build.gradle: -------------------------------------------------------------------------------- 1 | repositories { 2 | mavenCentral() 3 | } 4 | 5 | ext { 6 | slf4jVersion = '2.0.17' 7 | logbackVersion = '1.5.18' 8 | junitJupiterVersion = '5.13.0' 9 | } 10 | 11 | apply plugin: 'java' 12 | apply plugin: 'eclipse' 13 | apply plugin: 'idea' 14 | 15 | jar { 16 | archiveBaseName = 'junit5-console-launcher' 17 | archiveVersion = '1.0.0' 18 | } 19 | 20 | test { 21 | useJUnitPlatform() 22 | 23 | testLogging { 24 | events "passed", "skipped", "failed" 25 | showStandardStreams = true 26 | } 27 | } 28 | 29 | compileTestJava { 30 | sourceCompatibility = 17 31 | targetCompatibility = 17 32 | options.compilerArgs += '-parameters' 33 | } 34 | 35 | dependencies { 36 | implementation("org.slf4j:slf4j-api:${slf4jVersion}") 37 | implementation("ch.qos.logback:logback-classic:${logbackVersion}") 38 | implementation("org.junit.jupiter:junit-jupiter:${junitJupiterVersion}") 39 | } 40 | -------------------------------------------------------------------------------- /junit5-console-launcher/src/main/java/io/github/bonigarcia/EmptyTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * (C) Copyright 2017 Boni Garcia (https://bonigarcia.github.io/) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | */ 17 | package io.github.bonigarcia; 18 | 19 | import static java.lang.invoke.MethodHandles.lookup; 20 | import static org.slf4j.LoggerFactory.getLogger; 21 | 22 | import org.junit.jupiter.api.Test; 23 | import org.slf4j.Logger; 24 | 25 | class EmptyTest { 26 | 27 | static final Logger log = getLogger(lookup().lookupClass()); 28 | 29 | @Test 30 | void myTest() { 31 | log.debug("This is an empty test"); 32 | } 33 | 34 | } 35 | -------------------------------------------------------------------------------- /junit5-console-launcher/src/main/resources/logback.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | %d{yyyy-MM-dd HH:mm:ss} [%thread] %-5level %logger{36}.%M\(%line\) -- %msg%n 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /junit5-cucumber-selenium/src/main/resources/logback.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | %d{yyyy-MM-dd HH:mm:ss} [%thread] %-5level %logger{36}.%M\(%line\) - %msg%n 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /junit5-cucumber-selenium/src/test/java/io/github/bonigarcia/CucumberTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * (C) Copyright 2020 Boni Garcia (https://bonigarcia.github.io/) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | */ 17 | package io.github.bonigarcia; 18 | 19 | import static io.cucumber.junit.platform.engine.Constants.GLUE_PROPERTY_NAME; 20 | 21 | import org.junit.platform.suite.api.ConfigurationParameter; 22 | import org.junit.platform.suite.api.IncludeEngines; 23 | import org.junit.platform.suite.api.SelectClasspathResource; 24 | import org.junit.platform.suite.api.Suite; 25 | 26 | @Suite 27 | @IncludeEngines("cucumber") 28 | @SelectClasspathResource("io/github/bonigarcia") 29 | @ConfigurationParameter(key = GLUE_PROPERTY_NAME, value = "io.github.bonigarcia") 30 | public class CucumberTest { 31 | 32 | } 33 | -------------------------------------------------------------------------------- /junit5-cucumber-selenium/src/test/resources/io/github/bonigarcia/login.feature: -------------------------------------------------------------------------------- 1 | Feature: Login in practice site 2 | 3 | Scenario: Successful login 4 | When I navigate to "https://bonigarcia.dev/selenium-webdriver-java/login-form.html" 5 | And I login with the username "user" and password "user" 6 | And I click Submit 7 | Then I should be see the message "Login successful" 8 | 9 | Scenario: Failure login 10 | When I navigate to "https://bonigarcia.dev/selenium-webdriver-java/login-form.html" 11 | And I login with the username "bad-user" and password "bad-password" 12 | And I click Submit 13 | Then I should be see the message "Invalid credentials" -------------------------------------------------------------------------------- /junit5-cucumber-selenium/src/test/resources/junit-platform.properties: -------------------------------------------------------------------------------- 1 | cucumber.publish.quiet=true -------------------------------------------------------------------------------- /junit5-cucumber/build.gradle: -------------------------------------------------------------------------------- 1 | repositories { 2 | mavenCentral() 3 | } 4 | 5 | ext { 6 | slf4jVersion = '2.0.17' 7 | logbackVersion = '1.5.18' 8 | 9 | junitJupiterVersion = '5.13.0' 10 | junitPlatformSuiteVersion = '1.13.0' 11 | cucumberVersion = '7.23.0' 12 | } 13 | 14 | apply plugin: 'java' 15 | apply plugin: 'eclipse' 16 | apply plugin: 'idea' 17 | 18 | jar { 19 | archiveBaseName = 'junit5-cucumber' 20 | archiveVersion = '1.0.0' 21 | } 22 | 23 | test { 24 | useJUnitPlatform() 25 | 26 | testLogging { 27 | events "passed", "skipped", "failed" 28 | showStandardStreams = true 29 | } 30 | } 31 | 32 | compileTestJava { 33 | sourceCompatibility = 17 34 | targetCompatibility = 17 35 | options.compilerArgs += '-parameters' 36 | } 37 | 38 | dependencies { 39 | implementation("org.slf4j:slf4j-api:${slf4jVersion}") 40 | implementation("ch.qos.logback:logback-classic:${logbackVersion}") 41 | 42 | testImplementation("org.junit.jupiter:junit-jupiter:${junitJupiterVersion}") 43 | testImplementation("org.junit.platform:junit-platform-suite:${junitPlatformSuiteVersion}") 44 | testImplementation("io.cucumber:cucumber-java:${cucumberVersion}") 45 | testImplementation("io.cucumber:cucumber-junit-platform-engine:${cucumberVersion}") 46 | } 47 | -------------------------------------------------------------------------------- /junit5-cucumber/src/main/resources/logback.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | %d{yyyy-MM-dd HH:mm:ss} [%thread] %-5level %logger{36}.%M\(%line\) -- %msg%n 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /junit5-cucumber/src/test/java/io/github/bonigarcia/CucumberTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * (C) Copyright 2017 Boni Garcia (https://bonigarcia.github.io/) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | */ 17 | package io.github.bonigarcia; 18 | 19 | import static io.cucumber.junit.platform.engine.Constants.GLUE_PROPERTY_NAME; 20 | 21 | import org.junit.platform.suite.api.ConfigurationParameter; 22 | import org.junit.platform.suite.api.IncludeEngines; 23 | import org.junit.platform.suite.api.SelectClasspathResource; 24 | import org.junit.platform.suite.api.Suite; 25 | 26 | @Suite 27 | @IncludeEngines("cucumber") 28 | @SelectClasspathResource("io/github/bonigarcia") 29 | @ConfigurationParameter(key = GLUE_PROPERTY_NAME, value = "io.github.bonigarcia") 30 | public class CucumberTest { 31 | 32 | } 33 | -------------------------------------------------------------------------------- /junit5-cucumber/src/test/resources/io/github/bonigarcia/calculator.feature: -------------------------------------------------------------------------------- 1 | Feature: Basic Arithmetic 2 | 3 | Background: A Calculator 4 | Given a calculator I just turned on 5 | 6 | Scenario: Addition 7 | When I add 4 and 5 8 | Then the result is 9 9 | 10 | Scenario: Substraction 11 | When I substract 7 to 2 12 | Then the result is 5 13 | 14 | Scenario Outline: Several additions 15 | When I add and 16 | Then the result is 17 | 18 | Examples: Single digits 19 | | a | b | c | 20 | | 1 | 2 | 3 | 21 | | 3 | 7 | 10 | 22 | -------------------------------------------------------------------------------- /junit5-cucumber/src/test/resources/junit-platform.properties: -------------------------------------------------------------------------------- 1 | cucumber.publish.quiet=true -------------------------------------------------------------------------------- /junit5-dependency-injection/build.gradle: -------------------------------------------------------------------------------- 1 | repositories { 2 | mavenCentral() 3 | } 4 | 5 | ext { 6 | slf4jVersion = '2.0.17' 7 | logbackVersion = '1.5.18' 8 | 9 | junitJupiterVersion = '5.13.0' 10 | } 11 | 12 | apply plugin: 'java' 13 | apply plugin: 'eclipse' 14 | apply plugin: 'idea' 15 | 16 | jar { 17 | archiveBaseName = 'junit5-dependency-injection' 18 | archiveVersion = '1.0.0' 19 | } 20 | 21 | test { 22 | useJUnitPlatform() 23 | 24 | testLogging { 25 | events "passed", "skipped", "failed" 26 | showStandardStreams = true 27 | } 28 | } 29 | 30 | compileTestJava { 31 | sourceCompatibility = 17 32 | targetCompatibility = 17 33 | options.compilerArgs += '-parameters' 34 | } 35 | 36 | dependencies { 37 | implementation("org.slf4j:slf4j-api:${slf4jVersion}") 38 | implementation("ch.qos.logback:logback-classic:${logbackVersion}") 39 | 40 | testImplementation("org.junit.jupiter:junit-jupiter:${junitJupiterVersion}") 41 | } 42 | -------------------------------------------------------------------------------- /junit5-dependency-injection/src/main/resources/logback.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | %d{yyyy-MM-dd HH:mm:ss} [%thread] %-5level %logger{36}.%M\(%line\) -- %msg%n 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /junit5-dependency-injection/src/test/java/io/github/bonigarcia/RepetitionInfoTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * (C) Copyright 2017 Boni Garcia (https://bonigarcia.github.io/) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | */ 17 | package io.github.bonigarcia; 18 | 19 | import static java.lang.invoke.MethodHandles.lookup; 20 | import static org.slf4j.LoggerFactory.getLogger; 21 | 22 | import org.junit.jupiter.api.RepeatedTest; 23 | import org.junit.jupiter.api.RepetitionInfo; 24 | import org.slf4j.Logger; 25 | 26 | class RepetitionInfoTest { 27 | 28 | static final Logger log = getLogger(lookup().lookupClass()); 29 | 30 | @RepeatedTest(2) 31 | void test(RepetitionInfo repetitionInfo) { 32 | log.debug("Test {}/{}", repetitionInfo.getCurrentRepetition(), 33 | repetitionInfo.getTotalRepetitions()); 34 | } 35 | 36 | } 37 | -------------------------------------------------------------------------------- /junit5-dependency-injection/src/test/java/io/github/bonigarcia/TestReporterTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * (C) Copyright 2017 Boni Garcia (https://bonigarcia.github.io/) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | */ 17 | package io.github.bonigarcia; 18 | 19 | import java.util.HashMap; 20 | 21 | import org.junit.jupiter.api.Test; 22 | import org.junit.jupiter.api.TestReporter; 23 | 24 | class TestReporterTest { 25 | 26 | @Test 27 | void reportSingleValue(TestReporter testReporter) { 28 | testReporter.publishEntry("key", "value"); 29 | } 30 | 31 | @Test 32 | void reportSeveralValues(TestReporter testReporter) { 33 | HashMap values = new HashMap<>(); 34 | values.put("name", "john"); 35 | values.put("surname", "doe"); 36 | 37 | testReporter.publishEntry(values); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /junit5-disabled-tests/build.gradle: -------------------------------------------------------------------------------- 1 | repositories { 2 | mavenCentral() 3 | } 4 | 5 | ext { 6 | slf4jVersion = '2.0.17' 7 | logbackVersion = '1.5.18' 8 | junitJupiterVersion = '5.13.0' 9 | } 10 | 11 | apply plugin: 'java' 12 | apply plugin: 'eclipse' 13 | apply plugin: 'idea' 14 | 15 | jar { 16 | archiveBaseName = 'junit5-disabled-tests' 17 | archiveVersion = '1.0.0' 18 | } 19 | 20 | test { 21 | useJUnitPlatform() 22 | 23 | testLogging { 24 | events "passed", "skipped", "failed" 25 | showStandardStreams = true 26 | } 27 | } 28 | 29 | compileTestJava { 30 | sourceCompatibility = 17 31 | targetCompatibility = 17 32 | options.compilerArgs += '-parameters' 33 | } 34 | 35 | dependencies { 36 | implementation("org.slf4j:slf4j-api:${slf4jVersion}") 37 | implementation("ch.qos.logback:logback-classic:${logbackVersion}") 38 | implementation("org.junit.jupiter:junit-jupiter:${junitJupiterVersion}") 39 | } 40 | -------------------------------------------------------------------------------- /junit5-disabled-tests/src/main/resources/logback.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | %d{yyyy-MM-dd HH:mm:ss} [%thread] %-5level %logger{36}.%M\(%line\) -- %msg%n 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /junit5-disabled-tests/src/test/java/io/github/bonigarcia/DisabledAllTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * (C) Copyright 2020 Boni Garcia (https://bonigarcia.github.io/) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | */ 17 | package io.github.bonigarcia; 18 | 19 | import static java.lang.invoke.MethodHandles.lookup; 20 | import static org.slf4j.LoggerFactory.getLogger; 21 | 22 | import org.junit.jupiter.api.Disabled; 23 | import org.junit.jupiter.api.Test; 24 | import org.slf4j.Logger; 25 | 26 | @Disabled("All tests in this class are skipped") 27 | class DisabledAllTest { 28 | 29 | static final Logger log = getLogger(lookup().lookupClass()); 30 | 31 | @Test 32 | void skippedTestOne() { 33 | log.debug("This test is NOT executed"); 34 | } 35 | 36 | @Test 37 | void skippedTestTwo() { 38 | log.debug("This test is NOT executed"); 39 | } 40 | 41 | } 42 | -------------------------------------------------------------------------------- /junit5-disabled-tests/src/test/java/io/github/bonigarcia/DisabledTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * (C) Copyright 2020 Boni Garcia (https://bonigarcia.github.io/) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | */ 17 | package io.github.bonigarcia; 18 | 19 | import static java.lang.invoke.MethodHandles.lookup; 20 | import static org.slf4j.LoggerFactory.getLogger; 21 | 22 | import org.junit.jupiter.api.Disabled; 23 | import org.junit.jupiter.api.Test; 24 | import org.slf4j.Logger; 25 | 26 | class DisabledTest { 27 | 28 | static final Logger log = getLogger(lookup().lookupClass()); 29 | 30 | @Test 31 | void test() { 32 | log.debug("This test is executed"); 33 | } 34 | 35 | @Disabled 36 | @Test 37 | void skippedTest() { 38 | log.debug("This test is NOT executed"); 39 | } 40 | 41 | } 42 | -------------------------------------------------------------------------------- /junit5-docker/build.gradle: -------------------------------------------------------------------------------- 1 | repositories { 2 | mavenCentral() 3 | } 4 | 5 | ext { 6 | slf4jVersion = '2.0.17' 7 | logbackVersion = '1.5.18' 8 | junitJupiterVersion = '5.13.0' 9 | junitDockerVersion = '1.0.0' 10 | mysqlConnectorVersion = '8.0.33' 11 | } 12 | 13 | apply plugin: 'java' 14 | apply plugin: 'eclipse' 15 | apply plugin: 'idea' 16 | 17 | jar { 18 | archiveBaseName = 'junit5-docker' 19 | archiveVersion = '1.0.0' 20 | } 21 | 22 | test { 23 | useJUnitPlatform() 24 | 25 | testLogging { 26 | events "passed", "skipped", "failed" 27 | showStandardStreams = true 28 | } 29 | } 30 | 31 | compileTestJava { 32 | sourceCompatibility = 17 33 | targetCompatibility = 17 34 | options.compilerArgs += '-parameters' 35 | } 36 | 37 | dependencies { 38 | implementation("org.slf4j:slf4j-api:${slf4jVersion}") 39 | implementation("ch.qos.logback:logback-classic:${logbackVersion}") 40 | 41 | testImplementation("org.junit.jupiter:junit-jupiter:${junitJupiterVersion}") 42 | testImplementation("com.github.faustxvi:junit5-docker:${junitDockerVersion}") 43 | testImplementation("mysql:mysql-connector-java:${mysqlConnectorVersion}") 44 | } 45 | -------------------------------------------------------------------------------- /junit5-docker/src/main/resources/logback.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | %d{yyyy-MM-dd HH:mm:ss} [%thread] %-5level %logger{36} - %msg%n 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /junit5-dynamic-tests/build.gradle: -------------------------------------------------------------------------------- 1 | repositories { 2 | mavenCentral() 3 | } 4 | 5 | ext { 6 | slf4jVersion = '2.0.17' 7 | logbackVersion = '1.5.18' 8 | 9 | junitJupiterVersion = '5.13.0' 10 | } 11 | 12 | apply plugin: 'java' 13 | apply plugin: 'eclipse' 14 | apply plugin: 'idea' 15 | 16 | jar { 17 | archiveBaseName = 'junit5-dynamic-tests' 18 | archiveVersion = '1.0.0' 19 | } 20 | 21 | test { 22 | useJUnitPlatform() 23 | 24 | testLogging { 25 | events "passed", "skipped", "failed" 26 | showStandardStreams = true 27 | } 28 | } 29 | 30 | compileTestJava { 31 | sourceCompatibility = 17 32 | targetCompatibility = 17 33 | options.compilerArgs += '-parameters' 34 | } 35 | 36 | dependencies { 37 | implementation("org.slf4j:slf4j-api:${slf4jVersion}") 38 | implementation("ch.qos.logback:logback-classic:${logbackVersion}") 39 | 40 | testImplementation("org.junit.jupiter:junit-jupiter:${junitJupiterVersion}") 41 | } 42 | -------------------------------------------------------------------------------- /junit5-dynamic-tests/src/main/resources/logback.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | %d{yyyy-MM-dd HH:mm:ss} [%thread] %-5level %logger{36}.%M\(%line\) -- %msg%n 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /junit5-engine-spi/build.gradle: -------------------------------------------------------------------------------- 1 | repositories { 2 | mavenCentral() 3 | } 4 | 5 | ext { 6 | junitPlatformVersion = '1.13.0' 7 | } 8 | 9 | apply plugin: 'java' 10 | apply plugin: 'eclipse' 11 | apply plugin: 'idea' 12 | 13 | jar { 14 | archiveBaseName = 'junit5-engine-spi' 15 | archiveVersion = '1.0.0' 16 | } 17 | 18 | compileTestJava { 19 | sourceCompatibility = 17 20 | targetCompatibility = 17 21 | options.compilerArgs += '-parameters' 22 | } 23 | 24 | dependencies { 25 | implementation("org.junit.platform:junit-platform-engine:${junitPlatformVersion}") 26 | } 27 | -------------------------------------------------------------------------------- /junit5-engine-spi/pom.xml: -------------------------------------------------------------------------------- 1 | 4 | 4.0.0 5 | io.github.bonigarcia 6 | junit5-engine-spi 7 | 1.0.0 8 | 9 | 10 | 1.13.0 11 | 12 | 17 13 | ${java.version} 14 | ${java.version} 15 | 16 | UTF-8 17 | UTF-8 18 | 19 | 20 | 21 | 22 | org.junit.platform 23 | junit-platform-engine 24 | ${junit-platform.version} 25 | 26 | 27 | 28 | 29 | -------------------------------------------------------------------------------- /junit5-extension-model-automatic/build.gradle: -------------------------------------------------------------------------------- 1 | repositories { 2 | mavenCentral() 3 | } 4 | 5 | ext { 6 | slf4jVersion = '2.0.17' 7 | logbackVersion = '1.5.18' 8 | junitJupiterVersion = '5.13.0' 9 | } 10 | 11 | apply plugin: 'java' 12 | apply plugin: 'eclipse' 13 | apply plugin: 'idea' 14 | 15 | jar { 16 | archiveBaseName = 'junit5-extension-model-automatic' 17 | archiveVersion = '1.0.0' 18 | } 19 | 20 | test { 21 | useJUnitPlatform() 22 | 23 | testLogging { 24 | events "passed", "skipped", "failed" 25 | showStandardStreams = true 26 | } 27 | 28 | testLogging.showStandardStreams = true 29 | } 30 | 31 | compileTestJava { 32 | sourceCompatibility = 17 33 | targetCompatibility = 17 34 | options.compilerArgs += '-parameters' 35 | } 36 | 37 | dependencies { 38 | implementation("org.slf4j:slf4j-api:${slf4jVersion}") 39 | implementation("ch.qos.logback:logback-classic:${logbackVersion}") 40 | implementation("org.junit.jupiter:junit-jupiter:${junitJupiterVersion}") 41 | } 42 | -------------------------------------------------------------------------------- /junit5-extension-model-automatic/src/main/java/io/github/bonigarcia/MyExtension.java: -------------------------------------------------------------------------------- 1 | /* 2 | * (C) Copyright 2018 Boni Garcia (https://bonigarcia.github.io/) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | */ 17 | package io.github.bonigarcia; 18 | 19 | import static java.lang.invoke.MethodHandles.lookup; 20 | import static org.slf4j.LoggerFactory.getLogger; 21 | 22 | import org.junit.jupiter.api.extension.BeforeEachCallback; 23 | import org.junit.jupiter.api.extension.ExtensionContext; 24 | import org.slf4j.Logger; 25 | 26 | public class MyExtension implements BeforeEachCallback { 27 | 28 | static final Logger log = getLogger(lookup().lookupClass()); 29 | 30 | @Override 31 | public void beforeEach(ExtensionContext context) throws Exception { 32 | log.debug("Using my extension automatically"); 33 | } 34 | 35 | } 36 | -------------------------------------------------------------------------------- /junit5-extension-model-automatic/src/main/resources/META-INF/services/org.junit.jupiter.api.extension.Extension: -------------------------------------------------------------------------------- 1 | io.github.bonigarcia.MyExtension -------------------------------------------------------------------------------- /junit5-extension-model-automatic/src/main/resources/logback.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | %d{yyyy-MM-dd HH:mm:ss} [%thread] %-5level %logger{36}.%M\(%line\) -- %msg%n 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /junit5-extension-model-automatic/src/test/java/io/github/bonigarcia/MyTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * (C) Copyright 2018 Boni Garcia (https://bonigarcia.github.io/) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | */ 17 | package io.github.bonigarcia; 18 | 19 | import static java.lang.invoke.MethodHandles.lookup; 20 | import static org.slf4j.LoggerFactory.getLogger; 21 | 22 | import org.junit.jupiter.api.Test; 23 | import org.slf4j.Logger; 24 | 25 | public class MyTest { 26 | 27 | static final Logger log = getLogger(lookup().lookupClass()); 28 | 29 | @Test 30 | void myTest() { 31 | log.debug("This is my test"); 32 | } 33 | 34 | } 35 | -------------------------------------------------------------------------------- /junit5-extension-model-automatic/src/test/resources/junit-platform.properties: -------------------------------------------------------------------------------- 1 | junit.jupiter.extensions.autodetection.enabled=true -------------------------------------------------------------------------------- /junit5-extension-model/build.gradle: -------------------------------------------------------------------------------- 1 | repositories { 2 | mavenCentral() 3 | } 4 | 5 | ext { 6 | slf4jVersion = '2.0.17' 7 | logbackVersion = '1.5.18' 8 | junitJupiterVersion = '5.13.0' 9 | } 10 | 11 | apply plugin: 'java' 12 | apply plugin: 'eclipse' 13 | apply plugin: 'idea' 14 | 15 | jar { 16 | archiveBaseName = 'junit5-extension-model' 17 | archiveVersion = '1.0.0' 18 | } 19 | 20 | test { 21 | useJUnitPlatform() 22 | 23 | testLogging { 24 | events "passed", "skipped", "failed" 25 | showStandardStreams = true 26 | } 27 | } 28 | 29 | compileTestJava { 30 | sourceCompatibility = 17 31 | targetCompatibility = 17 32 | options.compilerArgs += '-parameters' 33 | } 34 | 35 | dependencies { 36 | testImplementation("org.slf4j:slf4j-api:${slf4jVersion}") 37 | testImplementation("ch.qos.logback:logback-classic:${logbackVersion}") 38 | testImplementation("org.junit.jupiter:junit-jupiter:${junitJupiterVersion}") 39 | } 40 | -------------------------------------------------------------------------------- /junit5-extension-model/src/main/resources/logback.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | %d{yyyy-MM-dd HH:mm:ss} [%thread] %-5level %logger{36}.%M\(%line\) -- %msg%n 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /junit5-extension-model/src/test/java/io/github/bonigarcia/DependencyInjectionTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * (C) Copyright 2017 Boni Garcia (https://bonigarcia.github.io/) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | */ 17 | package io.github.bonigarcia; 18 | 19 | import static java.lang.invoke.MethodHandles.lookup; 20 | import static org.slf4j.LoggerFactory.getLogger; 21 | 22 | import org.junit.jupiter.api.Test; 23 | import org.junit.jupiter.api.extension.ExtendWith; 24 | import org.slf4j.Logger; 25 | 26 | public class DependencyInjectionTest { 27 | 28 | static final Logger log = getLogger(lookup().lookupClass()); 29 | 30 | @ExtendWith(MyParameterResolver.class) 31 | @Test 32 | public void test(Object parameter) { 33 | log.debug("My parameter {}", parameter); 34 | } 35 | 36 | } 37 | -------------------------------------------------------------------------------- /junit5-extension-model/src/test/java/io/github/bonigarcia/ExceptionTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * (C) Copyright 2017 Boni Garcia (https://bonigarcia.github.io/) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | */ 17 | package io.github.bonigarcia; 18 | 19 | import java.io.IOException; 20 | 21 | import org.junit.jupiter.api.Test; 22 | import org.junit.jupiter.api.extension.RegisterExtension; 23 | 24 | public class ExceptionTest { 25 | 26 | @RegisterExtension 27 | static IgnoreIOExceptionExtension ignoreIOExceptionExtension = new IgnoreIOExceptionExtension(); 28 | 29 | @Test 30 | public void firstTest() throws IOException { 31 | throw new IOException("IO Exception"); 32 | } 33 | 34 | @Test 35 | public void secondTest() throws IOException { 36 | throw new IOException("My IO Exception"); 37 | } 38 | 39 | } 40 | -------------------------------------------------------------------------------- /junit5-extension-model/src/test/java/io/github/bonigarcia/IgnoreIOExceptionExtension.java: -------------------------------------------------------------------------------- 1 | /* 2 | * (C) Copyright 2017 Boni Garcia (https://bonigarcia.github.io/) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | */ 17 | package io.github.bonigarcia; 18 | 19 | import java.io.IOException; 20 | 21 | import org.junit.jupiter.api.extension.ExtensionContext; 22 | import org.junit.jupiter.api.extension.TestExecutionExceptionHandler; 23 | 24 | public class IgnoreIOExceptionExtension 25 | implements TestExecutionExceptionHandler { 26 | 27 | @Override 28 | public void handleTestExecutionException(ExtensionContext context, 29 | Throwable throwable) throws Throwable { 30 | 31 | if (throwable instanceof IOException) { 32 | return; 33 | } 34 | throw throwable; 35 | } 36 | 37 | } 38 | -------------------------------------------------------------------------------- /junit5-failsafe/src/test/java/io/github/bonigarcia/ExecutedByFailsafePluginIT.java: -------------------------------------------------------------------------------- 1 | /* 2 | * (C) Copyright 2018 Boni Garcia (https://bonigarcia.github.io/) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | */ 17 | package io.github.bonigarcia; 18 | 19 | import static org.junit.jupiter.api.Assertions.assertTrue; 20 | 21 | import org.junit.jupiter.api.Test; 22 | 23 | class ExecutedByFailsafePluginIT { 24 | 25 | @Test 26 | void failsafeTest() { 27 | assertTrue(true); 28 | } 29 | 30 | } 31 | -------------------------------------------------------------------------------- /junit5-failsafe/src/test/java/io/github/bonigarcia/ExecutedBySurefirePluginTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * (C) Copyright 2018 Boni Garcia (https://bonigarcia.github.io/) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | */ 17 | package io.github.bonigarcia; 18 | 19 | import static org.junit.jupiter.api.Assertions.assertTrue; 20 | 21 | import org.junit.jupiter.api.Test; 22 | 23 | class ExecutedBySurefirePluginTest { 24 | 25 | @Test 26 | void surefireTest() { 27 | assertTrue(true); 28 | } 29 | 30 | } 31 | -------------------------------------------------------------------------------- /junit5-junit4-runner/build.gradle: -------------------------------------------------------------------------------- 1 | repositories { 2 | mavenCentral() 3 | } 4 | 5 | ext { 6 | slf4jVersion = '2.0.17' 7 | logbackVersion = '1.5.18' 8 | 9 | junitJupiterVersion = '5.13.0' 10 | junitPlatformVersion = '1.13.0' 11 | } 12 | 13 | apply plugin: 'java' 14 | apply plugin: 'eclipse' 15 | apply plugin: 'idea' 16 | 17 | jar { 18 | archiveBaseName = 'junit5-junit4-runner' 19 | archiveVersion = '1.0.0' 20 | } 21 | 22 | test { 23 | useJUnitPlatform() 24 | 25 | testLogging { 26 | events "passed", "skipped", "failed" 27 | showStandardStreams = true 28 | } 29 | } 30 | 31 | compileTestJava { 32 | sourceCompatibility = 17 33 | targetCompatibility = 17 34 | options.compilerArgs += '-parameters' 35 | } 36 | 37 | dependencies { 38 | implementation("org.slf4j:slf4j-api:${slf4jVersion}") 39 | implementation("ch.qos.logback:logback-classic:${logbackVersion}") 40 | 41 | testImplementation("org.junit.jupiter:junit-jupiter:${junitJupiterVersion}") 42 | testImplementation("org.junit.platform:junit-platform-runner:${junitPlatformVersion}") 43 | } 44 | -------------------------------------------------------------------------------- /junit5-junit4-runner/src/main/resources/logback.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | %d{yyyy-MM-dd HH:mm:ss} [%thread] %-5level %logger{36}.%M\(%line\) -- %msg%n 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /junit5-junit4-runner/src/test/java/io/github/bonigarcia/JUnit5CompatibleTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * (C) Copyright 2017 Boni Garcia (https://bonigarcia.github.io/) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | */ 17 | package io.github.bonigarcia; 18 | 19 | import static java.lang.invoke.MethodHandles.lookup; 20 | import static org.junit.jupiter.api.Assertions.assertEquals; 21 | import static org.slf4j.LoggerFactory.getLogger; 22 | 23 | import org.junit.jupiter.api.Test; 24 | import org.junit.platform.suite.api.Suite; 25 | import org.slf4j.Logger; 26 | 27 | @Suite 28 | public class JUnit5CompatibleTest { 29 | 30 | static final Logger log = getLogger(lookup().lookupClass()); 31 | 32 | @Test 33 | void myTest() { 34 | String message = "1+1 should be equal to 2"; 35 | log.debug("{}", message); 36 | 37 | assertEquals(2, 1 + 1, message); 38 | } 39 | 40 | } 41 | -------------------------------------------------------------------------------- /junit5-launcher-api/build.gradle: -------------------------------------------------------------------------------- 1 | repositories { 2 | mavenCentral() 3 | } 4 | 5 | ext { 6 | junitJupiterVersion = '5.13.0' 7 | junitPlatformVersion = '1.13.0' 8 | } 9 | 10 | apply plugin: 'java' 11 | apply plugin: 'eclipse' 12 | apply plugin: 'idea' 13 | 14 | jar { 15 | archiveBaseName = 'junit5-launcher-api' 16 | archiveVersion = '1.0.0' 17 | } 18 | 19 | test { 20 | useJUnitPlatform() 21 | 22 | testLogging { 23 | events "passed", "skipped", "failed" 24 | showStandardStreams = true 25 | } 26 | } 27 | 28 | compileTestJava { 29 | sourceCompatibility = 17 30 | targetCompatibility = 17 31 | options.compilerArgs += '-parameters' 32 | } 33 | 34 | dependencies { 35 | testImplementation("org.junit.jupiter:junit-jupiter:${junitJupiterVersion}") 36 | testImplementation("org.junit.platform:junit-platform-launcher:${junitPlatformVersion}") 37 | } 38 | -------------------------------------------------------------------------------- /junit5-launcher-api/src/test/java/io/github/bonigarcia/DummyTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * (C) Copyright 2017 Boni Garcia (https://bonigarcia.github.io/) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | */ 17 | package io.github.bonigarcia; 18 | 19 | import static org.junit.jupiter.api.Assertions.assertTrue; 20 | import static org.junit.jupiter.api.Assertions.fail; 21 | 22 | import org.junit.jupiter.api.Disabled; 23 | import org.junit.jupiter.api.Test; 24 | 25 | @Disabled 26 | class DummyTest { 27 | 28 | @Test 29 | void successTest() { 30 | System.out.println("This is a sucess test"); 31 | assertTrue(true); 32 | } 33 | 34 | @Test 35 | void failTest1() { 36 | System.out.println("This is a failed test [1]"); 37 | fail(); 38 | } 39 | 40 | @Test 41 | void failTest2() { 42 | System.out.println("This is a failed test [2]"); 43 | fail(); 44 | } 45 | 46 | @Disabled 47 | @Test 48 | void ignoredTest() { 49 | // Nothing 50 | } 51 | 52 | } 53 | -------------------------------------------------------------------------------- /junit5-meta-annotations/build.gradle: -------------------------------------------------------------------------------- 1 | repositories { 2 | mavenCentral() 3 | } 4 | 5 | ext { 6 | slf4jVersion = '2.0.17' 7 | logbackVersion = '1.5.18' 8 | junitJupiterVersion = '5.13.0' 9 | } 10 | 11 | apply plugin: 'java' 12 | apply plugin: 'eclipse' 13 | apply plugin: 'idea' 14 | 15 | jar { 16 | archiveBaseName = 'junit5-meta-annotations' 17 | archiveVersion = '1.0.0' 18 | } 19 | 20 | test { 21 | useJUnitPlatform { 22 | includeTags 'non-functional' 23 | } 24 | 25 | testLogging { 26 | events "passed", "skipped", "failed" 27 | showStandardStreams = true 28 | } 29 | } 30 | 31 | compileTestJava { 32 | sourceCompatibility = 17 33 | targetCompatibility = 17 34 | options.compilerArgs += '-parameters' 35 | } 36 | 37 | dependencies { 38 | implementation("org.slf4j:slf4j-api:${slf4jVersion}") 39 | implementation("ch.qos.logback:logback-classic:${logbackVersion}") 40 | implementation("org.junit.jupiter:junit-jupiter:${junitJupiterVersion}") 41 | } 42 | -------------------------------------------------------------------------------- /junit5-meta-annotations/src/main/java/io/github/bonigarcia/Accessibility.java: -------------------------------------------------------------------------------- 1 | /* 2 | * (C) Copyright 2017 Boni Garcia (https://bonigarcia.github.io/) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | */ 17 | package io.github.bonigarcia; 18 | 19 | import java.lang.annotation.ElementType; 20 | import java.lang.annotation.Retention; 21 | import java.lang.annotation.RetentionPolicy; 22 | import java.lang.annotation.Target; 23 | 24 | import org.junit.jupiter.api.Tag; 25 | 26 | @Target({ ElementType.TYPE, ElementType.METHOD }) 27 | @Retention(RetentionPolicy.RUNTIME) 28 | @Tag("non-functional") 29 | @Tag("accessibility") 30 | public @interface Accessibility { 31 | } 32 | -------------------------------------------------------------------------------- /junit5-meta-annotations/src/main/java/io/github/bonigarcia/Functional.java: -------------------------------------------------------------------------------- 1 | /* 2 | * (C) Copyright 2017 Boni Garcia (https://bonigarcia.github.io/) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | */ 17 | package io.github.bonigarcia; 18 | 19 | import java.lang.annotation.ElementType; 20 | import java.lang.annotation.Retention; 21 | import java.lang.annotation.RetentionPolicy; 22 | import java.lang.annotation.Target; 23 | 24 | import org.junit.jupiter.api.Tag; 25 | 26 | @Target({ ElementType.TYPE, ElementType.METHOD }) 27 | @Retention(RetentionPolicy.RUNTIME) 28 | @Tag("functional") 29 | public @interface Functional { 30 | } 31 | -------------------------------------------------------------------------------- /junit5-meta-annotations/src/main/java/io/github/bonigarcia/Load.java: -------------------------------------------------------------------------------- 1 | /* 2 | * (C) Copyright 2017 Boni Garcia (https://bonigarcia.github.io/) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | */ 17 | package io.github.bonigarcia; 18 | 19 | import java.lang.annotation.ElementType; 20 | import java.lang.annotation.Retention; 21 | import java.lang.annotation.RetentionPolicy; 22 | import java.lang.annotation.Target; 23 | 24 | import org.junit.jupiter.api.Tag; 25 | 26 | @Target({ ElementType.TYPE, ElementType.METHOD }) 27 | @Retention(RetentionPolicy.RUNTIME) 28 | @Tag("non-functional") 29 | @Tag("performance") 30 | @Tag("load") 31 | public @interface Load { 32 | } 33 | -------------------------------------------------------------------------------- /junit5-meta-annotations/src/main/java/io/github/bonigarcia/Security.java: -------------------------------------------------------------------------------- 1 | /* 2 | * (C) Copyright 2017 Boni Garcia (https://bonigarcia.github.io/) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | */ 17 | package io.github.bonigarcia; 18 | 19 | import java.lang.annotation.ElementType; 20 | import java.lang.annotation.Retention; 21 | import java.lang.annotation.RetentionPolicy; 22 | import java.lang.annotation.Target; 23 | 24 | import org.junit.jupiter.api.Tag; 25 | 26 | @Target({ ElementType.TYPE, ElementType.METHOD }) 27 | @Retention(RetentionPolicy.RUNTIME) 28 | @Tag("non-functional") 29 | @Tag("security") 30 | public @interface Security { 31 | } 32 | -------------------------------------------------------------------------------- /junit5-meta-annotations/src/main/java/io/github/bonigarcia/Stress.java: -------------------------------------------------------------------------------- 1 | /* 2 | * (C) Copyright 2017 Boni Garcia (https://bonigarcia.github.io/) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | */ 17 | package io.github.bonigarcia; 18 | 19 | import java.lang.annotation.ElementType; 20 | import java.lang.annotation.Retention; 21 | import java.lang.annotation.RetentionPolicy; 22 | import java.lang.annotation.Target; 23 | 24 | import org.junit.jupiter.api.Tag; 25 | 26 | @Target({ ElementType.TYPE, ElementType.METHOD }) 27 | @Retention(RetentionPolicy.RUNTIME) 28 | @Tag("non-functional") 29 | @Tag("performance") 30 | @Tag("stress") 31 | public @interface Stress { 32 | } 33 | -------------------------------------------------------------------------------- /junit5-meta-annotations/src/main/java/io/github/bonigarcia/Usability.java: -------------------------------------------------------------------------------- 1 | /* 2 | * (C) Copyright 2017 Boni Garcia (https://bonigarcia.github.io/) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | */ 17 | package io.github.bonigarcia; 18 | 19 | import java.lang.annotation.ElementType; 20 | import java.lang.annotation.Retention; 21 | import java.lang.annotation.RetentionPolicy; 22 | import java.lang.annotation.Target; 23 | 24 | import org.junit.jupiter.api.Tag; 25 | 26 | @Target({ ElementType.TYPE, ElementType.METHOD }) 27 | @Retention(RetentionPolicy.RUNTIME) 28 | @Tag("non-functional") 29 | @Tag("usability") 30 | public @interface Usability { 31 | } 32 | -------------------------------------------------------------------------------- /junit5-meta-annotations/src/main/resources/logback.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | %d{yyyy-MM-dd HH:mm:ss} [%thread] %-5level %logger{36}.%M\(%line\) -- %msg%n 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /junit5-meta-annotations/src/test/java/io/github/bonigarcia/FunctionalTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * (C) Copyright 2017 Boni Garcia (https://bonigarcia.github.io/) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | */ 17 | package io.github.bonigarcia; 18 | 19 | import static java.lang.invoke.MethodHandles.lookup; 20 | import static org.slf4j.LoggerFactory.getLogger; 21 | 22 | import org.junit.jupiter.api.Test; 23 | import org.slf4j.Logger; 24 | 25 | @Functional 26 | class FunctionalTest { 27 | 28 | static final Logger log = getLogger(lookup().lookupClass()); 29 | 30 | @Test 31 | void testOne() { 32 | log.debug("Functional Test 1"); 33 | } 34 | 35 | @Test 36 | void testTwo() { 37 | log.debug("Functional Test 2"); 38 | } 39 | 40 | } 41 | -------------------------------------------------------------------------------- /junit5-migration-support/build.gradle: -------------------------------------------------------------------------------- 1 | repositories { 2 | mavenCentral() 3 | } 4 | 5 | ext { 6 | slf4jVersion = '2.0.17' 7 | logbackVersion = '1.5.18' 8 | 9 | junitJupiterVersion = '5.13.0' 10 | } 11 | 12 | apply plugin: 'java' 13 | apply plugin: 'eclipse' 14 | apply plugin: 'idea' 15 | 16 | jar { 17 | archiveBaseName = 'junit5-migration-support' 18 | archiveVersion = '1.0.0' 19 | } 20 | 21 | test { 22 | useJUnitPlatform() 23 | 24 | testLogging { 25 | events "passed", "skipped", "failed" 26 | showStandardStreams = true 27 | } 28 | } 29 | 30 | compileTestJava { 31 | sourceCompatibility = 17 32 | targetCompatibility = 17 33 | options.compilerArgs += '-parameters' 34 | } 35 | 36 | dependencies { 37 | implementation("org.slf4j:slf4j-api:${slf4jVersion}") 38 | implementation("ch.qos.logback:logback-classic:${logbackVersion}") 39 | 40 | testImplementation("org.junit.jupiter:junit-jupiter:${junitJupiterVersion}") 41 | testImplementation("org.junit.jupiter:junit-jupiter-migrationsupport:${junitJupiterVersion}") 42 | } 43 | -------------------------------------------------------------------------------- /junit5-migration-support/src/main/resources/logback.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | %d{yyyy-MM-dd HH:mm:ss} [%thread] %-5level %logger{36}.%M\(%line\) -- %msg%n 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /junit5-migration-support/src/test/java/io/github/bonigarcia/ErrorCollectorRuleTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * (C) Copyright 2017 Boni Garcia (https://bonigarcia.github.io/) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | */ 17 | package io.github.bonigarcia; 18 | 19 | import static org.hamcrest.CoreMatchers.equalTo; 20 | 21 | import org.junit.Rule; 22 | import org.junit.jupiter.api.Disabled; 23 | import org.junit.jupiter.api.Test; 24 | import org.junit.jupiter.migrationsupport.rules.EnableRuleMigrationSupport; 25 | import org.junit.rules.ErrorCollector; 26 | 27 | @EnableRuleMigrationSupport 28 | class ErrorCollectorRuleTest { 29 | 30 | @Rule 31 | public ErrorCollector collector = new ErrorCollector(); 32 | 33 | @Disabled 34 | @Test 35 | void test() { 36 | collector.checkThat("a", equalTo("b")); 37 | collector.checkThat(1, equalTo(2)); 38 | collector.checkThat("c", equalTo("c")); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /junit5-mockito/build.gradle: -------------------------------------------------------------------------------- 1 | repositories { 2 | mavenCentral() 3 | } 4 | 5 | ext { 6 | slf4jVersion = '2.0.17' 7 | logbackVersion = '1.5.18' 8 | 9 | junitJupiterVersion = '5.13.0' 10 | mockitoJupiterVersion = '5.18.0' 11 | } 12 | 13 | apply plugin: 'java' 14 | apply plugin: 'eclipse' 15 | apply plugin: 'idea' 16 | 17 | jar { 18 | archiveBaseName = 'junit5-mockito' 19 | archiveVersion = '1.0.0' 20 | } 21 | 22 | test { 23 | useJUnitPlatform() 24 | 25 | testLogging { 26 | events "passed", "skipped", "failed" 27 | showStandardStreams = true 28 | } 29 | } 30 | 31 | compileTestJava { 32 | sourceCompatibility = 17 33 | targetCompatibility = 17 34 | options.compilerArgs += '-parameters' 35 | } 36 | 37 | dependencies { 38 | implementation("org.slf4j:slf4j-api:${slf4jVersion}") 39 | implementation("ch.qos.logback:logback-classic:${logbackVersion}") 40 | 41 | testImplementation("org.junit.jupiter:junit-jupiter:${junitJupiterVersion}") 42 | testImplementation("org.mockito:mockito-junit-jupiter:${mockitoJupiterVersion}") 43 | } 44 | -------------------------------------------------------------------------------- /junit5-mockito/src/main/java/io/github/bonigarcia/LoginException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * (C) Copyright 2017 Boni Garcia (https://bonigarcia.github.io/) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | */ 17 | package io.github.bonigarcia; 18 | 19 | public class LoginException extends RuntimeException { 20 | 21 | private static final long serialVersionUID = 1L; 22 | 23 | public LoginException(String cause) { 24 | super(cause); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /junit5-mockito/src/main/resources/logback.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | %d{yyyy-MM-dd HH:mm:ss} [%thread] %-5level %logger{36}.%M\(%line\) -- %msg%n 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /junit5-nested-tests/build.gradle: -------------------------------------------------------------------------------- 1 | repositories { 2 | mavenCentral() 3 | } 4 | 5 | ext { 6 | slf4jVersion = '2.0.17' 7 | logbackVersion = '1.5.18' 8 | 9 | junitJupiterVersion = '5.13.0' 10 | } 11 | 12 | apply plugin: 'java' 13 | apply plugin: 'eclipse' 14 | apply plugin: 'idea' 15 | 16 | jar { 17 | archiveBaseName = 'junit5-nested-tests' 18 | archiveVersion = '1.0.0' 19 | } 20 | 21 | test { 22 | useJUnitPlatform() 23 | 24 | testLogging { 25 | events "passed", "skipped", "failed" 26 | showStandardStreams = true 27 | } 28 | } 29 | 30 | compileTestJava { 31 | sourceCompatibility = 17 32 | targetCompatibility = 17 33 | options.compilerArgs += '-parameters' 34 | } 35 | 36 | dependencies { 37 | implementation("org.slf4j:slf4j-api:${slf4jVersion}") 38 | implementation("ch.qos.logback:logback-classic:${logbackVersion}") 39 | 40 | testImplementation("org.junit.jupiter:junit-jupiter:${junitJupiterVersion}") 41 | } 42 | -------------------------------------------------------------------------------- /junit5-nested-tests/src/main/resources/logback.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | %d{yyyy-MM-dd HH:mm:ss} [%thread] %-5level %logger{36}.%M\(%line\) -- %msg%n 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /junit5-ordered-tests/build.gradle: -------------------------------------------------------------------------------- 1 | repositories { 2 | mavenCentral() 3 | } 4 | 5 | ext { 6 | slf4jVersion = '2.0.17' 7 | logbackVersion = '1.5.18' 8 | 9 | junitJupiterVersion = '5.13.0' 10 | } 11 | 12 | apply plugin: 'java' 13 | apply plugin: 'eclipse' 14 | apply plugin: 'idea' 15 | 16 | jar { 17 | archiveBaseName = 'junit5-nested-tests' 18 | archiveVersion = '1.0.0' 19 | } 20 | 21 | test { 22 | useJUnitPlatform() 23 | 24 | testLogging { 25 | events "passed", "skipped", "failed" 26 | showStandardStreams = true 27 | } 28 | } 29 | 30 | compileTestJava { 31 | sourceCompatibility = 17 32 | targetCompatibility = 17 33 | options.compilerArgs += '-parameters' 34 | } 35 | 36 | dependencies { 37 | implementation("org.slf4j:slf4j-api:${slf4jVersion}") 38 | implementation("ch.qos.logback:logback-classic:${logbackVersion}") 39 | 40 | testImplementation("org.junit.jupiter:junit-jupiter:${junitJupiterVersion}") 41 | } 42 | -------------------------------------------------------------------------------- /junit5-ordered-tests/src/main/resources/logback.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | %d{yyyy-MM-dd HH:mm:ss} [%thread] %-5level %logger{36}.%M\(%line\) -- %msg%n 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /junit5-ordered-tests/src/test/java/io/github/bonigarcia/NameOrderedTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * (C) Copyright 2020 Boni Garcia (https://bonigarcia.github.io/) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | */ 17 | package io.github.bonigarcia; 18 | 19 | import org.junit.jupiter.api.MethodOrderer; 20 | import org.junit.jupiter.api.Test; 21 | import org.junit.jupiter.api.TestMethodOrder; 22 | import org.slf4j.Logger; 23 | 24 | import static java.lang.invoke.MethodHandles.lookup; 25 | import static org.slf4j.LoggerFactory.getLogger; 26 | 27 | @TestMethodOrder(MethodOrderer.MethodName.class) 28 | class NameOrderedTest { 29 | 30 | static final Logger log = getLogger(lookup().lookupClass()); 31 | 32 | @Test 33 | void testStep1() { 34 | log.debug("Step 1"); 35 | } 36 | 37 | @Test 38 | void testStep2() { 39 | log.debug("Step 2"); 40 | } 41 | 42 | } 43 | -------------------------------------------------------------------------------- /junit5-ordered-tests/src/test/java/io/github/bonigarcia/OrderedTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * (C) Copyright 2020 Boni Garcia (https://bonigarcia.github.io/) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | */ 17 | package io.github.bonigarcia; 18 | 19 | import org.junit.jupiter.api.MethodOrderer.OrderAnnotation; 20 | import org.slf4j.Logger; 21 | 22 | import static java.lang.invoke.MethodHandles.lookup; 23 | import static org.slf4j.LoggerFactory.getLogger; 24 | 25 | import org.junit.jupiter.api.Order; 26 | import org.junit.jupiter.api.Test; 27 | import org.junit.jupiter.api.TestMethodOrder; 28 | 29 | @TestMethodOrder(OrderAnnotation.class) 30 | class OrderedTest { 31 | 32 | static final Logger log = getLogger(lookup().lookupClass()); 33 | 34 | @Test 35 | @Order(1) 36 | void testStep1() { 37 | log.debug("Step 1"); 38 | } 39 | 40 | @Test 41 | @Order(2) 42 | void testStep2() { 43 | log.debug("Step 2"); 44 | } 45 | 46 | } 47 | -------------------------------------------------------------------------------- /junit5-parallel-execution/build.gradle: -------------------------------------------------------------------------------- 1 | repositories { 2 | mavenCentral() 3 | } 4 | 5 | ext { 6 | junitJupiterVersion = '5.13.0' 7 | slf4jVersion = '2.0.17' 8 | logbackVersion = '1.5.18' 9 | } 10 | 11 | apply plugin: 'java' 12 | apply plugin: 'eclipse' 13 | apply plugin: 'idea' 14 | 15 | jar { 16 | archiveBaseName = 'junit5-parallel-execution' 17 | archiveVersion = '1.0.0' 18 | } 19 | 20 | test { 21 | useJUnitPlatform() 22 | 23 | testLogging { 24 | events "passed", "skipped", "failed" 25 | showStandardStreams = true 26 | } 27 | } 28 | 29 | compileTestJava { 30 | sourceCompatibility = 17 31 | targetCompatibility = 17 32 | options.compilerArgs += '-parameters' 33 | } 34 | 35 | dependencies { 36 | testImplementation("org.junit.jupiter:junit-jupiter:${junitJupiterVersion}") 37 | testImplementation("org.slf4j:slf4j-api:${slf4jVersion}") 38 | testImplementation("ch.qos.logback:logback-classic:${logbackVersion}") 39 | } 40 | -------------------------------------------------------------------------------- /junit5-parallel-execution/src/main/resources/logback-test.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | %d{yyyy-MM-dd HH:mm:ss} [%thread] %-5level %logger{36}.%M\(%line\) -- %msg%n 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /junit5-parallel-execution/src/test/java/io/github/bonigarcia/ParallelExecution01Test.java: -------------------------------------------------------------------------------- 1 | /* 2 | * (C) Copyright 2020 Boni Garcia (https://bonigarcia.github.io/) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | */ 17 | package io.github.bonigarcia; 18 | 19 | import static java.lang.invoke.MethodHandles.lookup; 20 | import static org.slf4j.LoggerFactory.getLogger; 21 | 22 | import org.junit.jupiter.api.Test; 23 | import org.slf4j.Logger; 24 | 25 | class ParallelExecution01Test { 26 | 27 | static final Logger log = getLogger(lookup().lookupClass()); 28 | 29 | @Test 30 | void test01() { 31 | log.debug("01.test01"); 32 | } 33 | 34 | @Test 35 | void test02() { 36 | log.debug("01.test02"); 37 | } 38 | 39 | } 40 | -------------------------------------------------------------------------------- /junit5-parallel-execution/src/test/java/io/github/bonigarcia/ParallelExecution02Test.java: -------------------------------------------------------------------------------- 1 | /* 2 | * (C) Copyright 2020 Boni Garcia (https://bonigarcia.github.io/) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | */ 17 | package io.github.bonigarcia; 18 | 19 | import static java.lang.invoke.MethodHandles.lookup; 20 | import static org.slf4j.LoggerFactory.getLogger; 21 | 22 | import org.junit.jupiter.api.Test; 23 | import org.slf4j.Logger; 24 | 25 | class ParallelExecution02Test { 26 | 27 | static final Logger log = getLogger(lookup().lookupClass()); 28 | 29 | @Test 30 | void test01() { 31 | log.debug("02.test01"); 32 | } 33 | 34 | @Test 35 | void test02() { 36 | log.debug("02.test02"); 37 | } 38 | 39 | } 40 | -------------------------------------------------------------------------------- /junit5-parallel-execution/src/test/resources/junit-platform.properties: -------------------------------------------------------------------------------- 1 | junit.jupiter.execution.parallel.enabled = true 2 | junit.jupiter.execution.parallel.mode.default = concurrent 3 | junit.jupiter.execution.parallel.mode.classes.default = same_thread 4 | 5 | # junit.jupiter.execution.parallel.config.strategy = fixed 6 | # junit.jupiter.execution.parallel.config.fixed.parallelism = 2 7 | -------------------------------------------------------------------------------- /junit5-parameterized/build.gradle: -------------------------------------------------------------------------------- 1 | repositories { 2 | mavenCentral() 3 | } 4 | 5 | ext { 6 | slf4jVersion = '2.0.17' 7 | logbackVersion = '1.5.18' 8 | 9 | junitJupiterVersion = '5.13.0' 10 | } 11 | 12 | apply plugin: 'java' 13 | apply plugin: 'eclipse' 14 | apply plugin: 'idea' 15 | 16 | jar { 17 | archiveBaseName = 'junit5-parameterized' 18 | archiveVersion = '1.0.0' 19 | } 20 | 21 | test { 22 | useJUnitPlatform() 23 | 24 | testLogging { 25 | events "passed", "skipped", "failed" 26 | showStandardStreams = true 27 | } 28 | } 29 | 30 | compileTestJava { 31 | sourceCompatibility = 17 32 | targetCompatibility = 17 33 | options.compilerArgs += '-parameters' 34 | } 35 | 36 | dependencies { 37 | implementation("org.slf4j:slf4j-api:${slf4jVersion}") 38 | implementation("ch.qos.logback:logback-classic:${logbackVersion}") 39 | 40 | testImplementation("org.junit.jupiter:junit-jupiter:${junitJupiterVersion}") 41 | } 42 | -------------------------------------------------------------------------------- /junit5-parameterized/src/main/resources/logback.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | %d{yyyy-MM-dd HH:mm:ss} [%thread] %-5level %logger{36}.%M\(%line\) -- %msg%n 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /junit5-parameterized/src/test/java/io/github/bonigarcia/CustomArgumentsConverter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * (C) Copyright 2017 Boni Garcia (https://bonigarcia.github.io/) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | */ 17 | package io.github.bonigarcia; 18 | 19 | import org.junit.jupiter.params.converter.SimpleArgumentConverter; 20 | 21 | public class CustomArgumentsConverter extends SimpleArgumentConverter { 22 | 23 | @Override 24 | protected Object convert(Object source, Class targetType) { 25 | return String.valueOf(source); 26 | } 27 | 28 | } 29 | -------------------------------------------------------------------------------- /junit5-parameterized/src/test/java/io/github/bonigarcia/EmptySourceParameterizedTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * (C) Copyright 2017 Boni Garcia (https://bonigarcia.github.io/) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | */ 17 | package io.github.bonigarcia; 18 | 19 | import static java.lang.invoke.MethodHandles.lookup; 20 | import static org.slf4j.LoggerFactory.getLogger; 21 | 22 | import org.junit.jupiter.params.ParameterizedTest; 23 | import org.junit.jupiter.params.provider.EmptySource; 24 | import org.junit.jupiter.params.provider.ValueSource; 25 | import org.slf4j.Logger; 26 | 27 | class EmptySourceParameterizedTest { 28 | 29 | static final Logger log = getLogger(lookup().lookupClass()); 30 | 31 | @ParameterizedTest 32 | @ValueSource(strings = { "three", "four" }) 33 | @EmptySource 34 | void testWithStringsAndEmpty(String argument) { 35 | log.debug("arg: {}", argument); 36 | } 37 | 38 | } 39 | -------------------------------------------------------------------------------- /junit5-parameterized/src/test/java/io/github/bonigarcia/EnumSourceParameterizedTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * (C) Copyright 2017 Boni Garcia (https://bonigarcia.github.io/) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | */ 17 | package io.github.bonigarcia; 18 | 19 | import static java.lang.invoke.MethodHandles.lookup; 20 | import static org.junit.jupiter.api.Assertions.assertNotNull; 21 | import static org.slf4j.LoggerFactory.getLogger; 22 | 23 | import java.util.concurrent.TimeUnit; 24 | 25 | import org.junit.jupiter.params.ParameterizedTest; 26 | import org.junit.jupiter.params.provider.EnumSource; 27 | import org.slf4j.Logger; 28 | 29 | class EnumSourceParameterizedTest { 30 | 31 | static final Logger log = getLogger(lookup().lookupClass()); 32 | 33 | @ParameterizedTest 34 | @EnumSource(TimeUnit.class) 35 | void testWithEnum(TimeUnit argument) { 36 | log.debug("Parameterized test with (TimeUnit) argument: {}", argument); 37 | assertNotNull(argument); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /junit5-parameterized/src/test/java/io/github/bonigarcia/NullAndEmptySourceParameterizedTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * (C) Copyright 2017 Boni Garcia (https://bonigarcia.github.io/) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | */ 17 | package io.github.bonigarcia; 18 | 19 | import static java.lang.invoke.MethodHandles.lookup; 20 | import static org.slf4j.LoggerFactory.getLogger; 21 | 22 | import org.junit.jupiter.params.ParameterizedTest; 23 | import org.junit.jupiter.params.provider.NullAndEmptySource; 24 | import org.junit.jupiter.params.provider.ValueSource; 25 | import org.slf4j.Logger; 26 | 27 | class NullAndEmptySourceParameterizedTest { 28 | 29 | static final Logger log = getLogger(lookup().lookupClass()); 30 | 31 | @ParameterizedTest 32 | @ValueSource(strings = { "five", "six" }) 33 | @NullAndEmptySource 34 | void testWithStringsAndNullAndEmpty(String arg) { 35 | log.debug("arg: {}", arg); 36 | } 37 | 38 | } 39 | -------------------------------------------------------------------------------- /junit5-parameterized/src/test/java/io/github/bonigarcia/NullSourceParameterizedTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * (C) Copyright 2017 Boni Garcia (https://bonigarcia.github.io/) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | */ 17 | package io.github.bonigarcia; 18 | 19 | import static java.lang.invoke.MethodHandles.lookup; 20 | import static org.slf4j.LoggerFactory.getLogger; 21 | 22 | import org.junit.jupiter.params.ParameterizedTest; 23 | import org.junit.jupiter.params.provider.NullSource; 24 | import org.junit.jupiter.params.provider.ValueSource; 25 | import org.slf4j.Logger; 26 | 27 | class NullSourceParameterizedTest { 28 | 29 | static final Logger log = getLogger(lookup().lookupClass()); 30 | 31 | @ParameterizedTest 32 | @ValueSource(strings = { "one", "two" }) 33 | @NullSource 34 | void testWithStringsAndNull(String argument) { 35 | log.debug("arg: {}", argument); 36 | } 37 | 38 | } 39 | -------------------------------------------------------------------------------- /junit5-parameterized/src/test/java/io/github/bonigarcia/ValueSourceStringsParameterizedTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * (C) Copyright 2017 Boni Garcia (https://bonigarcia.github.io/) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | */ 17 | package io.github.bonigarcia; 18 | 19 | import static java.lang.invoke.MethodHandles.lookup; 20 | import static org.junit.jupiter.api.Assertions.assertNotNull; 21 | import static org.slf4j.LoggerFactory.getLogger; 22 | 23 | import org.junit.jupiter.params.ParameterizedTest; 24 | import org.junit.jupiter.params.provider.ValueSource; 25 | import org.slf4j.Logger; 26 | 27 | class ValueSourceStringsParameterizedTest { 28 | 29 | static final Logger log = getLogger(lookup().lookupClass()); 30 | 31 | @ParameterizedTest 32 | @ValueSource(strings = { "Hello", "World" }) 33 | void testWithStrings(String argument) { 34 | log.debug("Parameterized test with (String) parameter: {}", argument); 35 | assertNotNull(argument); 36 | } 37 | 38 | } 39 | -------------------------------------------------------------------------------- /junit5-parameterized/src/test/resources/input.csv: -------------------------------------------------------------------------------- 1 | Mastering, 4 2 | JUnit 5, 5 3 | "hi, there", 6 -------------------------------------------------------------------------------- /junit5-repeated-tests/build.gradle: -------------------------------------------------------------------------------- 1 | repositories { 2 | mavenCentral() 3 | } 4 | 5 | ext { 6 | slf4jVersion = '2.0.17' 7 | logbackVersion = '1.5.18' 8 | 9 | junitJupiterVersion = '5.13.0' 10 | } 11 | 12 | apply plugin: 'java' 13 | apply plugin: 'eclipse' 14 | apply plugin: 'idea' 15 | 16 | jar { 17 | archiveBaseName = 'junit5-repeated-tests' 18 | archiveVersion = '1.0.0' 19 | } 20 | 21 | test { 22 | useJUnitPlatform() 23 | 24 | testLogging { 25 | events "passed", "skipped", "failed" 26 | showStandardStreams = true 27 | } 28 | } 29 | 30 | compileTestJava { 31 | sourceCompatibility = 17 32 | targetCompatibility = 17 33 | options.compilerArgs += '-parameters' 34 | } 35 | 36 | dependencies { 37 | implementation("org.slf4j:slf4j-api:${slf4jVersion}") 38 | implementation("ch.qos.logback:logback-classic:${logbackVersion}") 39 | 40 | testImplementation("org.junit.jupiter:junit-jupiter:${junitJupiterVersion}") 41 | } 42 | -------------------------------------------------------------------------------- /junit5-repeated-tests/src/main/resources/logback.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | %d{yyyy-MM-dd HH:mm:ss} [%thread] %-5level %logger{36}.%M\(%line\) -- %msg%n 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /junit5-repeated-tests/src/test/java/io/github/bonigarcia/RepetitionInfoInRepeatedTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * (C) Copyright 2017 Boni Garcia (https://bonigarcia.github.io/) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | */ 17 | package io.github.bonigarcia; 18 | 19 | import org.junit.jupiter.api.RepeatedTest; 20 | import org.junit.jupiter.api.RepetitionInfo; 21 | import org.slf4j.Logger; 22 | 23 | import static java.lang.invoke.MethodHandles.lookup; 24 | import static org.slf4j.LoggerFactory.getLogger; 25 | 26 | class RepetitionInfoInRepeatedTest { 27 | 28 | static final Logger log = getLogger(lookup().lookupClass()); 29 | @RepeatedTest(5) 30 | void test(RepetitionInfo repetitionInfo) { 31 | log.debug("Repeated test {}/{}", repetitionInfo.getCurrentRepetition(), repetitionInfo.getTotalRepetitions()); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /junit5-repeated-tests/src/test/java/io/github/bonigarcia/SimpleRepeatedTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * (C) Copyright 2017 Boni Garcia (https://bonigarcia.github.io/) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | */ 17 | package io.github.bonigarcia; 18 | 19 | import static java.lang.invoke.MethodHandles.lookup; 20 | import static org.slf4j.LoggerFactory.getLogger; 21 | 22 | import org.junit.jupiter.api.RepeatedTest; 23 | import org.slf4j.Logger; 24 | 25 | class SimpleRepeatedTest { 26 | 27 | static final Logger log = getLogger(lookup().lookupClass()); 28 | 29 | @RepeatedTest(5) 30 | void test() { 31 | log.debug("Repeated test"); 32 | } 33 | 34 | } 35 | -------------------------------------------------------------------------------- /junit5-reporting/build.gradle: -------------------------------------------------------------------------------- 1 | repositories { 2 | mavenCentral() 3 | } 4 | 5 | ext { 6 | junitJupiterVersion = '5.13.0' 7 | } 8 | 9 | apply plugin: 'java' 10 | apply plugin: 'eclipse' 11 | apply plugin: 'idea' 12 | 13 | jar { 14 | archiveBaseName = 'junit5-reporting' 15 | archiveVersion = '1.0.0' 16 | } 17 | 18 | test { 19 | useJUnitPlatform() 20 | 21 | testLogging { 22 | events "passed", "skipped", "failed" 23 | showStandardStreams = true 24 | } 25 | 26 | // reports.junitXml.enabled = true 27 | // reports.html.enabled = true 28 | } 29 | 30 | compileTestJava { 31 | sourceCompatibility = 17 32 | targetCompatibility = 17 33 | options.compilerArgs += '-parameters' 34 | } 35 | 36 | dependencies { 37 | testImplementation("org.junit.jupiter:junit-jupiter:${junitJupiterVersion}") 38 | } 39 | -------------------------------------------------------------------------------- /junit5-reporting/src/test/java/io/github/bonigarcia/PlayingWithReportingTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * (C) Copyright 2017 Boni Garcia (https://bonigarcia.github.io/) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | */ 17 | package io.github.bonigarcia; 18 | 19 | import static org.junit.jupiter.api.Assertions.assertTrue; 20 | 21 | import org.junit.jupiter.api.Disabled; 22 | import org.junit.jupiter.api.Test; 23 | 24 | @Disabled 25 | class PlayingWithReportingTest { 26 | 27 | @Test 28 | void successTest() { 29 | assertTrue(true); 30 | } 31 | 32 | @Test 33 | void failureTest() { 34 | assertTrue(false); 35 | } 36 | 37 | @Test 38 | void errorTest() { 39 | throw new RuntimeException("This test is broken!"); 40 | } 41 | 42 | } 43 | -------------------------------------------------------------------------------- /junit5-rest-assured/build.gradle: -------------------------------------------------------------------------------- 1 | repositories { 2 | mavenCentral() 3 | } 4 | 5 | ext { 6 | junitJupiterVersion = '5.13.0' 7 | restAssuredVersion = '5.5.5' 8 | } 9 | 10 | apply plugin: 'java' 11 | apply plugin: 'eclipse' 12 | apply plugin: 'idea' 13 | 14 | jar { 15 | archiveBaseName = 'junit5-rest-assured' 16 | archiveVersion = '1.0.0' 17 | } 18 | 19 | test { 20 | useJUnitPlatform() 21 | 22 | testLogging { 23 | events "passed", "skipped", "failed" 24 | showStandardStreams = true 25 | } 26 | } 27 | 28 | compileTestJava { 29 | sourceCompatibility = 17 30 | targetCompatibility = 17 31 | options.compilerArgs += '-parameters' 32 | } 33 | 34 | dependencies { 35 | testImplementation("org.junit.jupiter:junit-jupiter:${junitJupiterVersion}") 36 | testImplementation("io.rest-assured:rest-assured:${restAssuredVersion}") 37 | } 38 | -------------------------------------------------------------------------------- /junit5-selenium/build.gradle: -------------------------------------------------------------------------------- 1 | repositories { 2 | mavenCentral() 3 | } 4 | 5 | ext { 6 | junitJupiterVersion = '5.13.0' 7 | seleniumVersion = '4.33.0' 8 | seleniumJupiterVersion = '6.1.1' 9 | } 10 | 11 | apply plugin: 'java' 12 | apply plugin: 'eclipse' 13 | apply plugin: 'idea' 14 | 15 | jar { 16 | archiveBaseName = 'junit5-selenium' 17 | archiveVersion = '1.0.0' 18 | } 19 | 20 | test { 21 | useJUnitPlatform() 22 | 23 | testLogging { 24 | events "passed", "skipped", "failed" 25 | showStandardStreams = true 26 | } 27 | } 28 | 29 | compileTestJava { 30 | sourceCompatibility = 17 31 | targetCompatibility = 17 32 | options.compilerArgs += '-parameters' 33 | } 34 | 35 | dependencies { 36 | testImplementation("org.junit.jupiter:junit-jupiter:${junitJupiterVersion}") 37 | testImplementation("org.seleniumhq.selenium:selenium-java:${seleniumVersion}") 38 | testImplementation("io.github.bonigarcia:selenium-jupiter:${seleniumJupiterVersion}") 39 | } 40 | -------------------------------------------------------------------------------- /junit5-selenium/src/main/resources/logback.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | %d{yyyy-MM-dd HH:mm:ss} [%thread] %-5level %logger{36}.%M\(%line\) -- %msg%n 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /junit5-spring-boot-rest/build.gradle: -------------------------------------------------------------------------------- 1 | buildscript { 2 | ext { 3 | springBootVersion = '3.5.0' 4 | } 5 | repositories { 6 | mavenCentral() 7 | } 8 | dependencies { 9 | classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}") 10 | } 11 | } 12 | 13 | repositories { 14 | mavenCentral() 15 | } 16 | 17 | apply plugin: 'java' 18 | apply plugin: 'eclipse' 19 | apply plugin: 'idea' 20 | apply plugin: 'org.springframework.boot' 21 | apply plugin: 'io.spring.dependency-management' 22 | 23 | jar { 24 | archiveBaseName = 'junit5-spring-boot-rest' 25 | archiveVersion = '1.0.0' 26 | } 27 | 28 | test { 29 | useJUnitPlatform() 30 | 31 | testLogging { 32 | events "passed", "skipped", "failed" 33 | showStandardStreams = true 34 | } 35 | } 36 | 37 | compileTestJava { 38 | sourceCompatibility = 17 39 | targetCompatibility = 17 40 | options.compilerArgs += '-parameters' 41 | } 42 | 43 | dependencies { 44 | implementation('org.springframework.boot:spring-boot-starter-web') 45 | implementation('javax.annotation:javax.annotation-api:1.3.2') 46 | 47 | testImplementation("org.junit.jupiter:junit-jupiter") 48 | testImplementation("org.springframework.boot:spring-boot-starter-test") 49 | } 50 | -------------------------------------------------------------------------------- /junit5-spring-boot-rest/src/main/java/io/github/bonigarcia/SpringBootRestApp.java: -------------------------------------------------------------------------------- 1 | /* 2 | * (C) Copyright 2017 Boni Garcia (https://bonigarcia.github.io/) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | */ 17 | package io.github.bonigarcia; 18 | 19 | import org.springframework.boot.SpringApplication; 20 | import org.springframework.boot.autoconfigure.SpringBootApplication; 21 | 22 | @SpringBootApplication 23 | public class SpringBootRestApp { 24 | 25 | public static void main(String[] args) { 26 | SpringApplication.run(SpringBootRestApp.class, args); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /junit5-spring-boot-rest/src/main/resources/logback.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /junit5-spring-boot-rest/src/main/resources/static/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 |

This is index page

5 | 6 | 7 | -------------------------------------------------------------------------------- /junit5-spring-boot-rest/src/main/resources/static/page.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 |

This is page 2

5 | 6 | 7 | -------------------------------------------------------------------------------- /junit5-spring-boot-web/build.gradle: -------------------------------------------------------------------------------- 1 | buildscript { 2 | ext { 3 | springBootVersion = '3.5.0' 4 | } 5 | repositories { 6 | mavenCentral() 7 | } 8 | dependencies { 9 | classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}") 10 | } 11 | } 12 | 13 | repositories { 14 | mavenCentral() 15 | } 16 | 17 | apply plugin: 'java' 18 | apply plugin: 'eclipse' 19 | apply plugin: 'idea' 20 | apply plugin: 'org.springframework.boot' 21 | apply plugin: 'io.spring.dependency-management' 22 | 23 | jar { 24 | archiveBaseName = 'junit5-spring-boot-web' 25 | archiveVersion = '1.0.0' 26 | } 27 | 28 | test { 29 | useJUnitPlatform() 30 | 31 | testLogging { 32 | events "passed", "skipped", "failed" 33 | showStandardStreams = true 34 | } 35 | } 36 | 37 | compileTestJava { 38 | sourceCompatibility = 17 39 | targetCompatibility = 17 40 | options.compilerArgs += '-parameters' 41 | } 42 | 43 | dependencies { 44 | implementation('org.springframework.boot:spring-boot-starter-web') 45 | 46 | testImplementation("org.springframework.boot:spring-boot-starter-test") 47 | testImplementation("org.junit.jupiter:junit-jupiter") 48 | testImplementation("org.mockito:mockito-junit-jupiter") 49 | } 50 | -------------------------------------------------------------------------------- /junit5-spring-boot-web/src/main/java/io/github/bonigarcia/PageService.java: -------------------------------------------------------------------------------- 1 | /* 2 | * (C) Copyright 2017 Boni Garcia (https://bonigarcia.github.io/) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | */ 17 | package io.github.bonigarcia; 18 | 19 | import org.springframework.stereotype.Service; 20 | 21 | @Service 22 | public class PageService { 23 | 24 | public String getPage() { 25 | return "/index.html"; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /junit5-spring-boot-web/src/main/java/io/github/bonigarcia/SpringBootWebApp.java: -------------------------------------------------------------------------------- 1 | /* 2 | * (C) Copyright 2017 Boni Garcia (https://bonigarcia.github.io/) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | */ 17 | package io.github.bonigarcia; 18 | 19 | import org.springframework.boot.SpringApplication; 20 | import org.springframework.boot.autoconfigure.SpringBootApplication; 21 | 22 | @SpringBootApplication 23 | public class SpringBootWebApp { 24 | 25 | public static void main(String[] args) { 26 | SpringApplication.run(SpringBootWebApp.class, args); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /junit5-spring-boot-web/src/main/java/io/github/bonigarcia/WebController.java: -------------------------------------------------------------------------------- 1 | /* 2 | * (C) Copyright 2017 Boni Garcia (https://bonigarcia.github.io/) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | */ 17 | package io.github.bonigarcia; 18 | 19 | import static org.springframework.web.bind.annotation.RequestMethod.GET; 20 | 21 | import org.springframework.beans.factory.annotation.Autowired; 22 | import org.springframework.stereotype.Controller; 23 | import org.springframework.web.bind.annotation.RequestMapping; 24 | 25 | @Controller 26 | public class WebController { 27 | 28 | @Autowired 29 | private PageService pageService; 30 | 31 | @RequestMapping(value = "/", method = GET) 32 | public String greeting() { 33 | return pageService.getPage(); 34 | } 35 | 36 | } 37 | -------------------------------------------------------------------------------- /junit5-spring-boot-web/src/main/resources/logback.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /junit5-spring-boot-web/src/main/resources/static/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 |

This is index page

5 | 6 | 7 | -------------------------------------------------------------------------------- /junit5-spring-boot-web/src/main/resources/static/page.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 |

This is page 2

5 | 6 | 7 | -------------------------------------------------------------------------------- /junit5-spring-boot/build.gradle: -------------------------------------------------------------------------------- 1 | buildscript { 2 | ext { 3 | springBootVersion = '3.5.0' 4 | } 5 | repositories { 6 | mavenCentral() 7 | } 8 | dependencies { 9 | classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}") 10 | } 11 | } 12 | 13 | repositories { 14 | mavenCentral() 15 | } 16 | 17 | apply plugin: 'java' 18 | apply plugin: 'eclipse' 19 | apply plugin: 'idea' 20 | apply plugin: 'org.springframework.boot' 21 | apply plugin: 'io.spring.dependency-management' 22 | 23 | jar { 24 | archiveBaseName = 'junit5-spring-boot' 25 | archiveVersion = '1.0.0' 26 | } 27 | 28 | test { 29 | useJUnitPlatform() 30 | 31 | testLogging { 32 | events "passed", "skipped", "failed" 33 | showStandardStreams = true 34 | } 35 | } 36 | 37 | compileTestJava { 38 | sourceCompatibility = 17 39 | targetCompatibility = 17 40 | options.compilerArgs += '-parameters' 41 | } 42 | 43 | dependencies { 44 | implementation('org.springframework.boot:spring-boot-starter') 45 | implementation('javax.annotation:javax.annotation-api:1.3.2') 46 | 47 | testImplementation("org.springframework.boot:spring-boot-starter-test") 48 | testImplementation("org.junit.jupiter:junit-jupiter") 49 | } 50 | -------------------------------------------------------------------------------- /junit5-spring-boot/src/main/java/io/github/bonigarcia/MessageComponent.java: -------------------------------------------------------------------------------- 1 | /* 2 | * (C) Copyright 2017 Boni Garcia (https://bonigarcia.github.io/) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | */ 17 | package io.github.bonigarcia; 18 | 19 | import org.springframework.beans.factory.annotation.Autowired; 20 | import org.springframework.stereotype.Component; 21 | 22 | @Component 23 | public class MessageComponent { 24 | 25 | @Autowired 26 | private MessageService messageService; 27 | 28 | public String getMessage() { 29 | return messageService.getMessage(); 30 | } 31 | } -------------------------------------------------------------------------------- /junit5-spring-boot/src/main/java/io/github/bonigarcia/MessageService.java: -------------------------------------------------------------------------------- 1 | /* 2 | * (C) Copyright 2017 Boni Garcia (https://bonigarcia.github.io/) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | */ 17 | package io.github.bonigarcia; 18 | 19 | import org.springframework.stereotype.Service; 20 | 21 | @Service 22 | public class MessageService { 23 | 24 | public String getMessage() { 25 | return "Hello world!"; 26 | } 27 | 28 | } -------------------------------------------------------------------------------- /junit5-spring-boot/src/main/resources/logback.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /junit5-spring-boot/src/test/java/io/github/bonigarcia/SimpleSpringBootTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * (C) Copyright 2017 Boni Garcia (https://bonigarcia.github.io/) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | */ 17 | package io.github.bonigarcia; 18 | 19 | import static org.junit.jupiter.api.Assertions.assertEquals; 20 | 21 | import org.junit.jupiter.api.Test; 22 | import org.junit.jupiter.api.extension.ExtendWith; 23 | import org.springframework.beans.factory.annotation.Autowired; 24 | import org.springframework.boot.test.context.SpringBootTest; 25 | import org.springframework.test.context.junit.jupiter.SpringExtension; 26 | 27 | @ExtendWith(SpringExtension.class) 28 | @SpringBootTest 29 | class SimpleSpringBootTest { 30 | 31 | @Autowired 32 | public MessageComponent messagePrinter; 33 | 34 | @Test 35 | public void test() { 36 | assertEquals("Hello world!", messagePrinter.getMessage()); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /junit5-spring/build.gradle: -------------------------------------------------------------------------------- 1 | repositories { 2 | mavenCentral() 3 | } 4 | 5 | ext { 6 | slf4jVersion = '2.0.17' 7 | logbackVersion = '1.5.18' 8 | springVersion = '6.2.7' 9 | 10 | junitJupiterVersion = '5.13.0' 11 | } 12 | 13 | apply plugin: 'java' 14 | apply plugin: 'eclipse' 15 | apply plugin: 'idea' 16 | 17 | jar { 18 | archiveBaseName = 'junit5-spring' 19 | archiveVersion = '1.0.0' 20 | } 21 | 22 | test { 23 | useJUnitPlatform() 24 | 25 | testLogging { 26 | events "passed", "skipped", "failed" 27 | showStandardStreams = true 28 | } 29 | } 30 | 31 | compileTestJava { 32 | sourceCompatibility = 17 33 | targetCompatibility = 17 34 | options.compilerArgs += '-parameters' 35 | } 36 | 37 | dependencies { 38 | implementation("org.slf4j:slf4j-api:${slf4jVersion}") 39 | implementation("ch.qos.logback:logback-classic:${logbackVersion}") 40 | implementation("org.springframework:spring-context:${springVersion}") 41 | 42 | testImplementation("org.springframework:spring-test:${springVersion}") 43 | testImplementation("org.junit.jupiter:junit-jupiter:${junitJupiterVersion}") 44 | } 45 | -------------------------------------------------------------------------------- /junit5-spring/src/main/java/io/github/bonigarcia/MessageComponent.java: -------------------------------------------------------------------------------- 1 | /* 2 | * (C) Copyright 2017 Boni Garcia (https://bonigarcia.github.io/) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | */ 17 | package io.github.bonigarcia; 18 | 19 | import org.springframework.stereotype.Component; 20 | 21 | @Component 22 | public class MessageComponent { 23 | 24 | private MessageService messageService; 25 | 26 | public MessageComponent(MessageService messageService) { 27 | this.messageService = messageService; 28 | } 29 | 30 | public String getMessage() { 31 | return messageService.getMessage(); 32 | } 33 | 34 | } -------------------------------------------------------------------------------- /junit5-spring/src/main/java/io/github/bonigarcia/MessageService.java: -------------------------------------------------------------------------------- 1 | /* 2 | * (C) Copyright 2017 Boni Garcia (https://bonigarcia.github.io/) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | */ 17 | package io.github.bonigarcia; 18 | 19 | import org.springframework.stereotype.Service; 20 | 21 | @Service 22 | public class MessageService { 23 | 24 | public String getMessage() { 25 | return "Hello world!"; 26 | } 27 | 28 | } -------------------------------------------------------------------------------- /junit5-spring/src/main/resources/logback.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | %d{yyyy-MM-dd HH:mm:ss} [%thread] %-5level %logger{36}.%M\(%line\) -- %msg%n 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /junit5-spring/src/test/java/io/github/bonigarcia/SimpleSpringTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * (C) Copyright 2017 Boni Garcia (https://bonigarcia.github.io/) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | */ 17 | package io.github.bonigarcia; 18 | 19 | import static org.junit.jupiter.api.Assertions.assertEquals; 20 | 21 | import org.junit.jupiter.api.Test; 22 | import org.junit.jupiter.api.extension.ExtendWith; 23 | import org.springframework.beans.factory.annotation.Autowired; 24 | import org.springframework.test.context.ContextConfiguration; 25 | import org.springframework.test.context.junit.jupiter.SpringExtension; 26 | 27 | @ExtendWith(SpringExtension.class) 28 | @ContextConfiguration(classes = { MySpringApplication.class }) 29 | class SimpleSpringTest { 30 | 31 | @Autowired 32 | public MessageComponent messageComponent; 33 | 34 | @Test 35 | public void test() { 36 | assertEquals("Hello world!", messageComponent.getMessage()); 37 | } 38 | 39 | } 40 | -------------------------------------------------------------------------------- /junit5-tagging-filtering/build.gradle: -------------------------------------------------------------------------------- 1 | repositories { 2 | mavenCentral() 3 | } 4 | 5 | ext { 6 | slf4jVersion = '2.0.17' 7 | logbackVersion = '1.5.18' 8 | 9 | junitJupiterVersion = '5.13.0' 10 | } 11 | 12 | apply plugin: 'java' 13 | apply plugin: 'eclipse' 14 | apply plugin: 'idea' 15 | 16 | jar { 17 | archiveBaseName = 'junit5-tagging-filtering' 18 | archiveVersion = '1.0.0' 19 | } 20 | 21 | test { 22 | useJUnitPlatform { 23 | includeTags 'non-functional' 24 | excludeTags 'functional' 25 | } 26 | 27 | testLogging { 28 | events "passed", "skipped", "failed" 29 | showStandardStreams = true 30 | } 31 | } 32 | 33 | tasks.register("functionalTest", Test) { 34 | useJUnitPlatform { 35 | includeTags 'functional' 36 | excludeTags 'non-functional' 37 | } 38 | 39 | mustRunAfter check 40 | 41 | testLogging { 42 | events "passed", "skipped", "failed" 43 | showStandardStreams = true 44 | } 45 | } 46 | 47 | compileTestJava { 48 | sourceCompatibility = 17 49 | targetCompatibility = 17 50 | options.compilerArgs += '-parameters' 51 | } 52 | 53 | dependencies { 54 | implementation("org.slf4j:slf4j-api:${slf4jVersion}") 55 | implementation("ch.qos.logback:logback-classic:${logbackVersion}") 56 | 57 | testImplementation("org.junit.jupiter:junit-jupiter:${junitJupiterVersion}") 58 | } 59 | -------------------------------------------------------------------------------- /junit5-tagging-filtering/src/main/resources/logback.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | %d{yyyy-MM-dd HH:mm:ss} [%thread] %-5level %logger{36}.%M\(%line\) -- %msg%n 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /junit5-tagging-filtering/src/test/java/io/github/bonigarcia/FunctionalTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * (C) Copyright 2017 Boni Garcia (https://bonigarcia.github.io/) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | */ 17 | package io.github.bonigarcia; 18 | 19 | import static java.lang.invoke.MethodHandles.lookup; 20 | import static org.slf4j.LoggerFactory.getLogger; 21 | 22 | import org.junit.jupiter.api.Tag; 23 | import org.junit.jupiter.api.Test; 24 | import org.slf4j.Logger; 25 | 26 | @Tag("functional") 27 | class FunctionalTest { 28 | 29 | static final Logger log = getLogger(lookup().lookupClass()); 30 | 31 | @Test 32 | void testOne() { 33 | log.debug("Functional Test 1"); 34 | } 35 | 36 | @Test 37 | void testTwo() { 38 | log.debug("Functional Test 2"); 39 | } 40 | 41 | } 42 | -------------------------------------------------------------------------------- /junit5-test-interfaces/build.gradle: -------------------------------------------------------------------------------- 1 | repositories { 2 | mavenCentral() 3 | } 4 | 5 | ext { 6 | junitJupiterVersion = '5.13.0' 7 | slf4jVersion = '2.0.17' 8 | } 9 | 10 | apply plugin: 'java' 11 | apply plugin: 'eclipse' 12 | apply plugin: 'idea' 13 | 14 | jar { 15 | archiveBaseName = 'junit5-test-interfaces' 16 | archiveVersion = '1.0.0' 17 | } 18 | 19 | test { 20 | useJUnitPlatform() 21 | 22 | testLogging { 23 | events "passed", "skipped", "failed" 24 | showStandardStreams = true 25 | } 26 | } 27 | 28 | compileTestJava { 29 | sourceCompatibility = 17 30 | targetCompatibility = 17 31 | options.compilerArgs += '-parameters' 32 | } 33 | 34 | dependencies { 35 | implementation("org.junit.jupiter:junit-jupiter:${junitJupiterVersion}") 36 | implementation("org.slf4j:slf4j-api:${slf4jVersion}") 37 | } 38 | -------------------------------------------------------------------------------- /junit5-test-interfaces/src/main/java/io/github/bonigarcia/TestInterfaceDynamicTestsDemo.java: -------------------------------------------------------------------------------- 1 | /* 2 | * (C) Copyright 2017 Boni Garcia (https://bonigarcia.github.io/) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | */ 17 | package io.github.bonigarcia; 18 | 19 | import static org.junit.jupiter.api.Assertions.assertTrue; 20 | import static org.junit.jupiter.api.DynamicTest.dynamicTest; 21 | 22 | import java.util.Arrays; 23 | import java.util.Collection; 24 | 25 | import org.junit.jupiter.api.DynamicTest; 26 | import org.junit.jupiter.api.TestFactory; 27 | 28 | interface TestInterfaceDynamicTestsDemo { 29 | 30 | @TestFactory 31 | default Collection dynamicTestsFromCollection() { 32 | return Arrays.asList( 33 | dynamicTest("1st dynamic test in test interface", 34 | () -> assertTrue(true)), 35 | dynamicTest("2nd dynamic test in test interface", 36 | () -> assertTrue(true))); 37 | } 38 | 39 | } -------------------------------------------------------------------------------- /junit5-test-interfaces/src/main/java/io/github/bonigarcia/TimeExecutionLogger.java: -------------------------------------------------------------------------------- 1 | /* 2 | * (C) Copyright 2017 Boni Garcia (https://bonigarcia.github.io/) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | */ 17 | package io.github.bonigarcia; 18 | 19 | import org.junit.jupiter.api.Tag; 20 | import org.junit.jupiter.api.extension.ExtendWith; 21 | 22 | @Tag("timed") 23 | @ExtendWith(TimingExtension.class) 24 | public interface TimeExecutionLogger { 25 | } -------------------------------------------------------------------------------- /junit5-test-interfaces/src/main/resources/logback.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | %d{yyyy-MM-dd HH:mm:ss} [%thread] %-5level %logger{36}.%M\(%line\) -- %msg%n 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /junit5-test-interfaces/src/test/java/io/github/bonigarcia/TestInterfaceTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * (C) Copyright 2017 Boni Garcia (https://bonigarcia.github.io/) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | */ 17 | package io.github.bonigarcia; 18 | 19 | import static org.junit.jupiter.api.Assertions.assertEquals; 20 | 21 | import org.junit.jupiter.api.Test; 22 | 23 | class TestInterfaceTest implements TestLifecycleLogger, TimeExecutionLogger, 24 | TestInterfaceDynamicTestsDemo { 25 | 26 | @Test 27 | void isEqualValue() { 28 | assertEquals(1, 1); 29 | } 30 | 31 | } -------------------------------------------------------------------------------- /junit5-test-templates/build.gradle: -------------------------------------------------------------------------------- 1 | repositories { 2 | mavenCentral() 3 | } 4 | 5 | ext { 6 | slf4jVersion = '2.0.17' 7 | logbackVersion = '1.5.18' 8 | 9 | junitJupiterVersion = '5.13.0' 10 | } 11 | 12 | apply plugin: 'java' 13 | apply plugin: 'eclipse' 14 | apply plugin: 'idea' 15 | 16 | jar { 17 | archiveBaseName = 'junit5-test-templates' 18 | archiveVersion = '1.0.0' 19 | } 20 | 21 | test { 22 | useJUnitPlatform() 23 | 24 | testLogging { 25 | events "passed", "skipped", "failed" 26 | showStandardStreams = true 27 | } 28 | } 29 | 30 | compileTestJava { 31 | sourceCompatibility = 17 32 | targetCompatibility = 17 33 | options.compilerArgs += '-parameters' 34 | } 35 | 36 | dependencies { 37 | implementation("org.slf4j:slf4j-api:${slf4jVersion}") 38 | implementation("ch.qos.logback:logback-classic:${logbackVersion}") 39 | 40 | testImplementation("org.junit.jupiter:junit-jupiter:${junitJupiterVersion}") 41 | } 42 | -------------------------------------------------------------------------------- /junit5-test-templates/src/main/resources/logback.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | %d{yyyy-MM-dd HH:mm:ss} [%thread] %-5level %logger{36}.%M\(%line\) -- %msg%n 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /junit5-test-templates/src/test/java/io/github/bonigarcia/TemplateTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * (C) Copyright 2017 Boni Garcia (https://bonigarcia.github.io/) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | */ 17 | package io.github.bonigarcia; 18 | 19 | import static java.lang.invoke.MethodHandles.lookup; 20 | import static org.slf4j.LoggerFactory.getLogger; 21 | 22 | import org.junit.jupiter.api.TestTemplate; 23 | import org.junit.jupiter.api.extension.ExtendWith; 24 | import org.slf4j.Logger; 25 | 26 | class TemplateTest { 27 | 28 | static final Logger log = getLogger(lookup().lookupClass()); 29 | 30 | @TestTemplate 31 | @ExtendWith(MyTestTemplateInvocationContextProvider.class) 32 | void testTemplate(String parameter) { 33 | log.debug("Parameter: {}", parameter); 34 | } 35 | 36 | } 37 | -------------------------------------------------------------------------------- /junit5-vintage/build.gradle: -------------------------------------------------------------------------------- 1 | repositories { 2 | mavenCentral() 3 | } 4 | 5 | ext { 6 | slf4jVersion = '2.0.17' 7 | logbackVersion = '1.5.18' 8 | 9 | junitVintageVersion = '5.13.0' 10 | 11 | junitLegacyVersion = '4.13.2' 12 | } 13 | 14 | apply plugin: 'java' 15 | apply plugin: 'eclipse' 16 | apply plugin: 'idea' 17 | 18 | jar { 19 | archiveBaseName = 'junit5-vintage' 20 | archiveVersion = '1.0.0' 21 | } 22 | 23 | test { 24 | useJUnitPlatform() 25 | } 26 | 27 | compileTestJava { 28 | sourceCompatibility = 17 29 | targetCompatibility = 17 30 | options.compilerArgs += '-parameters' 31 | } 32 | 33 | dependencies { 34 | implementation("org.slf4j:slf4j-api:${slf4jVersion}") 35 | implementation("ch.qos.logback:logback-classic:${logbackVersion}") 36 | 37 | testImplementation("junit:junit:${junitLegacyVersion}") 38 | 39 | testRuntimeOnly("org.junit.vintage:junit-vintage-engine:${junitVintageVersion}") 40 | } 41 | -------------------------------------------------------------------------------- /junit5-vintage/src/main/resources/logback.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | %d{yyyy-MM-dd HH:mm:ss} [%thread] %-5level %logger{36}.%M\(%line\) -- %msg%n 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /junit5-vintage/src/test/java/io/github/bonigarcia/LegacyJUnit4Test.java: -------------------------------------------------------------------------------- 1 | /* 2 | * (C) Copyright 2017 Boni Garcia (https://bonigarcia.github.io/) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | */ 17 | package io.github.bonigarcia; 18 | 19 | import static java.lang.invoke.MethodHandles.lookup; 20 | import static org.junit.Assert.assertEquals; 21 | import static org.slf4j.LoggerFactory.getLogger; 22 | 23 | import org.junit.Test; 24 | import org.slf4j.Logger; 25 | 26 | public class LegacyJUnit4Test { 27 | 28 | static final Logger log = getLogger(lookup().lookupClass()); 29 | 30 | @Test 31 | public void myFirstTest() { 32 | String message = "1+1 should be equal to 2"; 33 | log.debug(message); 34 | 35 | assertEquals(message, 2, 1 + 1); 36 | } 37 | 38 | } 39 | -------------------------------------------------------------------------------- /junit5-wiremock/build.gradle: -------------------------------------------------------------------------------- 1 | repositories { 2 | mavenCentral() 3 | } 4 | 5 | ext { 6 | slf4jVersion = '2.0.17' 7 | logbackVersion = '1.5.18' 8 | retrofitVersion = '3.0.0' 9 | junitJupiterVersion = '5.13.0' 10 | wireMockVersion = '3.0.1' 11 | } 12 | 13 | apply plugin: 'java' 14 | apply plugin: 'eclipse' 15 | apply plugin: 'idea' 16 | 17 | jar { 18 | archiveBaseName = 'junit5-wiremock' 19 | archiveVersion = '1.0.0' 20 | } 21 | 22 | test { 23 | useJUnitPlatform() 24 | 25 | testLogging { 26 | events "passed", "skipped", "failed" 27 | showStandardStreams = true 28 | } 29 | } 30 | 31 | compileTestJava { 32 | sourceCompatibility = 17 33 | targetCompatibility = 17 34 | options.compilerArgs += '-parameters' 35 | } 36 | 37 | dependencies { 38 | implementation("org.slf4j:slf4j-api:${slf4jVersion}") 39 | implementation("ch.qos.logback:logback-classic:${logbackVersion}") 40 | implementation("com.squareup.retrofit2:retrofit:${retrofitVersion}") 41 | implementation("com.squareup.retrofit2:adapter-rxjava:${retrofitVersion}") 42 | implementation("com.squareup.retrofit2:converter-gson:${retrofitVersion}") 43 | 44 | testImplementation("org.junit.jupiter:junit-jupiter:${junitJupiterVersion}") 45 | testImplementation("com.github.tomakehurst:wiremock:${wireMockVersion}") 46 | } 47 | -------------------------------------------------------------------------------- /junit5-wiremock/src/main/java/io/github/bonigarcia/RemoteFileApi.java: -------------------------------------------------------------------------------- 1 | /* 2 | * (C) Copyright 2017 Boni Garcia (https://bonigarcia.github.io/) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | */ 17 | package io.github.bonigarcia; 18 | 19 | import okhttp3.ResponseBody; 20 | import retrofit2.Call; 21 | import retrofit2.http.POST; 22 | import retrofit2.http.Path; 23 | 24 | public interface RemoteFileApi { 25 | 26 | @POST("/api/v1/paths/{file}/open-file") 27 | Call openFile(@Path("file") String file); 28 | 29 | @POST("/api/v1/streams/{streamId}/read") 30 | Call readStream(@Path("streamId") String streamId); 31 | 32 | @POST("/api/v1/streams/{streamId}/close") 33 | Call closeStream(@Path("streamId") String streamId); 34 | 35 | } 36 | -------------------------------------------------------------------------------- /junit5-wiremock/src/main/resources/logback.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | %d{yyyy-MM-dd HH:mm:ss} [%thread] %-5level %logger{36}.%M\(%line\) -- %msg%n 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | include ':junit5-allure' 2 | include ':junit5-android' 3 | include ':junit5-assertions' 4 | include ':junit5-basic-tests' 5 | include ':junit5-console-launcher' 6 | include ':junit5-cucumber' 7 | include ':junit5-cucumber-selenium' 8 | include ':junit5-dependency-injection' 9 | include ':junit5-disabled-tests' 10 | include ':junit5-docker' 11 | include ':junit5-dynamic-tests' 12 | include ':junit5-engine-spi' 13 | include ':junit5-extension-model' 14 | include ':junit5-extension-model-automatic' 15 | include ':junit5-gradle-hello-world' 16 | include ':junit5-junit4-runner' 17 | include ':junit5-launcher-api' 18 | include ':junit5-meta-annotations' 19 | include ':junit5-migration-support' 20 | include ':junit5-mockito' 21 | include ':junit5-nested-tests' 22 | include ':junit5-ordered-tests' 23 | include ':junit5-parallel-execution' 24 | include ':junit5-parameterized' 25 | include ':junit5-repeated-tests' 26 | include ':junit5-reporting' 27 | include ':junit5-rest-assured' 28 | include ':junit5-selenium' 29 | include ':junit5-spring' 30 | include ':junit5-spring-boot' 31 | include ':junit5-spring-boot-rest' 32 | include ':junit5-spring-boot-web' 33 | include ':junit5-tagging-filtering' 34 | include ':junit5-test-interfaces' 35 | include ':junit5-test-templates' 36 | include ':junit5-vintage' 37 | include ':junit5-wiremock' 38 | --------------------------------------------------------------------------------