├── .github ├── ISSUE_TEMPLATE │ ├── bug_report.md │ └── feature_request.md └── workflows │ ├── ci.yml │ ├── promote.yml │ └── release.yml ├── .gitignore ├── CHANGELOG.md ├── LICENSE ├── README.md ├── README_TEMPLATE.md ├── build.gradle ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── integration_manual_files ├── note_junit5_properties.png ├── step_add_project.png ├── step_add_project2.png ├── step_add_run_configuration.png ├── step_add_user.png ├── step_group_and_artifact_id.png ├── step_launches.png ├── step_new_maven_project.png ├── step_project_name.png ├── step_project_structure.png ├── step_test_results.png └── step_user_profile.png ├── settings.gradle └── src ├── main ├── java │ └── com │ │ └── epam │ │ └── reportportal │ │ └── junit5 │ │ ├── ItemType.java │ │ ├── ReportPortalExtension.java │ │ ├── SystemAttributesFetcher.java │ │ └── utils │ │ └── ItemTreeUtils.java └── resources │ ├── META-INF │ └── aop-ajc.xml │ └── agent.properties └── test ├── java └── com │ └── epam │ └── reportportal │ └── junit5 │ ├── AssumptionsTest.java │ ├── AttributesTest.java │ ├── BasicTest.java │ ├── BeforeAfterAllTest.java │ ├── CallbackReportingTest.java │ ├── CodeReferenceTest.java │ ├── DescriptionTest.java │ ├── DisabledTestTest.java │ ├── DisplayNameTest.java │ ├── ErrorLastLogTest.java │ ├── IssueReportingTest.java │ ├── JunitNestedTestTest.java │ ├── NestedStepTest.java │ ├── ParametersTest.java │ ├── StepReporterTest.java │ ├── SystemAttributesFetcherTest.java │ ├── TestCaseIdTest.java │ ├── TestInitTest.java │ ├── bugs │ ├── BeforeEachFailedDuplication.java │ └── LaunchStartTimeTest.java │ ├── features │ ├── JUnit5Tests.java │ ├── TestFailure.java │ ├── attributes │ │ ├── ClassLevelAttributesTest.java │ │ └── MethodLevelAttributesTest.java │ ├── beforeafterall │ │ ├── AfterAllTest.java │ │ ├── BeforeAfterAllBeforeAfterEachTwoTestsTest.java │ │ ├── BeforeAfterAllFailedTest.java │ │ ├── BeforeAfterAllTest.java │ │ ├── BeforeAfterAllTwoTestsTest.java │ │ ├── BeforeAllAfterAllFailedTest.java │ │ ├── BeforeAllFailedTest.java │ │ ├── BeforeAllTest.java │ │ ├── FailedAfterEachTest.java │ │ ├── FailedConstructorTest.java │ │ └── NonStaticBeforeAfterAllTest.java │ ├── bug │ │ ├── BeforeEachFailedDuplicate.java │ │ └── TestIncorrectStartTime.java │ ├── callback │ │ ├── CallbackFeatureTest.java │ │ └── CallbackLogFeatureTest.java │ ├── coderef │ │ ├── SingleDynamicTest.java │ │ └── SingleTest.java │ ├── configname │ │ ├── ConfigurationMethodsDefaultDisplayNameTest.java │ │ ├── ConfigurationMethodsDisplayNameGeneratorTest.java │ │ ├── ConfigurationMethodsDisplayNameTest.java │ │ └── CustomDisplayNameGenerator.java │ ├── description │ │ ├── DescriptionAnnotatedClassDynamicTest.java │ │ ├── DescriptionAnnotatedClassTest.java │ │ ├── DescriptionAnnotatedMethodAndClassDynamicTest.java │ │ ├── DescriptionAnnotatedMethodAndClassTest.java │ │ ├── DescriptionAnnotatedMethodDynamicTest.java │ │ └── DescriptionAnnotatedMethodTest.java │ ├── disabled │ │ ├── OneDisabledOneEnabledTest.java │ │ ├── OneDisabledTest.java │ │ ├── OneDisabledWithReasonDescriptionTest.java │ │ └── OneDisabledWithReasonTest.java │ ├── displayname │ │ ├── DisplayNameAnnotatedClassDynamicTest.java │ │ ├── DisplayNameAnnotatedClassTest.java │ │ ├── DisplayNameAnnotatedClassWithEmptyValueTest.java │ │ ├── DisplayNameAnnotatedMethodAndClassDynamicTest.java │ │ ├── DisplayNameAnnotatedMethodAndClassTest.java │ │ ├── DisplayNameAnnotatedMethodDynamicTest.java │ │ ├── DisplayNameAnnotatedMethodTest.java │ │ ├── DisplayNameAnnotatedMethodWithEmptyValueTest.java │ │ ├── DisplayNameBothJunitAndRPAnnotatedClassDynamicTest.java │ │ ├── DisplayNameBothJunitAndRPAnnotatedClassTest.java │ │ ├── DisplayNameBothJunitAndRPAnnotatedMethodAndClassDynamicTest.java │ │ ├── DisplayNameBothJunitAndRPAnnotatedMethodAndClassTest.java │ │ ├── DisplayNameBothJunitAndRPAnnotatedMethodDynamicTest.java │ │ └── DisplayNameBothJunitAndRPAnnotatedMethodTest.java │ ├── issue │ │ ├── DynamicIssueTest.java │ │ ├── ParameterizedWithOneIssueTest.java │ │ ├── ParameterizedWithTwoIssueTest.java │ │ ├── SimpleIssueTest.java │ │ ├── SimpleSkippedIssueTest.java │ │ ├── SimpleTwoIssuesTest.java │ │ ├── TwoDynamicIssueTest.java │ │ └── TwoDynamicTwoIssueTest.java │ ├── lasterrorlog │ │ ├── ErrorLastLogFeatureWithAssertionErrorTest.java │ │ ├── ErrorLastLogFeatureWithAssertionPassedTest.java │ │ ├── ErrorLastLogFeatureWithExceptionTest.java │ │ └── ErrorLastLogFeatureWithStepTest.java │ ├── nested │ │ ├── JunitClassNestedTests.java │ │ ├── JunitClassNestedTestsLongDepth.java │ │ ├── JunitDynamicNestedTest.java │ │ ├── NestedStepFeatureFailedTest.java │ │ ├── NestedStepFeaturePassedTest.java │ │ ├── NestedStepMultiLevelTest.java │ │ └── NestedStepWithBeforeEachTest.java │ ├── parameters │ │ ├── CsvParametersTest.java │ │ ├── EnumParametersFailedTest.java │ │ ├── EnumParametersTest.java │ │ ├── NullParameterTest.java │ │ ├── ParameterNamesNotAllNamedTest.java │ │ ├── ParameterNamesTest.java │ │ └── TwoParametersTest.java │ ├── skipped │ │ ├── AfterEachFailedTest.java │ │ ├── AssertJAssumptionFailedTest.java │ │ ├── AssumptionFailedTest.java │ │ ├── BeforeEachAssumptionFailedTest.java │ │ ├── BeforeEachFailedParametrizedTest.java │ │ ├── BeforeEachFailedTest.java │ │ ├── BeforeEachFailedWithAfterEach.java │ │ ├── Junit4AssumptionFailedTest.java │ │ └── Junit4ExtendedAssumptionFailedTest.java │ ├── step │ │ ├── ManualStepReporterFeatureTest.java │ │ └── ManualStepReporterSimpleTest.java │ └── testcaseid │ │ ├── SingleDynamicAnnotatedTest.java │ │ ├── SingleDynamicTest.java │ │ ├── TestCaseIdFromAnnotationTest.java │ │ ├── TestCaseIdFromCodeRefAndParamsTest.java │ │ ├── TestCaseIdFromCodeRefTest.java │ │ ├── TestCaseIdFromParametrizedAnnotationTest.java │ │ └── TestCaseIdTemplateTest.java │ ├── miscellaneous │ ├── DisplayNamesForConfigurationItemsTest.java │ ├── FailedBeforeEachReportsSkippedTestTest.java │ └── FailedBeforeEachSkippedTestOrder.java │ ├── util │ ├── TestUtils.java │ └── Verifications.java │ └── utils │ └── ItemTreeUtilsTest.java └── resources ├── META-INF └── aop-ajc.xml ├── agent.properties ├── files └── css.css ├── logback-test.xml └── pug └── unlucky.jpg /.github/ISSUE_TEMPLATE/bug_report.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Bug report 3 | about: Create a report to help us improve 4 | title: '' 5 | labels: bug 6 | assignees: '' 7 | 8 | --- 9 | 10 | **Describe the bug** 11 | A clear and concise description of what the bug is. 12 | 13 | **Steps to Reproduce** 14 | Steps to reproduce the behavior: 15 | 1. ... 16 | 2. ... 17 | 18 | **Expected behavior** 19 | A clear and concise description of what you expected to happen. 20 | 21 | **Actual behavior** 22 | What actually happened. 23 | 24 | **Dependency versions** 25 | Include version info of the following libraries: client-java, agent-java-junit5 26 | 27 | **Additional context** 28 | Add any other context about the problem here. 29 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/feature_request.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Feature request 3 | about: Suggest an idea for this project 4 | title: '' 5 | labels: enhancement 6 | assignees: '' 7 | 8 | --- 9 | 10 | **Is your feature request related to a problem? Please describe.** 11 | A clear and concise description of what the issue is. Ex. I'm always frustrated when [...] 12 | 13 | **Describe the solution you'd like** 14 | A clear and concise description of what you want to happen. 15 | 16 | **Describe alternatives you've considered** 17 | A clear and concise description of any alternative solutions or features you've considered. 18 | 19 | **Additional context** 20 | Add any other context or screenshots about the feature request here. 21 | -------------------------------------------------------------------------------- /.github/workflows/ci.yml: -------------------------------------------------------------------------------- 1 | # Copyright 2022 EPAM Systems 2 | # Licensed under the Apache License, Version 2.0 (the "License"); 3 | # you may not use this file except in compliance with the License. 4 | # You may obtain a copy of the License at 5 | # 6 | # https://www.apache.org/licenses/LICENSE-2.0 7 | # 8 | # Unless required by applicable law or agreed to in writing, software 9 | # distributed under the License is distributed on an "AS IS" BASIS, 10 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | # See the License for the specific language governing permissions and 12 | # limitations under the License. 13 | 14 | name: CI Build 15 | 16 | on: 17 | push: 18 | branches: 19 | - '*' 20 | - '!master' 21 | - '!v4-hotfix' 22 | paths-ignore: 23 | - README.md 24 | - README_TEMPLATE.md 25 | - CHANGELOG.md 26 | 27 | pull_request: 28 | branches: 29 | - master 30 | - v4-hotfix 31 | 32 | jobs: 33 | build: 34 | runs-on: ubuntu-latest 35 | 36 | steps: 37 | - name: Checkout repository 38 | uses: actions/checkout@v4 39 | 40 | - name: Set up JDK 1.8 41 | uses: actions/setup-java@v4 42 | with: 43 | distribution: 'temurin' 44 | java-version: '8' 45 | 46 | - name: Build with Gradle 47 | run: ./gradlew build 48 | 49 | - name: Codecov upload 50 | uses: codecov/codecov-action@v4 51 | with: 52 | token: ${{ secrets.CODECOV_TOKEN }} 53 | -------------------------------------------------------------------------------- /.github/workflows/promote.yml: -------------------------------------------------------------------------------- 1 | # Copyright 2021 EPAM Systems 2 | # Licensed under the Apache License, Version 2.0 (the "License"); 3 | # you may not use this file except in compliance with the License. 4 | # You may obtain a copy of the License at 5 | # 6 | # http://www.apache.org/licenses/LICENSE-2.0 7 | # 8 | # Unless required by applicable law or agreed to in writing, software 9 | # distributed under the License is distributed on an "AS IS" BASIS, 10 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | # See the License for the specific language governing permissions and 12 | # limitations under the License. 13 | 14 | name: Promote 15 | 16 | on: 17 | workflow_dispatch: 18 | inputs: 19 | version: 20 | description: 'Release version' 21 | required: true 22 | 23 | env: 24 | REPOSITORY_URL: 'https://maven.pkg.github.com' 25 | UPSTREAM_REPOSITORY_URL: 'https://oss.sonatype.org' 26 | PACKAGE_SUFFIXES: '-javadoc.jar,-javadoc.jar.asc,-sources.jar,-sources.jar.asc,.jar,.jar.asc,.pom,.pom.asc' 27 | PACKAGE: 'com.epam.reportportal' 28 | 29 | 30 | jobs: 31 | build: 32 | runs-on: ubuntu-latest 33 | 34 | steps: 35 | - name: Get variables 36 | run: | 37 | echo "ARTIFACT=`echo ${{ github.repository }} | cut -d/ -f2- | awk '{print tolower($0)}'`" >> $GITHUB_ENV 38 | echo "PACKAGE_PATH=`echo ${{ env.PACKAGE }} | sed 's/\./\//g'`" >> $GITHUB_ENV 39 | 40 | - name: Upload package 41 | run: | 42 | IFS=',' read -a files <<< '${{ env.PACKAGE_SUFFIXES }}' 43 | for f in ${files[@]}; do 44 | export URL="${{ env.REPOSITORY_URL }}/${{ github.repository }}/${PACKAGE_PATH}/${ARTIFACT}/${{ github.event.inputs.version }}/${ARTIFACT}-${{ github.event.inputs.version }}${f}" 45 | echo "Downloading artifact: ${URL}" 46 | curl -f -u ${{ github.actor }}:${{ secrets.GITHUB_TOKEN }} -s -O -L "${URL}" 47 | done 48 | files=($(ls)) 49 | echo 'Files downloaded:' 50 | echo "${files[@]}" 51 | 52 | echo 'Bundle generation' 53 | export BUNDLE_FILE="bundle.jar" 54 | jar -cvf ${BUNDLE_FILE} "${files[@]}" 55 | 56 | echo 'Bundle upload' 57 | curl -f -u ${{ secrets.SONATYPE_USER }}:${{ secrets.SONATYPE_PASSWORD }} -L \ 58 | --request POST '${{ env.UPSTREAM_REPOSITORY_URL }}/service/local/staging/bundle_upload' \ 59 | --form "file=@${BUNDLE_FILE}" >response.json 60 | 61 | response_type=`jq type response.json || echo ''` 62 | if [ -z "$response_type" ]; then 63 | echo 'ERROR: Response is not JSON!' 1>&2 64 | cat response.json 1>&2 65 | exit 1 66 | fi 67 | 68 | repo=`jq -r '.repositoryUris[0]' response.json` 69 | if [ -z "$repo" ]; then 70 | echo 'Unable to upload bundle' 1>&2 71 | cat response.json 1>&2 72 | exit 1 73 | fi 74 | 75 | echo "NEXUS_REPOSITORY=${repo}" >> $GITHUB_ENV 76 | 77 | - name: Get repository variables 78 | run: | 79 | echo "NEXUS_REPOSITORY_NAME=`echo ${NEXUS_REPOSITORY} | sed -E 's/(.+)\/([^\/]+)$/\2/'`" >> $GITHUB_ENV 80 | 81 | - name: Promote package 82 | env: 83 | ATTEMPTS: 60 84 | SLEEP_TIME: 10 85 | run: | 86 | verified=false 87 | for i in `seq 0 ${ATTEMPTS}`; do 88 | sleep $SLEEP_TIME 89 | curl -f -s -u ${{ secrets.SONATYPE_USER }}:${{ secrets.SONATYPE_PASSWORD }} -L \ 90 | --header 'Accept: application/json' \ 91 | ${{ env.UPSTREAM_REPOSITORY_URL }}/service/local/staging/repository/${NEXUS_REPOSITORY_NAME} >result.json 92 | 93 | is_closed=`jq -r '.type' result.json` 94 | is_transitioning=`jq -r '.transitioning' result.json` 95 | echo "Current repository status: $is_closed; transitioning: $is_transitioning" 96 | 97 | if [[ "$is_closed" == "closed" && "$is_transitioning" == "false" ]]; then 98 | verified=true 99 | break 100 | fi 101 | done 102 | if $verified; then 103 | echo "A bundle was verified, releasing" 104 | curl -f -u ${{ secrets.SONATYPE_USER }}:${{ secrets.SONATYPE_PASSWORD }} -L \ 105 | --header 'Content-Type: application/json' \ 106 | --data-raw "{\"data\":{\"stagedRepositoryIds\":[\"${NEXUS_REPOSITORY_NAME}\"], \"description\":\"Releasing ${{ github.event.inputs.version }}\"}}" \ 107 | --request POST ${{ env.UPSTREAM_REPOSITORY_URL }}/service/local/staging/bulk/promote 108 | else 109 | echo 'Verification failed, please check the bundle' 1>&2 110 | exit 1 111 | fi 112 | -------------------------------------------------------------------------------- /.github/workflows/release.yml: -------------------------------------------------------------------------------- 1 | # Copyright 2022 EPAM Systems 2 | # Licensed under the Apache License, Version 2.0 (the "License"); 3 | # you may not use this file except in compliance with the License. 4 | # You may obtain a copy of the License at 5 | # 6 | # https://www.apache.org/licenses/LICENSE-2.0 7 | # 8 | # Unless required by applicable law or agreed to in writing, software 9 | # distributed under the License is distributed on an "AS IS" BASIS, 10 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | # See the License for the specific language governing permissions and 12 | # limitations under the License. 13 | 14 | name: Release 15 | 16 | on: 17 | push: 18 | branches: 19 | - master 20 | - v4-hotfix 21 | 22 | paths-ignore: 23 | - '.github/**' 24 | - README.md 25 | - README_TEMPLATE.md 26 | - CHANGELOG.md 27 | 28 | env: 29 | VERSION_FILE: gradle.properties 30 | VERSION_EXTRACT_PATTERN: '(?<=version=).+' 31 | CHANGE_LOG_FILE: CHANGELOG.md 32 | CHANGE_LOG_TMP_FILE: CHANGELOG_updated.md 33 | REPOSITORY_URL: 'https://maven.pkg.github.com/' 34 | README_FILE: README.md 35 | README_TEMPLATE_FILE: README_TEMPLATE.md 36 | README_VERSION_PLACEHOLDER: $LATEST_VERSION 37 | 38 | jobs: 39 | release: 40 | runs-on: ubuntu-latest 41 | steps: 42 | - name: Checkout repository 43 | uses: actions/checkout@v4 44 | 45 | - name: Generate versions 46 | uses: HardNorth/github-version-generate@v1 47 | with: 48 | version-source: file 49 | version-file: ${{ env.VERSION_FILE }} 50 | version-file-extraction-pattern: ${{ env.VERSION_EXTRACT_PATTERN }} 51 | 52 | - name: Set up JDK 1.8 53 | uses: actions/setup-java@v4 54 | with: 55 | distribution: 'temurin' 56 | java-version: '8' 57 | 58 | - name: Setup git credentials 59 | uses: oleksiyrudenko/gha-git-credentials@v2-latest 60 | with: 61 | name: 'reportportal.io' 62 | email: 'support@reportportal.io' 63 | token: ${{ secrets.GITHUB_TOKEN }} 64 | 65 | - name: Release with Gradle 66 | id: release 67 | run: | 68 | ./gradlew release -Prelease.useAutomaticVersion=true -Prelease.releaseVersion=${{ env.RELEASE_VERSION }} \ 69 | -Prelease.newVersion=${{ env.NEXT_VERSION }} -PpublishRepo=${{ env.REPOSITORY_URL }}${{ github.repository }} \ 70 | -PgithubUserName=${{ github.actor }} -PgithubToken=${{ secrets.GITHUB_TOKEN }} \ 71 | -PgpgPassphrase=${{ secrets.GPG_PASSPHRASE }} -PgpgPrivateKey="${{ secrets.GPG_PRIVATE_KEY }}" 72 | 73 | - name: Update README.md 74 | id: readmeUpdate 75 | run: | 76 | sed 's/${{ env.README_VERSION_PLACEHOLDER }}/${{ env.RELEASE_VERSION }}/g' ${{ env.README_TEMPLATE_FILE }} > ${{ env.README_FILE }} 77 | git add ${{ env.README_FILE }} 78 | git commit -m "Readme update" 79 | 80 | - name: Update CHANGELOG.md 81 | id: changelogUpdate 82 | run: | 83 | sed '/\[Unreleased\]/q' ${{ env.CHANGE_LOG_FILE }} >> ${{ env.CHANGE_LOG_TMP_FILE }} 84 | sed -E '1,/#?#\s*\[Unreleased\]/d' ${{ env.CHANGE_LOG_FILE }} | sed -E '/#?#\s*\[/q' | \ 85 | { echo -e '\n## [${{env.RELEASE_VERSION}}]'; sed '$d'; } >> ${{ env.CHANGE_LOG_TMP_FILE }} 86 | grep -E '#?#\s*\[[0-9]' ${{ env.CHANGE_LOG_FILE }} | head -n1 >> ${{ env.CHANGE_LOG_TMP_FILE }} 87 | sed -E '1,/#?#\s*\[[0-9]/d' ${{ env.CHANGE_LOG_FILE }} >> ${{ env.CHANGE_LOG_TMP_FILE }} 88 | rm ${{ env.CHANGE_LOG_FILE }} 89 | mv ${{ env.CHANGE_LOG_TMP_FILE }} ${{ env.CHANGE_LOG_FILE }} 90 | git add ${{ env.CHANGE_LOG_FILE }} 91 | git commit -m "Changelog update" 92 | git push 93 | 94 | - name: Read changelog Entry 95 | id: readChangelogEntry 96 | uses: mindsers/changelog-reader-action@v2 97 | with: 98 | version: ${{ env.RELEASE_VERSION }} 99 | path: ./${{ env.CHANGE_LOG_FILE }} 100 | 101 | - name: Create Release 102 | id: createRelease 103 | uses: ncipollo/release-action@v1 104 | with: 105 | tag: ${{ env.RELEASE_VERSION }} 106 | name: Release ${{ env.RELEASE_VERSION }} 107 | body: ${{ steps.readChangelogEntry.outputs.changes }} 108 | 109 | - name: Checkout develop branch 110 | if: ${{ github.ref }} == 'master' 111 | uses: actions/checkout@v4 112 | with: 113 | ref: 'develop' 114 | fetch-depth: 0 115 | 116 | - name: Merge release branch into develop 117 | id: mergeIntoDevelop 118 | if: ${{ github.ref }} == 'master' 119 | run: | 120 | git merge -m 'Merge master branch into develop after a release' origin/master 121 | git status | (! grep -Fq 'both modified:') || git status | grep -F 'both modified:' \ 122 | | { echo -e 'Unable to merge master into develop, merge conflicts:'; (! grep -Eo '[^ ]+$') } 123 | git push origin develop 124 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.class 2 | 3 | # Mobile Tools for Java (J2ME) 4 | .mtj.tmp/ 5 | 6 | # Package Files # 7 | *.jar 8 | !gradle/wrapper/** 9 | *.war 10 | *.ear 11 | 12 | # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml 13 | hs_err_pid* 14 | 15 | .DS_Store 16 | 17 | .gradle/ 18 | build/ 19 | .idea/ 20 | .classpath 21 | .project 22 | .settings 23 | *.iml 24 | /bin/ 25 | /out 26 | -------------------------------------------------------------------------------- /build.gradle: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2021 EPAM Systems 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 | apply plugin: 'java-library' 17 | 18 | apply from: "${project.scripts_url}/${project.scripts_branch}/build-quality.gradle" 19 | apply from: "${project.scripts_url}/${project.scripts_branch}/release-commons.gradle" 20 | apply from: "${project.scripts_url}/${project.scripts_branch}/signing.gradle" 21 | apply from: "${project.scripts_url}/${project.scripts_branch}/jacoco.gradle" 22 | 23 | project.ext.limits = [ 24 | 'instruction': 70, 25 | 'branch' : 53, 26 | 'line' : 75, 27 | 'complexity' : 60, 28 | 'method' : 65, 29 | 'class' : 87 30 | ] 31 | 32 | sourceCompatibility = JavaVersion.VERSION_1_8 33 | targetCompatibility = JavaVersion.VERSION_1_8 34 | 35 | repositories { 36 | mavenCentral() 37 | } 38 | 39 | dependencies { 40 | api 'com.epam.reportportal:client-java:5.3.14' 41 | 42 | compileOnly "org.junit.jupiter:junit-jupiter-api:${junit_version}" 43 | implementation 'org.slf4j:slf4j-api:2.0.7' 44 | 45 | testImplementation 'com.epam.reportportal:agent-java-test-utils:0.0.12' 46 | testImplementation "org.junit.platform:junit-platform-runner:${junit_runner_version}" // We need runner for JUnit 4 compatibility tests 47 | testImplementation "org.junit.jupiter:junit-jupiter-engine:${junit_version}" // Required for tests to run 48 | testImplementation "org.junit.jupiter:junit-jupiter-params:${junit_version}" 49 | testImplementation 'org.aspectj:aspectjweaver:1.9.19' 50 | testImplementation 'org.hamcrest:hamcrest:2.2' 51 | testImplementation 'org.mockito:mockito-core:3.3.3' 52 | testImplementation 'ch.qos.logback:logback-classic:1.3.15' 53 | testImplementation 'com.epam.reportportal:logger-java-logback:5.2.3' 54 | testImplementation 'org.assertj:assertj-core:3.23.1' 55 | testImplementation 'com.squareup.okhttp3:okhttp:4.12.0' 56 | } 57 | 58 | test { 59 | outputs.upToDateWhen { return false } 60 | useJUnitPlatform() 61 | exclude("com/epam/reportportal/junit5/features/**") 62 | maxParallelForks(5) // it's forks - separate JVMs, should not interfere each other 63 | forkEvery(1) 64 | doFirst { 65 | def weaver = configurations.testRuntimeClasspath.find { it.name.contains("aspectjweaver") } 66 | jvmArgs += "-javaagent:$weaver" 67 | } 68 | environment "AGENT_NO_ANALYTICS", "1" 69 | testLogging { 70 | events "failed" 71 | exceptionFormat "full" 72 | } 73 | } 74 | 75 | wrapper { 76 | gradleVersion = '5.4.1' 77 | } 78 | 79 | processResources { 80 | filesMatching('agent.properties') { 81 | expand(project.properties) 82 | } 83 | } 84 | 85 | release { 86 | git { 87 | requireBranch = 'master' 88 | } 89 | } 90 | 91 | build.dependsOn jacocoTestReport 92 | -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | version=5.4.1-SNAPSHOT 2 | description=JUnit5 integration for ReportPortal 3 | junit_version=5.9.3 4 | # We need runner for JUnit 4 compatibility tests 5 | junit_runner_version=1.9.3 6 | scripts_url=https://raw.githubusercontent.com/reportportal/gradle-scripts 7 | scripts_branch=master 8 | excludeTests= 9 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/reportportal/agent-java-junit5/72bb2f10b35124a6a6c6e25842196ef2566a3682/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.6.4-bin.zip 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | -------------------------------------------------------------------------------- /gradlew: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env sh 2 | 3 | # 4 | # Copyright 2015 the original author or authors. 5 | # 6 | # Licensed under the Apache License, Version 2.0 (the "License"); 7 | # you may not use this file except in compliance with the License. 8 | # You may obtain a copy of the License at 9 | # 10 | # http://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, software 13 | # distributed under the License is distributed on an "AS IS" BASIS, 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | # See the License for the specific language governing permissions and 16 | # limitations under the License. 17 | # 18 | 19 | ############################################################################## 20 | ## 21 | ## Gradle start up script for UN*X 22 | ## 23 | ############################################################################## 24 | 25 | # Attempt to set APP_HOME 26 | # Resolve links: $0 may be a link 27 | PRG="$0" 28 | # Need this for relative symlinks. 29 | while [ -h "$PRG" ] ; do 30 | ls=`ls -ld "$PRG"` 31 | link=`expr "$ls" : '.*-> \(.*\)$'` 32 | if expr "$link" : '/.*' > /dev/null; then 33 | PRG="$link" 34 | else 35 | PRG=`dirname "$PRG"`"/$link" 36 | fi 37 | done 38 | SAVED="`pwd`" 39 | cd "`dirname \"$PRG\"`/" >/dev/null 40 | APP_HOME="`pwd -P`" 41 | cd "$SAVED" >/dev/null 42 | 43 | APP_NAME="Gradle" 44 | APP_BASE_NAME=`basename "$0"` 45 | 46 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 47 | DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' 48 | 49 | # Use the maximum available, or set MAX_FD != -1 to use that value. 50 | MAX_FD="maximum" 51 | 52 | warn () { 53 | echo "$*" 54 | } 55 | 56 | die () { 57 | echo 58 | echo "$*" 59 | echo 60 | exit 1 61 | } 62 | 63 | # OS specific support (must be 'true' or 'false'). 64 | cygwin=false 65 | msys=false 66 | darwin=false 67 | nonstop=false 68 | case "`uname`" in 69 | CYGWIN* ) 70 | cygwin=true 71 | ;; 72 | Darwin* ) 73 | darwin=true 74 | ;; 75 | MINGW* ) 76 | msys=true 77 | ;; 78 | NONSTOP* ) 79 | nonstop=true 80 | ;; 81 | esac 82 | 83 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 84 | 85 | # Determine the Java command to use to start the JVM. 86 | if [ -n "$JAVA_HOME" ] ; then 87 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 88 | # IBM's JDK on AIX uses strange locations for the executables 89 | JAVACMD="$JAVA_HOME/jre/sh/java" 90 | else 91 | JAVACMD="$JAVA_HOME/bin/java" 92 | fi 93 | if [ ! -x "$JAVACMD" ] ; then 94 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 95 | 96 | Please set the JAVA_HOME variable in your environment to match the 97 | location of your Java installation." 98 | fi 99 | else 100 | JAVACMD="java" 101 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 102 | 103 | Please set the JAVA_HOME variable in your environment to match the 104 | location of your Java installation." 105 | fi 106 | 107 | # Increase the maximum file descriptors if we can. 108 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then 109 | MAX_FD_LIMIT=`ulimit -H -n` 110 | if [ $? -eq 0 ] ; then 111 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 112 | MAX_FD="$MAX_FD_LIMIT" 113 | fi 114 | ulimit -n $MAX_FD 115 | if [ $? -ne 0 ] ; then 116 | warn "Could not set maximum file descriptor limit: $MAX_FD" 117 | fi 118 | else 119 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 120 | fi 121 | fi 122 | 123 | # For Darwin, add options to specify how the application appears in the dock 124 | if $darwin; then 125 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 126 | fi 127 | 128 | # For Cygwin, switch paths to Windows format before running java 129 | if $cygwin ; then 130 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 131 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 132 | JAVACMD=`cygpath --unix "$JAVACMD"` 133 | 134 | # We build the pattern for arguments to be converted via cygpath 135 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 136 | SEP="" 137 | for dir in $ROOTDIRSRAW ; do 138 | ROOTDIRS="$ROOTDIRS$SEP$dir" 139 | SEP="|" 140 | done 141 | OURCYGPATTERN="(^($ROOTDIRS))" 142 | # Add a user-defined pattern to the cygpath arguments 143 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 144 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 145 | fi 146 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 147 | i=0 148 | for arg in "$@" ; do 149 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 150 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 151 | 152 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 153 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 154 | else 155 | eval `echo args$i`="\"$arg\"" 156 | fi 157 | i=$((i+1)) 158 | done 159 | case $i in 160 | (0) set -- ;; 161 | (1) set -- "$args0" ;; 162 | (2) set -- "$args0" "$args1" ;; 163 | (3) set -- "$args0" "$args1" "$args2" ;; 164 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;; 165 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 166 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 167 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 168 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 169 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 170 | esac 171 | fi 172 | 173 | # Escape application args 174 | save () { 175 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done 176 | echo " " 177 | } 178 | APP_ARGS=$(save "$@") 179 | 180 | # Collect all arguments for the java command, following the shell quoting and substitution rules 181 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" 182 | 183 | # by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong 184 | if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then 185 | cd "$(dirname "$0")" 186 | fi 187 | 188 | exec "$JAVACMD" "$@" 189 | -------------------------------------------------------------------------------- /gradlew.bat: -------------------------------------------------------------------------------- 1 | @rem 2 | @rem Copyright 2015 the original author or authors. 3 | @rem 4 | @rem Licensed under the Apache License, Version 2.0 (the "License"); 5 | @rem you may not use this file except in compliance with the License. 6 | @rem You may obtain a copy of the License at 7 | @rem 8 | @rem http://www.apache.org/licenses/LICENSE-2.0 9 | @rem 10 | @rem Unless required by applicable law or agreed to in writing, software 11 | @rem distributed under the License is distributed on an "AS IS" BASIS, 12 | @rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | @rem See the License for the specific language governing permissions and 14 | @rem limitations under the License. 15 | @rem 16 | 17 | @if "%DEBUG%" == "" @echo off 18 | @rem ########################################################################## 19 | @rem 20 | @rem Gradle startup script for Windows 21 | @rem 22 | @rem ########################################################################## 23 | 24 | @rem Set local scope for the variables with windows NT shell 25 | if "%OS%"=="Windows_NT" setlocal 26 | 27 | set DIRNAME=%~dp0 28 | if "%DIRNAME%" == "" set DIRNAME=. 29 | set APP_BASE_NAME=%~n0 30 | set APP_HOME=%DIRNAME% 31 | 32 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 33 | set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" 34 | 35 | @rem Find java.exe 36 | if defined JAVA_HOME goto findJavaFromJavaHome 37 | 38 | set JAVA_EXE=java.exe 39 | %JAVA_EXE% -version >NUL 2>&1 40 | if "%ERRORLEVEL%" == "0" goto init 41 | 42 | echo. 43 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 44 | echo. 45 | echo Please set the JAVA_HOME variable in your environment to match the 46 | echo location of your Java installation. 47 | 48 | goto fail 49 | 50 | :findJavaFromJavaHome 51 | set JAVA_HOME=%JAVA_HOME:"=% 52 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 53 | 54 | if exist "%JAVA_EXE%" goto init 55 | 56 | echo. 57 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 58 | echo. 59 | echo Please set the JAVA_HOME variable in your environment to match the 60 | echo location of your Java installation. 61 | 62 | goto fail 63 | 64 | :init 65 | @rem Get command-line arguments, handling Windows variants 66 | 67 | if not "%OS%" == "Windows_NT" goto win9xME_args 68 | 69 | :win9xME_args 70 | @rem Slurp the command line arguments. 71 | set CMD_LINE_ARGS= 72 | set _SKIP=2 73 | 74 | :win9xME_args_slurp 75 | if "x%~1" == "x" goto execute 76 | 77 | set CMD_LINE_ARGS=%* 78 | 79 | :execute 80 | @rem Setup the command line 81 | 82 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 83 | 84 | @rem Execute Gradle 85 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 86 | 87 | :end 88 | @rem End local scope for the variables with windows NT shell 89 | if "%ERRORLEVEL%"=="0" goto mainEnd 90 | 91 | :fail 92 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 93 | rem the _cmd.exe /c_ return code! 94 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 95 | exit /b 1 96 | 97 | :mainEnd 98 | if "%OS%"=="Windows_NT" endlocal 99 | 100 | :omega 101 | -------------------------------------------------------------------------------- /integration_manual_files/note_junit5_properties.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/reportportal/agent-java-junit5/72bb2f10b35124a6a6c6e25842196ef2566a3682/integration_manual_files/note_junit5_properties.png -------------------------------------------------------------------------------- /integration_manual_files/step_add_project.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/reportportal/agent-java-junit5/72bb2f10b35124a6a6c6e25842196ef2566a3682/integration_manual_files/step_add_project.png -------------------------------------------------------------------------------- /integration_manual_files/step_add_project2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/reportportal/agent-java-junit5/72bb2f10b35124a6a6c6e25842196ef2566a3682/integration_manual_files/step_add_project2.png -------------------------------------------------------------------------------- /integration_manual_files/step_add_run_configuration.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/reportportal/agent-java-junit5/72bb2f10b35124a6a6c6e25842196ef2566a3682/integration_manual_files/step_add_run_configuration.png -------------------------------------------------------------------------------- /integration_manual_files/step_add_user.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/reportportal/agent-java-junit5/72bb2f10b35124a6a6c6e25842196ef2566a3682/integration_manual_files/step_add_user.png -------------------------------------------------------------------------------- /integration_manual_files/step_group_and_artifact_id.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/reportportal/agent-java-junit5/72bb2f10b35124a6a6c6e25842196ef2566a3682/integration_manual_files/step_group_and_artifact_id.png -------------------------------------------------------------------------------- /integration_manual_files/step_launches.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/reportportal/agent-java-junit5/72bb2f10b35124a6a6c6e25842196ef2566a3682/integration_manual_files/step_launches.png -------------------------------------------------------------------------------- /integration_manual_files/step_new_maven_project.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/reportportal/agent-java-junit5/72bb2f10b35124a6a6c6e25842196ef2566a3682/integration_manual_files/step_new_maven_project.png -------------------------------------------------------------------------------- /integration_manual_files/step_project_name.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/reportportal/agent-java-junit5/72bb2f10b35124a6a6c6e25842196ef2566a3682/integration_manual_files/step_project_name.png -------------------------------------------------------------------------------- /integration_manual_files/step_project_structure.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/reportportal/agent-java-junit5/72bb2f10b35124a6a6c6e25842196ef2566a3682/integration_manual_files/step_project_structure.png -------------------------------------------------------------------------------- /integration_manual_files/step_test_results.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/reportportal/agent-java-junit5/72bb2f10b35124a6a6c6e25842196ef2566a3682/integration_manual_files/step_test_results.png -------------------------------------------------------------------------------- /integration_manual_files/step_user_profile.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/reportportal/agent-java-junit5/72bb2f10b35124a6a6c6e25842196ef2566a3682/integration_manual_files/step_user_profile.png -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | rootProject.name = 'agent-java-junit5' 2 | -------------------------------------------------------------------------------- /src/main/java/com/epam/reportportal/junit5/ItemType.java: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | * Copyright 2019 EPAM Systems 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package com.epam.reportportal.junit5; 19 | 20 | /** 21 | * JUnit 5's item types set 22 | */ 23 | public enum ItemType { 24 | BEFORE_CLASS, 25 | BEFORE_METHOD, 26 | AFTER_CLASS, 27 | AFTER_METHOD, 28 | TEMPLATE, 29 | SUITE, 30 | STEP 31 | } 32 | -------------------------------------------------------------------------------- /src/main/java/com/epam/reportportal/junit5/SystemAttributesFetcher.java: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | * Copyright 2019 EPAM Systems 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package com.epam.reportportal.junit5; 19 | 20 | import com.epam.reportportal.utils.properties.SystemAttributesExtractor; 21 | import com.epam.ta.reportportal.ws.model.attribute.ItemAttributesRQ; 22 | 23 | import java.util.Set; 24 | 25 | /** 26 | * Util class that retrieves useful info about agent environment and composes it in Report Portal system attributes 27 | */ 28 | public class SystemAttributesFetcher { 29 | 30 | private static final String SKIPPED_ISSUE_KEY = "skippedIssue"; 31 | private static final String AGENT_PROPERTIES = "agent.properties"; 32 | 33 | private static ItemAttributesRQ skippedAnIssue(Boolean fromParams) { 34 | ItemAttributesRQ skippedIssueAttr = new ItemAttributesRQ(); 35 | skippedIssueAttr.setKey(SKIPPED_ISSUE_KEY); 36 | skippedIssueAttr.setValue(fromParams == null ? "true" : fromParams.toString()); 37 | skippedIssueAttr.setSystem(true); 38 | return skippedIssueAttr; 39 | } 40 | 41 | static Set collectSystemAttributes(Boolean skippedAnIssue) { 42 | Set systemAttributes = SystemAttributesExtractor.extract(AGENT_PROPERTIES, SystemAttributesFetcher.class.getClassLoader()); 43 | systemAttributes.add(skippedAnIssue(skippedAnIssue)); 44 | return systemAttributes; 45 | } 46 | 47 | } 48 | -------------------------------------------------------------------------------- /src/main/java/com/epam/reportportal/junit5/utils/ItemTreeUtils.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 EPAM Systems 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 com.epam.reportportal.junit5.utils; 18 | 19 | import com.epam.reportportal.service.tree.TestItemTree; 20 | import io.reactivex.annotations.Nullable; 21 | import org.junit.jupiter.api.TestInfo; 22 | import org.junit.jupiter.api.extension.ExtensionContext; 23 | 24 | /** 25 | * Util class for creating {@link com.epam.reportportal.service.tree.TestItemTree.ItemTreeKey} objects from JUnit5 test-related entities. 26 | * {@link com.epam.reportportal.service.tree.TestItemTree.ItemTreeKey} is required for accessing {@link TestItemTree} entries which 27 | * are used in {@link com.epam.reportportal.service.tree.ItemTreeReporter} that provides possibility to send requests to the Report Portal 28 | * instance right from the end-user code 29 | * 30 | * @author Ivan Budayeu 31 | */ 32 | public class ItemTreeUtils { 33 | 34 | private ItemTreeUtils() { 35 | //static only 36 | } 37 | 38 | public static TestItemTree.ItemTreeKey createItemTreeKey(String name) { 39 | return TestItemTree.ItemTreeKey.of(name); 40 | } 41 | 42 | public static TestItemTree.ItemTreeKey createItemTreeKey(String name, int hash) { 43 | return TestItemTree.ItemTreeKey.of(name, hash); 44 | } 45 | 46 | public static TestItemTree.ItemTreeKey createItemTreeKey(TestInfo testInfo) { 47 | return TestItemTree.ItemTreeKey.of(testInfo.getDisplayName()); 48 | } 49 | 50 | public static TestItemTree.ItemTreeKey createItemTreeKey(TestInfo testInfo, int hash) { 51 | return TestItemTree.ItemTreeKey.of(testInfo.getDisplayName(), hash); 52 | } 53 | 54 | public static TestItemTree.ItemTreeKey createItemTreeKey(ExtensionContext extensionContext) { 55 | return TestItemTree.ItemTreeKey.of(extensionContext.getDisplayName()); 56 | } 57 | 58 | public static TestItemTree.ItemTreeKey createItemTreeKey(ExtensionContext extensionContext, int hash) { 59 | return TestItemTree.ItemTreeKey.of(extensionContext.getDisplayName(), hash); 60 | } 61 | 62 | @Nullable 63 | public static TestItemTree.TestItemLeaf retrieveLeaf(String name, TestItemTree testItemTree) { 64 | return testItemTree.getTestItems().get(createItemTreeKey(name)); 65 | } 66 | 67 | @Nullable 68 | public static TestItemTree.TestItemLeaf retrieveLeaf(TestInfo testInfo, TestItemTree testItemTree) { 69 | return retrieveLeaf(testInfo.getDisplayName(), testItemTree); 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /src/main/resources/META-INF/aop-ajc.xml: -------------------------------------------------------------------------------- 1 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /src/main/resources/agent.properties: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright 2019 EPAM Systems 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 | agent.name=${name} 17 | agent.version=${version} 18 | -------------------------------------------------------------------------------- /src/test/java/com/epam/reportportal/junit5/AssumptionsTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 EPAM Systems 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 com.epam.reportportal.junit5; 18 | 19 | import com.epam.reportportal.junit5.features.skipped.*; 20 | import com.epam.reportportal.junit5.util.TestUtils; 21 | import com.epam.reportportal.listeners.ItemStatus; 22 | import com.epam.reportportal.service.Launch; 23 | import com.epam.reportportal.service.step.StepReporter; 24 | import com.epam.reportportal.util.test.CommonUtils; 25 | import com.epam.ta.reportportal.ws.model.FinishTestItemRQ; 26 | import com.epam.ta.reportportal.ws.model.StartTestItemRQ; 27 | import io.reactivex.Maybe; 28 | import org.junit.jupiter.api.BeforeEach; 29 | import org.junit.jupiter.api.Test; 30 | import org.junit.jupiter.api.TestInstance; 31 | import org.junit.jupiter.api.extension.ExtensionContext; 32 | import org.junit.jupiter.params.ParameterizedTest; 33 | import org.junit.jupiter.params.provider.ValueSource; 34 | import org.mockito.ArgumentCaptor; 35 | import org.mockito.stubbing.Answer; 36 | 37 | import java.util.List; 38 | 39 | import static org.hamcrest.MatcherAssert.assertThat; 40 | import static org.hamcrest.Matchers.equalTo; 41 | import static org.hamcrest.Matchers.nullValue; 42 | import static org.mockito.ArgumentMatchers.any; 43 | import static org.mockito.ArgumentMatchers.notNull; 44 | import static org.mockito.Mockito.*; 45 | 46 | @TestInstance(TestInstance.Lifecycle.PER_CLASS) 47 | public class AssumptionsTest { 48 | 49 | public static class AssumptionsTestExtension extends ReportPortalExtension { 50 | static Launch LAUNCH; 51 | 52 | @Override 53 | protected Launch getLaunch(ExtensionContext context) { 54 | return LAUNCH; 55 | } 56 | } 57 | 58 | @BeforeEach 59 | public void setupMock() { 60 | AssumptionsTestExtension.LAUNCH = mock(Launch.class); 61 | Launch launch = AssumptionsTestExtension.LAUNCH; 62 | when(launch.getStepReporter()).thenReturn(StepReporter.NOOP_STEP_REPORTER); 63 | when(launch.startTestItem(any())).thenAnswer((Answer>) invocation -> CommonUtils.createMaybeUuid()); 64 | when(launch.startTestItem( 65 | any(), 66 | any() 67 | )).thenAnswer((Answer>) invocation -> CommonUtils.createMaybeUuid()); 68 | } 69 | 70 | @ParameterizedTest 71 | @ValueSource(classes = {AssumptionFailedTest.class, Junit4AssumptionFailedTest.class, 72 | AssertJAssumptionFailedTest.class, Junit4ExtendedAssumptionFailedTest.class}) 73 | public void verify_assumption_failure_marks_test_as_skipped(Class testClass) { 74 | TestUtils.runClasses(testClass); 75 | 76 | Launch launch = AssumptionsTestExtension.LAUNCH; 77 | 78 | verify(launch).startTestItem(any(StartTestItemRQ.class)); // Start parent Suite 79 | verify(launch, times(1)).startTestItem(notNull(), any(StartTestItemRQ.class)); // Start a test 80 | 81 | ArgumentCaptor finishCaptor = ArgumentCaptor.forClass(FinishTestItemRQ.class); 82 | verify(launch, times(2)).finishTestItem(any(), finishCaptor.capture()); 83 | List finishItems = finishCaptor.getAllValues(); 84 | assertThat(finishItems.get(0).getStatus(), equalTo(ItemStatus.SKIPPED.name())); 85 | assertThat(finishItems.get(1).getStatus(), nullValue()); 86 | } 87 | 88 | @Test 89 | public void verify_before_each_assumption_failure_marks_test_as_skipped() { 90 | TestUtils.runClasses(BeforeEachAssumptionFailedTest.class); 91 | 92 | Launch launch = AssumptionsTestExtension.LAUNCH; 93 | 94 | verify(launch).startTestItem(any(StartTestItemRQ.class)); // Start parent Suite 95 | verify(launch, times(2)).startTestItem(notNull(), any(StartTestItemRQ.class)); // Start a test 96 | 97 | ArgumentCaptor finishCaptor = ArgumentCaptor.forClass(FinishTestItemRQ.class); 98 | verify(launch, times(3)).finishTestItem(any(), finishCaptor.capture()); 99 | List finishItems = finishCaptor.getAllValues(); 100 | assertThat(finishItems.get(0).getStatus(), equalTo(ItemStatus.SKIPPED.name())); 101 | assertThat(finishItems.get(1).getStatus(), equalTo(ItemStatus.SKIPPED.name())); 102 | assertThat(finishItems.get(2).getStatus(), nullValue()); 103 | } 104 | } 105 | -------------------------------------------------------------------------------- /src/test/java/com/epam/reportportal/junit5/AttributesTest.java: -------------------------------------------------------------------------------- 1 | package com.epam.reportportal.junit5; 2 | 3 | import com.epam.reportportal.junit5.features.attributes.ClassLevelAttributesTest; 4 | import com.epam.reportportal.junit5.features.attributes.MethodLevelAttributesTest; 5 | import com.epam.reportportal.junit5.util.TestUtils; 6 | import com.epam.reportportal.service.Launch; 7 | import com.epam.reportportal.util.test.CommonUtils; 8 | import com.epam.ta.reportportal.ws.model.OperationCompletionRS; 9 | import com.epam.ta.reportportal.ws.model.StartTestItemRQ; 10 | import com.epam.ta.reportportal.ws.model.attribute.ItemAttributesRQ; 11 | import io.reactivex.Maybe; 12 | import org.junit.jupiter.api.BeforeEach; 13 | import org.junit.jupiter.api.Test; 14 | import org.junit.jupiter.api.TestInstance; 15 | import org.junit.jupiter.api.extension.ExtensionContext; 16 | import org.mockito.ArgumentCaptor; 17 | import org.mockito.stubbing.Answer; 18 | 19 | import static com.epam.reportportal.junit5.util.TestUtils.extractRequest; 20 | import static org.hamcrest.MatcherAssert.assertThat; 21 | import static org.hamcrest.Matchers.*; 22 | import static org.mockito.ArgumentMatchers.any; 23 | import static org.mockito.Mockito.*; 24 | 25 | @TestInstance(TestInstance.Lifecycle.PER_CLASS) 26 | public class AttributesTest { 27 | 28 | public static class AttributesTestExtension extends ReportPortalExtension { 29 | static Launch LAUNCH; 30 | 31 | @Override 32 | protected Launch getLaunch(ExtensionContext context) { 33 | return LAUNCH; 34 | } 35 | } 36 | 37 | @BeforeEach 38 | public void setupMock() { 39 | AttributesTestExtension.LAUNCH = mock(Launch.class); 40 | when(AttributesTestExtension.LAUNCH.startTestItem(any())).thenAnswer((Answer>) invocation -> CommonUtils.createMaybeUuid()); 41 | when(AttributesTestExtension.LAUNCH.startTestItem(any(), 42 | any() 43 | )).thenAnswer((Answer>) invocation -> CommonUtils.createMaybeUuid()); 44 | when(AttributesTestExtension.LAUNCH.finishTestItem( 45 | any(), 46 | any() 47 | )).thenAnswer(invocation -> Maybe.just(new OperationCompletionRS())); 48 | } 49 | 50 | @Test 51 | public void verify_class_level_attributes() { 52 | TestUtils.runClasses(ClassLevelAttributesTest.class); 53 | 54 | Launch launch = AttributesTestExtension.LAUNCH; 55 | 56 | ArgumentCaptor captor = ArgumentCaptor.forClass(StartTestItemRQ.class); 57 | verify(launch).startTestItem(captor.capture()); // Start test 58 | verify(launch).startTestItem(any(), captor.capture()); // Start step 59 | 60 | StartTestItemRQ testRequest = extractRequest(captor, "suite"); 61 | 62 | assertThat(testRequest.getAttributes(), hasSize(1)); 63 | ItemAttributesRQ attribute = testRequest.getAttributes().iterator().next(); 64 | assertThat(attribute.getKey(), equalTo(ClassLevelAttributesTest.KEY)); 65 | assertThat(attribute.getValue(), equalTo(ClassLevelAttributesTest.VALUE)); 66 | 67 | StartTestItemRQ stepRequest = extractRequest(captor, "step"); 68 | assertThat(stepRequest.getAttributes(), anyOf(nullValue(), emptyIterable())); 69 | } 70 | 71 | @Test 72 | public void verify_method_level_attributes() { 73 | TestUtils.runClasses(MethodLevelAttributesTest.class); 74 | 75 | Launch launch = AttributesTestExtension.LAUNCH; 76 | 77 | ArgumentCaptor captor = ArgumentCaptor.forClass(StartTestItemRQ.class); 78 | verify(launch).startTestItem(captor.capture()); // Start test 79 | verify(launch).startTestItem(any(), captor.capture()); // Start step 80 | 81 | StartTestItemRQ testRequest = extractRequest(captor, "suite"); 82 | assertThat(testRequest.getAttributes(), anyOf(nullValue(), emptyIterable())); 83 | 84 | StartTestItemRQ stepRequest = extractRequest(captor, "step"); 85 | assertThat(stepRequest.getAttributes(), hasSize(1)); 86 | ItemAttributesRQ attribute = stepRequest.getAttributes().iterator().next(); 87 | assertThat(attribute.getKey(), equalTo("myKey")); 88 | assertThat(attribute.getValue(), equalTo("myValue")); 89 | } 90 | } 91 | -------------------------------------------------------------------------------- /src/test/java/com/epam/reportportal/junit5/BasicTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 EPAM Systems 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 com.epam.reportportal.junit5; 18 | 19 | import com.epam.reportportal.junit5.features.TestFailure; 20 | import com.epam.reportportal.junit5.util.TestUtils; 21 | import com.epam.reportportal.listeners.ItemStatus; 22 | import com.epam.reportportal.service.Launch; 23 | import com.epam.reportportal.service.ReportPortal; 24 | import com.epam.reportportal.service.ReportPortalClient; 25 | import com.epam.ta.reportportal.ws.model.FinishTestItemRQ; 26 | import com.epam.ta.reportportal.ws.model.StartTestItemRQ; 27 | import com.epam.ta.reportportal.ws.model.launch.StartLaunchRQ; 28 | import org.hamcrest.Matchers; 29 | import org.junit.jupiter.api.Test; 30 | import org.junit.jupiter.api.TestInstance; 31 | import org.junit.jupiter.api.extension.ExtensionContext; 32 | import org.junit.platform.engine.TestExecutionResult; 33 | import org.junit.platform.launcher.TestExecutionListener; 34 | import org.junit.platform.launcher.TestIdentifier; 35 | import org.mockito.ArgumentCaptor; 36 | 37 | import java.util.Deque; 38 | import java.util.List; 39 | import java.util.concurrent.ConcurrentLinkedDeque; 40 | 41 | import static com.epam.reportportal.util.test.CommonUtils.namedId; 42 | import static org.hamcrest.MatcherAssert.assertThat; 43 | import static org.hamcrest.Matchers.*; 44 | import static org.mockito.Mockito.*; 45 | 46 | @TestInstance(TestInstance.Lifecycle.PER_CLASS) 47 | public class BasicTest { 48 | 49 | public static class BasicTestExtension extends ReportPortalExtension { 50 | static final String testClassUuid = namedId("class"); 51 | static final String testMethodUuid = namedId("test"); 52 | 53 | static final ThreadLocal client = new ThreadLocal<>(); 54 | static final ThreadLocal launch = new ThreadLocal<>(); 55 | 56 | public static void init() { 57 | client.set(mock(ReportPortalClient.class)); 58 | TestUtils.mockLaunch(client.get(), "launchUuid", testClassUuid, testMethodUuid); 59 | TestUtils.mockLogging(client.get()); 60 | ReportPortal reportPortal = ReportPortal.create(client.get(), TestUtils.standardParameters()); 61 | launch.set(reportPortal.newLaunch(TestUtils.launchRQ(reportPortal.getParameters()))); 62 | } 63 | 64 | @Override 65 | protected Launch getLaunch(ExtensionContext context) { 66 | return launch.get(); 67 | } 68 | } 69 | 70 | public static class Listener implements TestExecutionListener { 71 | public Deque results = new ConcurrentLinkedDeque<>(); 72 | 73 | @Override 74 | public void executionFinished(TestIdentifier testIdentifier, TestExecutionResult testExecutionResult) { 75 | if (testIdentifier.isTest()) { 76 | results.add(testExecutionResult); 77 | } 78 | } 79 | } 80 | 81 | @Test 82 | public void verify_test_failure_report() { 83 | BasicTestExtension.init(); 84 | Listener listener = new Listener(); 85 | TestUtils.runClasses(listener, TestFailure.class); 86 | 87 | ReportPortalClient client = BasicTestExtension.client.get(); 88 | ArgumentCaptor launchCaptor = ArgumentCaptor.forClass(StartLaunchRQ.class); 89 | verify(client, timeout(1000)).startLaunch(launchCaptor.capture()); 90 | 91 | ArgumentCaptor suiteCaptor = ArgumentCaptor.forClass(StartTestItemRQ.class); 92 | verify(client, timeout(1000)).startTestItem(suiteCaptor.capture()); 93 | 94 | ArgumentCaptor testCaptor = ArgumentCaptor.forClass(StartTestItemRQ.class); 95 | verify(client, timeout(1000)).startTestItem(anyString(), testCaptor.capture()); 96 | 97 | ArgumentCaptor testFinishCaptor = ArgumentCaptor.forClass(FinishTestItemRQ.class); 98 | verify(client, timeout(1000).times(2)).finishTestItem(anyString(), testFinishCaptor.capture()); 99 | 100 | assertThat(listener.results.remove().getStatus(), sameInstance(TestExecutionResult.Status.FAILED)); 101 | 102 | StartLaunchRQ launchStart = launchCaptor.getValue(); 103 | assertThat(launchStart.getName(), allOf(notNullValue(), Matchers.startsWith("My-test-launch-"))); 104 | 105 | List itemFinish = testFinishCaptor.getAllValues(); 106 | assertThat(itemFinish.get(0).getStatus(), equalTo(ItemStatus.FAILED.name())); 107 | assertThat(itemFinish.get(1).getStatus(), nullValue()); 108 | } 109 | } 110 | -------------------------------------------------------------------------------- /src/test/java/com/epam/reportportal/junit5/CodeReferenceTest.java: -------------------------------------------------------------------------------- 1 | package com.epam.reportportal.junit5; 2 | 3 | import com.epam.reportportal.junit5.features.coderef.SingleDynamicTest; 4 | import com.epam.reportportal.junit5.features.coderef.SingleTest; 5 | import com.epam.reportportal.junit5.util.TestUtils; 6 | import com.epam.reportportal.service.Launch; 7 | import com.epam.reportportal.util.test.CommonUtils; 8 | import com.epam.ta.reportportal.ws.model.StartTestItemRQ; 9 | import io.reactivex.Maybe; 10 | import org.junit.jupiter.api.BeforeEach; 11 | import org.junit.jupiter.api.Test; 12 | import org.junit.jupiter.api.TestInstance; 13 | import org.junit.jupiter.api.extension.ExtensionContext; 14 | import org.mockito.ArgumentCaptor; 15 | import org.mockito.stubbing.Answer; 16 | 17 | import java.util.List; 18 | 19 | import static org.hamcrest.MatcherAssert.assertThat; 20 | import static org.hamcrest.Matchers.equalTo; 21 | import static org.mockito.ArgumentMatchers.any; 22 | import static org.mockito.Mockito.*; 23 | 24 | @TestInstance(TestInstance.Lifecycle.PER_CLASS) 25 | public class CodeReferenceTest { 26 | 27 | public static class CodeReferenceTestExtension extends ReportPortalExtension { 28 | static Launch LAUNCH; 29 | 30 | @Override 31 | protected Launch getLaunch(ExtensionContext context) { 32 | return LAUNCH; 33 | } 34 | } 35 | 36 | @BeforeEach 37 | public void setupMock() { 38 | CodeReferenceTestExtension.LAUNCH = mock(Launch.class); 39 | when(CodeReferenceTestExtension.LAUNCH.startTestItem(any())).thenAnswer((Answer>) invocation -> CommonUtils.createMaybeUuid()); 40 | when(CodeReferenceTestExtension.LAUNCH.startTestItem(any(), 41 | any() 42 | )).thenAnswer((Answer>) invocation -> CommonUtils.createMaybeUuid()); 43 | } 44 | 45 | @Test 46 | public void verify_static_test_code_reference_generation() { 47 | TestUtils.runClasses(SingleTest.class); 48 | 49 | Launch launch = CodeReferenceTestExtension.LAUNCH; 50 | 51 | ArgumentCaptor suiteCaptor = ArgumentCaptor.forClass(StartTestItemRQ.class); 52 | verify(launch, times(1)).startTestItem(suiteCaptor.capture()); // Start parent Suite 53 | 54 | ArgumentCaptor testCaptor = ArgumentCaptor.forClass(StartTestItemRQ.class); 55 | verify(launch, times(1)).startTestItem(notNull(), testCaptor.capture()); // Start a test 56 | 57 | String className = SingleTest.class.getCanonicalName(); 58 | StartTestItemRQ suiteRq = suiteCaptor.getValue(); 59 | assertThat(suiteRq.getCodeRef(), equalTo(className)); 60 | 61 | StartTestItemRQ testRq = testCaptor.getValue(); 62 | assertThat(testRq.getCodeRef(), equalTo(className + ".singleTest")); 63 | } 64 | 65 | @Test 66 | public void verify_dynamic_test_code_reference_generation() { 67 | TestUtils.runClasses(SingleDynamicTest.class); 68 | 69 | Launch launch = CodeReferenceTestExtension.LAUNCH; 70 | 71 | ArgumentCaptor suiteCaptor = ArgumentCaptor.forClass(StartTestItemRQ.class); 72 | verify(launch, times(1)).startTestItem(suiteCaptor.capture()); // Start parent Suite 73 | 74 | ArgumentCaptor testCaptor = ArgumentCaptor.forClass(StartTestItemRQ.class); 75 | verify(launch, times(2)).startTestItem(notNull(), testCaptor.capture()); // Start a test class and a test 76 | 77 | String className = SingleDynamicTest.class.getCanonicalName(); 78 | StartTestItemRQ suiteRq = suiteCaptor.getValue(); 79 | assertThat(suiteRq.getCodeRef(), equalTo(className)); 80 | 81 | List rqValues = testCaptor.getAllValues(); 82 | String testName = className + ".testForTestFactory"; 83 | assertThat(rqValues.get(0).getCodeRef(), equalTo(testName)); 84 | assertThat(rqValues.get(1).getCodeRef(), equalTo(testName + "$" + SingleDynamicTest.TEST_CASE_DISPLAY_NAME)); 85 | } 86 | 87 | } 88 | -------------------------------------------------------------------------------- /src/test/java/com/epam/reportportal/junit5/DescriptionTest.java: -------------------------------------------------------------------------------- 1 | package com.epam.reportportal.junit5; 2 | 3 | import com.epam.reportportal.junit5.features.description.*; 4 | import com.epam.reportportal.junit5.util.TestUtils; 5 | import com.epam.reportportal.service.Launch; 6 | import com.epam.reportportal.util.test.CommonUtils; 7 | import com.epam.ta.reportportal.ws.model.StartTestItemRQ; 8 | import io.reactivex.Maybe; 9 | import org.junit.jupiter.api.BeforeEach; 10 | import org.junit.jupiter.api.Test; 11 | import org.junit.jupiter.api.extension.ExtensionContext; 12 | import org.mockito.ArgumentCaptor; 13 | import org.mockito.stubbing.Answer; 14 | 15 | import java.util.List; 16 | import java.util.stream.Collectors; 17 | 18 | import static org.hamcrest.MatcherAssert.assertThat; 19 | import static org.hamcrest.Matchers.equalTo; 20 | import static org.hamcrest.Matchers.hasItem; 21 | import static org.mockito.ArgumentMatchers.any; 22 | import static org.mockito.Mockito.*; 23 | 24 | /** 25 | * @author Oleksandr Fomenko 26 | */ 27 | public class DescriptionTest { 28 | public static class TestExtension extends ReportPortalExtension { 29 | static Launch LAUNCH; 30 | 31 | @Override 32 | protected Launch getLaunch(ExtensionContext context) { 33 | return LAUNCH; 34 | } 35 | } 36 | 37 | @BeforeEach 38 | public void setupMock() { 39 | TestExtension.LAUNCH = mock(Launch.class); 40 | when(TestExtension.LAUNCH.startTestItem(any())).thenAnswer((Answer>) invocation -> CommonUtils.createMaybeUuid()); 41 | when(TestExtension.LAUNCH.startTestItem(any(), 42 | any() 43 | )).thenAnswer((Answer>) invocation -> CommonUtils.createMaybeUuid()); 44 | } 45 | 46 | @Test 47 | void descriptionFromMethodAnnotationTest() { 48 | TestUtils.runClasses(DescriptionAnnotatedMethodTest.class); 49 | 50 | Launch launch = TestExtension.LAUNCH; 51 | 52 | verify(launch, times(1)).startTestItem(any()); // Start parent Suite 53 | 54 | ArgumentCaptor captor = ArgumentCaptor.forClass(StartTestItemRQ.class); 55 | verify(launch, times(1)).startTestItem(notNull(), captor.capture()); // Start a test 56 | 57 | StartTestItemRQ request = captor.getValue(); 58 | assertThat(request.getDescription(), equalTo(DescriptionAnnotatedMethodTest.TEST_DESCRIPTION_METHOD)); 59 | } 60 | 61 | @Test 62 | void descriptionFromClassAnnotationTest() { 63 | TestUtils.runClasses(DescriptionAnnotatedClassTest.class); 64 | 65 | Launch launch = TestExtension.LAUNCH; 66 | 67 | verify(launch, times(1)).startTestItem(any()); // Start parent Suite 68 | 69 | ArgumentCaptor captor = ArgumentCaptor.forClass(StartTestItemRQ.class); 70 | verify(launch, times(1)).startTestItem(notNull(), captor.capture()); // Start a test 71 | 72 | StartTestItemRQ request = captor.getValue(); 73 | assertThat(request.getDescription(), equalTo(DescriptionAnnotatedClassTest.TEST_DESCRIPTION_CLASS)); 74 | } 75 | 76 | @Test 77 | void descriptionFromBothMethodAndClassAnnotationTest() { 78 | TestUtils.runClasses(DescriptionAnnotatedMethodAndClassTest.class); 79 | 80 | Launch launch = TestExtension.LAUNCH; 81 | 82 | verify(launch, times(1)).startTestItem(any()); // Start parent Suite 83 | 84 | ArgumentCaptor captor = ArgumentCaptor.forClass(StartTestItemRQ.class); 85 | verify(launch, times(1)).startTestItem(notNull(), captor.capture()); // Start a test 86 | 87 | StartTestItemRQ request = captor.getValue(); 88 | //from both annotations the expected one should be taken from the method 89 | assertThat(request.getDescription(), equalTo(DescriptionAnnotatedMethodTest.TEST_DESCRIPTION_METHOD)); 90 | } 91 | 92 | @Test 93 | void descriptionFromMethodAnnotationDynamicTest() { 94 | TestUtils.runClasses(DescriptionAnnotatedMethodDynamicTest.class); 95 | 96 | Launch launch = TestExtension.LAUNCH; 97 | verify(launch, times(1)).startTestItem(any()); // Start parent Suite 98 | 99 | ArgumentCaptor captor = ArgumentCaptor.forClass(StartTestItemRQ.class); 100 | verify(launch, times(2)).startTestItem(notNull(), captor.capture()); // Start a test 101 | 102 | List testStepsDescription = captor.getAllValues() 103 | .stream() 104 | .filter(e -> e.getType().equals(ItemType.STEP.name())) 105 | .map(StartTestItemRQ::getDescription) 106 | .collect(Collectors.toList()); 107 | 108 | assertThat(testStepsDescription, hasItem(DescriptionAnnotatedMethodDynamicTest.TEST_DESCRIPTION_DYNAMIC_METHOD)); 109 | } 110 | 111 | @Test 112 | void descriptionFromClassAnnotationDynamicTest() { 113 | TestUtils.runClasses(DescriptionAnnotatedClassDynamicTest.class); 114 | 115 | Launch launch = TestExtension.LAUNCH; 116 | verify(launch, times(1)).startTestItem(any()); // Start parent Suite 117 | 118 | ArgumentCaptor captor = ArgumentCaptor.forClass(StartTestItemRQ.class); 119 | verify(launch, times(2)).startTestItem(notNull(), captor.capture()); // Start a test 120 | 121 | List testStepsDescription = captor.getAllValues() 122 | .stream() 123 | .filter(e -> e.getType().equals(ItemType.STEP.name())) 124 | .map(StartTestItemRQ::getDescription) 125 | .collect(Collectors.toList()); 126 | 127 | assertThat(testStepsDescription, hasItem(DescriptionAnnotatedClassDynamicTest.TEST_DESCRIPTION_DYNAMIC_CLASS)); 128 | } 129 | 130 | @Test 131 | void descriptionFromBothMethodAndClassAnnotationDynamicTest() { 132 | TestUtils.runClasses(DescriptionAnnotatedMethodAndClassDynamicTest.class); 133 | 134 | Launch launch = TestExtension.LAUNCH; 135 | verify(launch, times(1)).startTestItem(any()); // Start parent Suite 136 | 137 | ArgumentCaptor captor = ArgumentCaptor.forClass(StartTestItemRQ.class); 138 | verify(launch, times(2)).startTestItem(notNull(), captor.capture()); // Start a test 139 | 140 | List testStepsDescription = captor.getAllValues() 141 | .stream() 142 | .filter(e -> e.getType().equals(ItemType.STEP.name())) 143 | .map(StartTestItemRQ::getDescription) 144 | .collect(Collectors.toList()); 145 | //from both annotations the expected one should be taken from the method 146 | assertThat(testStepsDescription, hasItem(DescriptionAnnotatedMethodDynamicTest.TEST_DESCRIPTION_DYNAMIC_METHOD)); 147 | } 148 | } 149 | -------------------------------------------------------------------------------- /src/test/java/com/epam/reportportal/junit5/DisabledTestTest.java: -------------------------------------------------------------------------------- 1 | package com.epam.reportportal.junit5; 2 | 3 | import com.epam.reportportal.junit5.features.disabled.OneDisabledOneEnabledTest; 4 | import com.epam.reportportal.junit5.features.disabled.OneDisabledTest; 5 | import com.epam.reportportal.junit5.features.disabled.OneDisabledWithReasonTest; 6 | import com.epam.reportportal.junit5.features.disabled.OneDisabledWithReasonDescriptionTest; 7 | import com.epam.reportportal.junit5.util.TestUtils; 8 | import com.epam.reportportal.listeners.ItemStatus; 9 | import com.epam.reportportal.service.Launch; 10 | import com.epam.reportportal.service.step.StepReporter; 11 | import com.epam.reportportal.util.test.CommonUtils; 12 | import com.epam.reportportal.utils.formatting.MarkdownUtils; 13 | import com.epam.ta.reportportal.ws.model.FinishTestItemRQ; 14 | import com.epam.ta.reportportal.ws.model.StartTestItemRQ; 15 | import io.reactivex.Maybe; 16 | import org.junit.jupiter.api.*; 17 | import org.junit.jupiter.api.extension.ExtensionContext; 18 | import org.mockito.ArgumentCaptor; 19 | import org.mockito.stubbing.Answer; 20 | 21 | import java.util.List; 22 | 23 | import static org.hamcrest.MatcherAssert.assertThat; 24 | import static org.hamcrest.Matchers.equalTo; 25 | import static org.hamcrest.Matchers.hasSize; 26 | import static org.mockito.ArgumentMatchers.any; 27 | import static org.mockito.Mockito.*; 28 | 29 | @TestInstance(TestInstance.Lifecycle.PER_CLASS) 30 | public class DisabledTestTest { 31 | 32 | public static class DisabledTestExtension extends ReportPortalExtension { 33 | static Launch LAUNCH; 34 | 35 | @Override 36 | protected Launch getLaunch(ExtensionContext context) { 37 | return LAUNCH; 38 | } 39 | } 40 | 41 | @BeforeAll 42 | public void setupProperty() { 43 | System.setProperty("reportDisabledTests", Boolean.TRUE.toString()); 44 | } 45 | 46 | @BeforeEach 47 | public void setupMock() { 48 | DisabledTestExtension.LAUNCH = mock(Launch.class); 49 | when(DisabledTestExtension.LAUNCH.getStepReporter()).thenReturn(StepReporter.NOOP_STEP_REPORTER); 50 | when(DisabledTestExtension.LAUNCH.startTestItem(any())).thenAnswer((Answer>) invocation -> CommonUtils.createMaybeUuid()); 51 | when(DisabledTestExtension.LAUNCH.startTestItem(any(), 52 | any() 53 | )).thenAnswer((Answer>) invocation -> CommonUtils.createMaybeUuid()); 54 | 55 | } 56 | 57 | @Test 58 | public void verify_a_disabled_test_reported_as_skipped() { 59 | TestUtils.runClasses(OneDisabledTest.class); 60 | 61 | Launch launch = DisabledTestExtension.LAUNCH; 62 | 63 | verify(launch, times(1)).startTestItem(any()); // Start parent Suite 64 | ArgumentCaptor captorStart = ArgumentCaptor.forClass(StartTestItemRQ.class); 65 | verify(launch, times(1)).startTestItem(notNull(), captorStart.capture()); // Start a test 66 | 67 | ArgumentCaptor captorFinish = ArgumentCaptor.forClass(FinishTestItemRQ.class); 68 | verify(launch, times(2)).finishTestItem(notNull(), captorFinish.capture()); // finish a test and a suite 69 | 70 | List steps = captorStart.getAllValues(); 71 | 72 | assertThat("There is only one StartTestItem request", steps, hasSize(1)); 73 | assertThat("StartTestItem request has proper Description field", 74 | steps.get(0).getDescription(), 75 | equalTo("void " + OneDisabledTest.class.getCanonicalName() + ".disabledTest() is @Disabled") 76 | ); 77 | 78 | List finishes = captorFinish.getAllValues(); 79 | assertThat("There are only finish test and finish suite requests", finishes, hasSize(2)); 80 | 81 | FinishTestItemRQ finishStep = finishes.get(0); 82 | assertThat("Finish item has skipped status", finishStep.getStatus(), equalTo(ItemStatus.SKIPPED.name())); 83 | } 84 | 85 | @Test 86 | public void verify_a_disabled_test_reason_reported() { 87 | TestUtils.runClasses(OneDisabledWithReasonTest.class); 88 | 89 | Launch launch = DisabledTestExtension.LAUNCH; 90 | 91 | verify(launch, times(1)).startTestItem(any()); // Start parent Suite 92 | ArgumentCaptor captorStart = ArgumentCaptor.forClass(StartTestItemRQ.class); 93 | verify(launch, times(1)).startTestItem(notNull(), captorStart.capture()); // Start a test 94 | 95 | List steps = captorStart.getAllValues(); 96 | assertThat("StartTestItem request has proper Description field", 97 | steps.get(0).getDescription(), 98 | equalTo(OneDisabledWithReasonTest.REASON) 99 | ); 100 | } 101 | 102 | @Test 103 | public void verify_a_disabled_test_does_not_affect_enabled_in_the_same_class() { 104 | TestUtils.runClasses(OneDisabledOneEnabledTest.class); 105 | 106 | Launch launch = DisabledTestExtension.LAUNCH; 107 | 108 | verify(launch, times(1)).startTestItem(any()); // Start parent Suite 109 | ArgumentCaptor captorStart = ArgumentCaptor.forClass(StartTestItemRQ.class); 110 | verify(launch, times(2)).startTestItem(notNull(), captorStart.capture()); // Start a disabled test and an enabled one 111 | 112 | ArgumentCaptor captorFinish = ArgumentCaptor.forClass(FinishTestItemRQ.class); 113 | verify(launch, times(3)).finishTestItem(notNull(), captorFinish.capture()); // finish two tests and a suite 114 | 115 | List steps = captorStart.getAllValues(); 116 | assertThat("There two StartTestItem request", steps, hasSize(2)); 117 | assertThat("StartTestItem request for enabled test has proper Name field", 118 | steps.get(1).getName(), 119 | equalTo(OneDisabledOneEnabledTest.DISPLAY_NAME) 120 | ); 121 | 122 | List finishes = captorFinish.getAllValues(); 123 | assertThat("There are two finish tests and a finish suite requests", finishes, hasSize(3)); 124 | 125 | FinishTestItemRQ finishStep = finishes.get(0); 126 | assertThat("Disabled test has skipped status", finishStep.getStatus(), equalTo(ItemStatus.SKIPPED.name())); 127 | 128 | finishStep = finishes.get(1); 129 | assertThat("Enabled has passed status", finishStep.getStatus(), equalTo(ItemStatus.PASSED.name())); 130 | } 131 | 132 | @Test 133 | public void verify_a_disabled_test_reason_and_description_reported() { 134 | TestUtils.runClasses(OneDisabledWithReasonDescriptionTest.class); 135 | 136 | Launch launch = DisabledTestExtension.LAUNCH; 137 | 138 | verify(launch, times(1)).startTestItem(any()); // Start parent Suite 139 | ArgumentCaptor captorStart = ArgumentCaptor.forClass(StartTestItemRQ.class); 140 | verify(launch, times(1)).startTestItem(notNull(), captorStart.capture()); // Start a test 141 | 142 | List steps = captorStart.getAllValues(); 143 | assertThat("StartTestItem request has proper Description field", 144 | steps.get(0).getDescription(), 145 | equalTo(MarkdownUtils.asTwoParts(OneDisabledWithReasonDescriptionTest.REASON, OneDisabledWithReasonDescriptionTest.TEST_DESCRIPTION_METHOD)) 146 | ); 147 | } 148 | 149 | @AfterAll 150 | public void cleanProperty() { 151 | System.clearProperty("reportDisabledTests"); 152 | } 153 | } 154 | -------------------------------------------------------------------------------- /src/test/java/com/epam/reportportal/junit5/StepReporterTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 EPAM Systems 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 com.epam.reportportal.junit5; 18 | 19 | import com.epam.reportportal.junit5.features.step.ManualStepReporterFeatureTest; 20 | import com.epam.reportportal.junit5.features.step.ManualStepReporterSimpleTest; 21 | import com.epam.reportportal.junit5.util.TestUtils; 22 | import com.epam.reportportal.listeners.ItemStatus; 23 | import com.epam.reportportal.service.Launch; 24 | import com.epam.reportportal.service.ReportPortal; 25 | import com.epam.reportportal.service.ReportPortalClient; 26 | import com.epam.ta.reportportal.ws.model.FinishTestItemRQ; 27 | import org.apache.commons.lang3.tuple.Pair; 28 | import org.junit.jupiter.api.Test; 29 | import org.junit.jupiter.api.extension.ExtensionContext; 30 | import org.junit.platform.engine.TestExecutionResult; 31 | import org.junit.platform.launcher.TestExecutionListener; 32 | import org.junit.platform.launcher.TestIdentifier; 33 | import org.mockito.ArgumentCaptor; 34 | 35 | import java.util.Deque; 36 | import java.util.List; 37 | import java.util.concurrent.ConcurrentLinkedDeque; 38 | import java.util.stream.Collectors; 39 | import java.util.stream.Stream; 40 | 41 | import static com.epam.reportportal.junit5.util.TestUtils.runClasses; 42 | import static com.epam.reportportal.util.test.CommonUtils.namedId; 43 | import static org.hamcrest.MatcherAssert.assertThat; 44 | import static org.hamcrest.Matchers.equalTo; 45 | import static org.hamcrest.Matchers.sameInstance; 46 | import static org.mockito.ArgumentMatchers.any; 47 | import static org.mockito.Mockito.*; 48 | 49 | /** 50 | * @author Ivan Budayeu 51 | */ 52 | public class StepReporterTest { 53 | 54 | public static class TestExtension extends ReportPortalExtension { 55 | static final String testClassUuid = namedId("class"); 56 | static final String testMethodUuid = namedId("test"); 57 | static final List stepUuidList = Stream.generate(() -> namedId("step")).limit(3).collect(Collectors.toList()); 58 | static final List> testStepUuidOrder = stepUuidList.stream() 59 | .map(u -> Pair.of(testMethodUuid, u)) 60 | .collect(Collectors.toList()); 61 | 62 | static final ThreadLocal client = new ThreadLocal<>(); 63 | static final ThreadLocal launch = new ThreadLocal<>(); 64 | 65 | public static void init() { 66 | client.set(mock(ReportPortalClient.class)); 67 | TestUtils.mockLaunch(client.get(), "launchUuid", testClassUuid, testMethodUuid); 68 | TestUtils.mockNestedSteps(client.get(), testStepUuidOrder); 69 | TestUtils.mockLogging(client.get()); 70 | ReportPortal reportPortal = ReportPortal.create(client.get(), TestUtils.standardParameters()); 71 | launch.set(reportPortal.newLaunch(TestUtils.launchRQ(reportPortal.getParameters()))); 72 | } 73 | 74 | @Override 75 | protected Launch getLaunch(ExtensionContext context) { 76 | return launch.get(); 77 | } 78 | } 79 | 80 | public static class Listener implements TestExecutionListener { 81 | public Deque results = new ConcurrentLinkedDeque<>(); 82 | 83 | @Override 84 | public void executionFinished(TestIdentifier testIdentifier, TestExecutionResult testExecutionResult) { 85 | results.add(testExecutionResult); 86 | } 87 | } 88 | 89 | @Test 90 | public void verify_failed_nested_step_not_fails_test_run() { 91 | TestExtension.init(); 92 | Listener listener = new Listener(); 93 | runClasses(listener, ManualStepReporterFeatureTest.class); 94 | 95 | ReportPortalClient client = TestExtension.client.get(); 96 | ArgumentCaptor finishNestedStep = ArgumentCaptor.forClass(FinishTestItemRQ.class); 97 | verify(client, timeout(1000)).finishTestItem(eq(TestExtension.stepUuidList.get(2)), finishNestedStep.capture()); 98 | 99 | ArgumentCaptor finishTestStep = ArgumentCaptor.forClass(FinishTestItemRQ.class); 100 | verify(client, timeout(1000)).finishTestItem(eq(TestExtension.testMethodUuid), finishTestStep.capture()); 101 | 102 | assertThat(finishNestedStep.getValue().getStatus(), equalTo(ItemStatus.FAILED.name())); 103 | assertThat(finishTestStep.getValue().getStatus(), equalTo(ItemStatus.FAILED.name())); 104 | 105 | assertThat(listener.results.remove().getStatus(), sameInstance(TestExecutionResult.Status.SUCCESSFUL)); 106 | } 107 | 108 | @Test 109 | public void verify_listener_finishes_unfinished_step() { 110 | TestExtension.init(); 111 | runClasses(ManualStepReporterSimpleTest.class); 112 | 113 | ReportPortalClient client = TestExtension.client.get(); 114 | verify(client, timeout(1000)).finishTestItem(eq(TestExtension.stepUuidList.get(0)), any()); 115 | } 116 | 117 | } 118 | -------------------------------------------------------------------------------- /src/test/java/com/epam/reportportal/junit5/SystemAttributesFetcherTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 EPAM Systems 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 com.epam.reportportal.junit5; 18 | 19 | import com.epam.ta.reportportal.ws.model.attribute.ItemAttributeResource; 20 | import com.epam.ta.reportportal.ws.model.attribute.ItemAttributesRQ; 21 | import org.apache.commons.lang3.StringUtils; 22 | import org.junit.jupiter.api.Assertions; 23 | import org.junit.jupiter.api.Test; 24 | 25 | import java.util.Arrays; 26 | import java.util.List; 27 | import java.util.Set; 28 | import java.util.stream.Collectors; 29 | 30 | import static org.junit.jupiter.api.Assertions.*; 31 | 32 | /** 33 | * @author Ihar Kahadouski 34 | */ 35 | class SystemAttributesFetcherTest { 36 | 37 | private static final List expectedKeys = Arrays.asList("jvm", "os", "agent", "skippedIssue"); 38 | 39 | @Test 40 | void systemAttributesRetrievingTest() { 41 | Set systemAttributes = SystemAttributesFetcher.collectSystemAttributes(false); 42 | assertNotNull(systemAttributes); 43 | assertEquals(expectedKeys.size(), systemAttributes.size()); 44 | systemAttributes.stream().map(ItemAttributesRQ::isSystem).forEach(Assertions::assertTrue); 45 | assertTrue(systemAttributes.stream().map(ItemAttributeResource::getKey).collect(Collectors.toList()).containsAll(expectedKeys)); 46 | assertEquals( 47 | expectedKeys.size(), 48 | (int) systemAttributes.stream().map(ItemAttributeResource::getValue).filter(StringUtils::isNotBlank).count() 49 | ); 50 | } 51 | } -------------------------------------------------------------------------------- /src/test/java/com/epam/reportportal/junit5/TestInitTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2023 EPAM Systems 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 com.epam.reportportal.junit5; 18 | 19 | import com.epam.reportportal.junit5.features.beforeafterall.FailedConstructorTest; 20 | import com.epam.reportportal.junit5.util.TestUtils; 21 | import com.epam.reportportal.listeners.ItemStatus; 22 | import com.epam.reportportal.service.Launch; 23 | import com.epam.reportportal.service.step.StepReporter; 24 | import com.epam.reportportal.util.test.CommonUtils; 25 | import com.epam.ta.reportportal.ws.model.FinishTestItemRQ; 26 | import com.epam.ta.reportportal.ws.model.OperationCompletionRS; 27 | import com.epam.ta.reportportal.ws.model.StartTestItemRQ; 28 | import io.reactivex.Maybe; 29 | import org.junit.jupiter.api.BeforeEach; 30 | import org.junit.jupiter.api.Test; 31 | import org.junit.jupiter.api.TestInstance; 32 | import org.junit.jupiter.api.extension.ExtensionContext; 33 | import org.mockito.ArgumentCaptor; 34 | import org.mockito.stubbing.Answer; 35 | 36 | import java.util.List; 37 | import java.util.Map; 38 | import java.util.concurrent.ConcurrentHashMap; 39 | import java.util.stream.Collectors; 40 | 41 | import static com.epam.reportportal.junit5.TestInitTest.TestInitTestExtension.LAUNCH; 42 | import static org.hamcrest.MatcherAssert.assertThat; 43 | import static org.hamcrest.Matchers.equalTo; 44 | import static org.hamcrest.Matchers.hasSize; 45 | import static org.mockito.ArgumentMatchers.any; 46 | import static org.mockito.ArgumentMatchers.notNull; 47 | import static org.mockito.Mockito.*; 48 | import static org.mockito.Mockito.times; 49 | 50 | @TestInstance(TestInstance.Lifecycle.PER_CLASS) 51 | public class TestInitTest { 52 | public static class TestInitTestExtension extends ReportPortalExtension { 53 | static Launch LAUNCH; 54 | 55 | @Override 56 | protected Launch getLaunch(ExtensionContext context) { 57 | return LAUNCH; 58 | } 59 | } 60 | 61 | private Map> itemStartMap; 62 | private Map, FinishTestItemRQ> itemFinishMap; 63 | 64 | 65 | @BeforeEach 66 | public void setupMock() { 67 | itemStartMap = new ConcurrentHashMap<>(); 68 | itemFinishMap = new ConcurrentHashMap<>(); 69 | LAUNCH = mock(Launch.class); 70 | when(LAUNCH.getStepReporter()).thenReturn(StepReporter.NOOP_STEP_REPORTER); 71 | when(LAUNCH.startTestItem(any())).thenAnswer((Answer>) invocation -> CommonUtils.createMaybeUuid()); 72 | when(LAUNCH.startTestItem(any(), any())).thenAnswer((Answer>) invocation -> { 73 | Maybe uuidMaybe = CommonUtils.createMaybeUuid(); 74 | StartTestItemRQ start = invocation.getArgument(1); 75 | itemStartMap.put(start, uuidMaybe); 76 | return uuidMaybe; 77 | }); 78 | when(LAUNCH.finishTestItem(any(), any())).thenAnswer((Answer>) invocation -> { 79 | Maybe uuidMaybe = invocation.getArgument(0); 80 | FinishTestItemRQ finish = invocation.getArgument(1); 81 | itemFinishMap.put(uuidMaybe, finish); 82 | return Maybe.just(new OperationCompletionRS()); 83 | }); 84 | } 85 | 86 | @Test 87 | public void verify_a_test_with_failed_init_in_constructor_reported() { 88 | TestUtils.runClasses(FailedConstructorTest.class); 89 | 90 | verify(LAUNCH, times(1)).startTestItem(any()); // Start parent Suite 91 | ArgumentCaptor captorStart = ArgumentCaptor.forClass(StartTestItemRQ.class); 92 | verify(LAUNCH, times(2)).startTestItem(notNull(), captorStart.capture()); // Start a suite and two methods 93 | 94 | ArgumentCaptor captorFinish = ArgumentCaptor.forClass(FinishTestItemRQ.class); 95 | verify(LAUNCH, times(3)).finishTestItem(notNull(), captorFinish.capture()); // finish tests and suites 96 | 97 | List beforeAll = captorStart.getAllValues() 98 | .stream() 99 | .filter(e -> e.getType().equals(ItemType.BEFORE_CLASS.name())) 100 | .collect(Collectors.toList()); 101 | 102 | List beforeEach = captorStart.getAllValues() 103 | .stream() 104 | .filter(e -> e.getType().equals(ItemType.BEFORE_METHOD.name())) 105 | .collect(Collectors.toList()); 106 | 107 | List testSteps = captorStart.getAllValues() 108 | .stream() 109 | .filter(e -> e.getType().equals(ItemType.STEP.name())) 110 | .collect(Collectors.toList()); 111 | 112 | assertThat("There are one @Test methods", testSteps, hasSize(1)); 113 | assertThat("There are no @BeforeEach methods", beforeEach, hasSize(0)); 114 | assertThat("There are one @BeforeAll method", beforeAll, hasSize(1)); 115 | 116 | FinishTestItemRQ finishTest = itemFinishMap.get(itemStartMap.get(testSteps.get(0))); 117 | assertThat(finishTest.getStatus(), equalTo(ItemStatus.FAILED.name())); 118 | 119 | FinishTestItemRQ finishBeforeAll = itemFinishMap.get(itemStartMap.get(beforeAll.get(0))); 120 | assertThat(finishBeforeAll.getStatus(), equalTo(ItemStatus.PASSED.name())); 121 | } 122 | } 123 | -------------------------------------------------------------------------------- /src/test/java/com/epam/reportportal/junit5/bugs/LaunchStartTimeTest.java: -------------------------------------------------------------------------------- 1 | package com.epam.reportportal.junit5.bugs; 2 | 3 | import com.epam.reportportal.junit5.ReportPortalExtension; 4 | import com.epam.reportportal.junit5.features.bug.TestIncorrectStartTime; 5 | import com.epam.reportportal.junit5.util.TestUtils; 6 | import com.epam.reportportal.service.ReportPortal; 7 | import com.epam.reportportal.service.ReportPortalClient; 8 | import com.epam.reportportal.util.test.CommonUtils; 9 | import com.epam.ta.reportportal.ws.model.StartTestItemRQ; 10 | import com.epam.ta.reportportal.ws.model.launch.StartLaunchRQ; 11 | import org.junit.jupiter.api.BeforeEach; 12 | import org.junit.jupiter.api.Test; 13 | import org.mockito.ArgumentCaptor; 14 | 15 | import java.util.Date; 16 | import java.util.concurrent.TimeUnit; 17 | 18 | import static org.hamcrest.MatcherAssert.assertThat; 19 | import static org.hamcrest.Matchers.lessThanOrEqualTo; 20 | import static org.mockito.ArgumentMatchers.any; 21 | import static org.mockito.Mockito.*; 22 | 23 | public class LaunchStartTimeTest { 24 | 25 | private final String launchUuid = CommonUtils.namedId("launch"); 26 | private final String suitedUuid = CommonUtils.namedId("suite"); 27 | private final String testMethodUuid = CommonUtils.namedId("test"); 28 | 29 | public static class TestExtension extends ReportPortalExtension { 30 | static volatile ReportPortal REPORT_PORTAL; 31 | 32 | @Override 33 | protected ReportPortal getReporter() { 34 | return REPORT_PORTAL; 35 | } 36 | } 37 | 38 | private ReportPortalClient client; 39 | 40 | @BeforeEach 41 | public void setupMock() { 42 | client = mock(ReportPortalClient.class); 43 | TestUtils.mockLaunch(client, launchUuid, suitedUuid, testMethodUuid); 44 | TestUtils.mockLogging(client); 45 | TestExtension.REPORT_PORTAL = ReportPortal.create(client, TestUtils.standardParameters()); 46 | } 47 | 48 | @Test 49 | public void verify_start_time_has_correct_order() { 50 | TestUtils.runClasses(TestIncorrectStartTime.class); 51 | 52 | ArgumentCaptor startLaunchCaptor = ArgumentCaptor.forClass(StartLaunchRQ.class); 53 | verify(client, timeout(TimeUnit.SECONDS.toMillis(2)).times(1)).startLaunch(startLaunchCaptor.capture()); 54 | 55 | ArgumentCaptor startSuiteCaptor = ArgumentCaptor.forClass(StartTestItemRQ.class); 56 | verify(client, timeout(TimeUnit.SECONDS.toMillis(2)).times(1)).startTestItem(startSuiteCaptor.capture()); 57 | 58 | ArgumentCaptor startTestCaptor = ArgumentCaptor.forClass(StartTestItemRQ.class); 59 | verify(client, timeout(TimeUnit.SECONDS.toMillis(2)).times(1)).startTestItem(any(), startTestCaptor.capture()); 60 | 61 | Date launchStart = startLaunchCaptor.getValue().getStartTime(); 62 | Date suiteStart = startSuiteCaptor.getValue().getStartTime(); 63 | Date itemStart = startTestCaptor.getValue().getStartTime(); 64 | 65 | assertThat(launchStart, lessThanOrEqualTo(suiteStart)); 66 | assertThat(suiteStart, lessThanOrEqualTo(itemStart)); 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /src/test/java/com/epam/reportportal/junit5/features/TestFailure.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2024 EPAM Systems 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 | * https://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 com.epam.reportportal.junit5.features; 18 | 19 | import com.epam.reportportal.junit5.BasicTest; 20 | import org.junit.jupiter.api.Assertions; 21 | import org.junit.jupiter.api.Test; 22 | import org.junit.jupiter.api.extension.ExtendWith; 23 | 24 | @ExtendWith(BasicTest.BasicTestExtension.class) 25 | public class TestFailure { 26 | 27 | public static final String FAILURE_MESSAGE = "Test failure"; 28 | 29 | @Test 30 | public void testFailure() { 31 | Assertions.fail(FAILURE_MESSAGE); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/test/java/com/epam/reportportal/junit5/features/attributes/ClassLevelAttributesTest.java: -------------------------------------------------------------------------------- 1 | package com.epam.reportportal.junit5.features.attributes; 2 | 3 | import com.epam.reportportal.annotations.attribute.Attribute; 4 | import com.epam.reportportal.annotations.attribute.Attributes; 5 | import com.epam.reportportal.junit5.AttributesTest; 6 | import org.junit.jupiter.api.Test; 7 | import org.junit.jupiter.api.extension.ExtendWith; 8 | import org.slf4j.Logger; 9 | import org.slf4j.LoggerFactory; 10 | 11 | @ExtendWith(AttributesTest.AttributesTestExtension.class) 12 | @Attributes(attributes = {@Attribute(key = ClassLevelAttributesTest.KEY, value = ClassLevelAttributesTest.VALUE)}) 13 | public class ClassLevelAttributesTest { 14 | public static final String KEY = "attribute_test_key"; 15 | public static final String VALUE = "attribute_test_value"; 16 | 17 | private static final Logger LOGGER = LoggerFactory.getLogger(ClassLevelAttributesTest.class); 18 | 19 | @Test 20 | public void testClassLevelAttributes() { 21 | LOGGER.info("Inside 'testClassLevelAttributes' method"); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/test/java/com/epam/reportportal/junit5/features/attributes/MethodLevelAttributesTest.java: -------------------------------------------------------------------------------- 1 | package com.epam.reportportal.junit5.features.attributes; 2 | 3 | import com.epam.reportportal.annotations.attribute.Attribute; 4 | import com.epam.reportportal.annotations.attribute.Attributes; 5 | import com.epam.reportportal.junit5.AttributesTest; 6 | import org.junit.jupiter.api.Test; 7 | import org.junit.jupiter.api.extension.ExtendWith; 8 | import org.slf4j.Logger; 9 | import org.slf4j.LoggerFactory; 10 | 11 | @ExtendWith(AttributesTest.AttributesTestExtension.class) 12 | public class MethodLevelAttributesTest { 13 | private static final Logger LOGGER = LoggerFactory.getLogger(MethodLevelAttributesTest.class); 14 | 15 | @Test 16 | @Attributes(attributes = {@Attribute(key = "myKey", value = "myValue")}) 17 | public void testMethodLevelAttributes() { 18 | LOGGER.info("Inside 'testMethodLevelAttributes' method"); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /src/test/java/com/epam/reportportal/junit5/features/beforeafterall/AfterAllTest.java: -------------------------------------------------------------------------------- 1 | package com.epam.reportportal.junit5.features.beforeafterall; 2 | 3 | import org.junit.jupiter.api.AfterAll; 4 | import org.junit.jupiter.api.Test; 5 | import org.junit.jupiter.api.extension.ExtendWith; 6 | 7 | @ExtendWith(com.epam.reportportal.junit5.BeforeAfterAllTest.BeforeAfterAllTestExtension.class) 8 | public class AfterAllTest { 9 | public static final String CLASS_ID = "3b6f28a9-4988-464e-b07f-17ab9f3abe72"; 10 | 11 | @Test 12 | public void testAfterAll() { 13 | System.out.println("Test: " + CLASS_ID); 14 | } 15 | 16 | @AfterAll 17 | public static void afterAll() { 18 | System.out.println("After all: " + CLASS_ID); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /src/test/java/com/epam/reportportal/junit5/features/beforeafterall/BeforeAfterAllBeforeAfterEachTwoTestsTest.java: -------------------------------------------------------------------------------- 1 | package com.epam.reportportal.junit5.features.beforeafterall; 2 | 3 | import org.junit.jupiter.api.*; 4 | import org.junit.jupiter.api.extension.ExtendWith; 5 | 6 | @ExtendWith(com.epam.reportportal.junit5.BeforeAfterAllTest.BeforeAfterAllTestExtension.class) 7 | public class BeforeAfterAllBeforeAfterEachTwoTestsTest { 8 | public static final String CLASS_ID = "777a99a9-e9fd-43f2-9ab4-8621cffbebf4"; 9 | 10 | @BeforeAll 11 | public static void beforeAll() { 12 | System.out.println("Before all: " + CLASS_ID); 13 | } 14 | 15 | @BeforeEach 16 | public void beforeEach() { 17 | System.out.println("Before each: " + CLASS_ID); 18 | } 19 | 20 | @Test 21 | public void testFirstBeforeAfterAllBeforeAfterEach() { 22 | System.out.println("First Test: " + CLASS_ID); 23 | } 24 | 25 | @Test 26 | public void testSecondBeforeAfterAllBeforeAfterEach() { 27 | System.out.println("Second Test: " + CLASS_ID); 28 | } 29 | 30 | @AfterEach 31 | public void afterEach() { 32 | System.out.println("After each: " + CLASS_ID); 33 | } 34 | 35 | @AfterAll 36 | public static void afterAll() { 37 | System.out.println("After all: " + CLASS_ID); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/test/java/com/epam/reportportal/junit5/features/beforeafterall/BeforeAfterAllFailedTest.java: -------------------------------------------------------------------------------- 1 | package com.epam.reportportal.junit5.features.beforeafterall; 2 | 3 | import org.junit.jupiter.api.AfterAll; 4 | import org.junit.jupiter.api.BeforeAll; 5 | import org.junit.jupiter.api.Test; 6 | import org.junit.jupiter.api.extension.ExtendWith; 7 | 8 | @ExtendWith(com.epam.reportportal.junit5.BeforeAfterAllTest.BeforeAfterAllTestExtension.class) 9 | public class BeforeAfterAllFailedTest { 10 | public static final String CLASS_ID = "e3a09449-b508-485d-aa9b-b6b2cf4b4fd5"; 11 | 12 | @BeforeAll 13 | public static void beforeAll() { 14 | System.out.println("Before all: " + CLASS_ID); 15 | } 16 | 17 | @Test 18 | public void testBeforeAfterAllFailed() { 19 | throw new IllegalStateException("Test: " + CLASS_ID); 20 | } 21 | 22 | @AfterAll 23 | public static void afterAll() { 24 | System.out.println("After all: " + CLASS_ID); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/test/java/com/epam/reportportal/junit5/features/beforeafterall/BeforeAfterAllTest.java: -------------------------------------------------------------------------------- 1 | package com.epam.reportportal.junit5.features.beforeafterall; 2 | 3 | import org.junit.jupiter.api.AfterAll; 4 | import org.junit.jupiter.api.BeforeAll; 5 | import org.junit.jupiter.api.Test; 6 | import org.junit.jupiter.api.extension.ExtendWith; 7 | 8 | @ExtendWith(com.epam.reportportal.junit5.BeforeAfterAllTest.BeforeAfterAllTestExtension.class) 9 | public class BeforeAfterAllTest { 10 | public static final String CLASS_ID = "96a167df-0353-41cf-8d4d-dcba8368ddac"; 11 | 12 | @BeforeAll 13 | public static void beforeAll() { 14 | System.out.println("Before all: " + CLASS_ID); 15 | } 16 | 17 | @Test 18 | public void testBeforeAfterAll() { 19 | System.out.println("Test: " + CLASS_ID); 20 | } 21 | 22 | @AfterAll 23 | public static void afterAll() { 24 | System.out.println("After all: " + CLASS_ID); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/test/java/com/epam/reportportal/junit5/features/beforeafterall/BeforeAfterAllTwoTestsTest.java: -------------------------------------------------------------------------------- 1 | package com.epam.reportportal.junit5.features.beforeafterall; 2 | 3 | import org.junit.jupiter.api.AfterAll; 4 | import org.junit.jupiter.api.BeforeAll; 5 | import org.junit.jupiter.api.Test; 6 | import org.junit.jupiter.api.extension.ExtendWith; 7 | 8 | @ExtendWith(com.epam.reportportal.junit5.BeforeAfterAllTest.BeforeAfterAllTestExtension.class) 9 | public class BeforeAfterAllTwoTestsTest { 10 | public static final String CLASS_ID = "7a9347b3-4d66-4133-88b7-60d52db61436"; 11 | 12 | @BeforeAll 13 | public static void beforeAll() { 14 | System.out.println("Before all: " + CLASS_ID); 15 | } 16 | 17 | @Test 18 | public void testFirstBeforeAfterAll() { 19 | System.out.println("First Test: " + CLASS_ID); 20 | } 21 | 22 | @Test 23 | public void testSecondBeforeAfterAll() { 24 | System.out.println("Second Test: " + CLASS_ID); 25 | } 26 | 27 | @AfterAll 28 | public static void afterAll() { 29 | System.out.println("After all: " + CLASS_ID); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/test/java/com/epam/reportportal/junit5/features/beforeafterall/BeforeAllAfterAllFailedTest.java: -------------------------------------------------------------------------------- 1 | package com.epam.reportportal.junit5.features.beforeafterall; 2 | 3 | import com.epam.reportportal.junit5.BeforeAfterAllTest; 4 | import org.junit.jupiter.api.AfterAll; 5 | import org.junit.jupiter.api.BeforeAll; 6 | import org.junit.jupiter.api.Test; 7 | import org.junit.jupiter.api.extension.ExtendWith; 8 | 9 | @ExtendWith(BeforeAfterAllTest.BeforeAfterAllTestExtension.class) 10 | public class BeforeAllAfterAllFailedTest { 11 | public static final String CLASS_ID = "28b580fa-a7c0-4a7e-b0bc-54f196565d69"; 12 | 13 | @BeforeAll 14 | public static void beforeAllFailed() { 15 | System.out.println("Before all: " + CLASS_ID); 16 | } 17 | 18 | @Test 19 | public void testBeforeAllFailed() { 20 | System.out.println("Test: " + CLASS_ID); 21 | } 22 | 23 | @AfterAll 24 | public static void afterAllFailed() { 25 | throw new IllegalStateException("After all: " + CLASS_ID); 26 | } 27 | 28 | } 29 | -------------------------------------------------------------------------------- /src/test/java/com/epam/reportportal/junit5/features/beforeafterall/BeforeAllFailedTest.java: -------------------------------------------------------------------------------- 1 | package com.epam.reportportal.junit5.features.beforeafterall; 2 | 3 | import org.junit.jupiter.api.BeforeAll; 4 | import org.junit.jupiter.api.Test; 5 | import org.junit.jupiter.api.extension.ExtendWith; 6 | 7 | @ExtendWith(com.epam.reportportal.junit5.BeforeAfterAllTest.BeforeAfterAllTestExtension.class) 8 | public class BeforeAllFailedTest { 9 | public static final String CLASS_ID = "710b184b-4f81-403c-8310-9a54f56b687b"; 10 | 11 | @BeforeAll 12 | public static void beforeAllFailed() { 13 | throw new IllegalStateException("Before all: " + CLASS_ID); 14 | } 15 | 16 | @Test 17 | public void testBeforeAllFailed() { 18 | System.out.println("Test: " + CLASS_ID); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /src/test/java/com/epam/reportportal/junit5/features/beforeafterall/BeforeAllTest.java: -------------------------------------------------------------------------------- 1 | package com.epam.reportportal.junit5.features.beforeafterall; 2 | 3 | import org.junit.jupiter.api.BeforeAll; 4 | import org.junit.jupiter.api.Disabled; 5 | import org.junit.jupiter.api.Test; 6 | import org.junit.jupiter.api.extension.ExtendWith; 7 | 8 | @ExtendWith(com.epam.reportportal.junit5.BeforeAfterAllTest.BeforeAfterAllTestExtension.class) 9 | public class BeforeAllTest { 10 | public static final String CLASS_ID = "8b2354a9-4448-4189-ae5d-f74f547f0f66"; 11 | 12 | @BeforeAll 13 | public static void beforeAll() { 14 | System.out.println("Before all: " + CLASS_ID); 15 | } 16 | 17 | @Test 18 | public void testBeforeAll() { 19 | System.out.println("Test: " + CLASS_ID); 20 | } 21 | 22 | @Test 23 | @Disabled 24 | public void testDisabled() { 25 | System.out.println("Test: " + CLASS_ID); 26 | } 27 | 28 | } 29 | -------------------------------------------------------------------------------- /src/test/java/com/epam/reportportal/junit5/features/beforeafterall/FailedAfterEachTest.java: -------------------------------------------------------------------------------- 1 | package com.epam.reportportal.junit5.features.beforeafterall; 2 | 3 | import com.epam.reportportal.junit5.BeforeAfterAllTest; 4 | import org.junit.jupiter.api.AfterEach; 5 | import org.junit.jupiter.api.Test; 6 | import org.junit.jupiter.api.extension.ExtendWith; 7 | 8 | @ExtendWith(BeforeAfterAllTest.BeforeAfterAllTestExtension.class) 9 | public class FailedAfterEachTest { 10 | 11 | @Test 12 | public void testAfterEachFailed() { 13 | System.out.println("Test: testAfterEachFailed"); 14 | } 15 | 16 | @AfterEach 17 | public void afterEach() { 18 | throw new IllegalStateException("After each: afterEach"); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /src/test/java/com/epam/reportportal/junit5/features/beforeafterall/FailedConstructorTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2023 EPAM Systems 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 com.epam.reportportal.junit5.features.beforeafterall; 18 | 19 | import com.epam.reportportal.junit5.TestInitTest; 20 | import org.junit.jupiter.api.BeforeAll; 21 | import org.junit.jupiter.api.BeforeEach; 22 | import org.junit.jupiter.api.Test; 23 | import org.junit.jupiter.api.extension.ExtendWith; 24 | 25 | @ExtendWith(TestInitTest.TestInitTestExtension.class) 26 | public class FailedConstructorTest { 27 | private int a = 4 / 0; 28 | 29 | @BeforeAll 30 | public static void beforeAll() { 31 | } 32 | 33 | @BeforeEach 34 | public void beforeEach() { 35 | } 36 | 37 | @Test 38 | public void test() { 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/test/java/com/epam/reportportal/junit5/features/beforeafterall/NonStaticBeforeAfterAllTest.java: -------------------------------------------------------------------------------- 1 | package com.epam.reportportal.junit5.features.beforeafterall; 2 | 3 | import org.junit.jupiter.api.AfterAll; 4 | import org.junit.jupiter.api.BeforeAll; 5 | import org.junit.jupiter.api.Test; 6 | import org.junit.jupiter.api.TestInstance; 7 | import org.junit.jupiter.api.extension.ExtendWith; 8 | 9 | @ExtendWith(com.epam.reportportal.junit5.BeforeAfterAllTest.BeforeAfterAllTestExtension.class) 10 | @TestInstance(TestInstance.Lifecycle.PER_CLASS) 11 | public class NonStaticBeforeAfterAllTest { 12 | public static final String CLASS_ID = "d93ecaae-2161-4c1c-8b68-124ed4dcb4f1"; 13 | 14 | @BeforeAll 15 | public void beforeAll() { 16 | System.out.println("Before all: " + CLASS_ID); 17 | } 18 | 19 | @Test 20 | public void testBeforeAfterAll() { 21 | System.out.println("Test: " + CLASS_ID); 22 | } 23 | 24 | @AfterAll 25 | public void afterAll() { 26 | System.out.println("After all: " + CLASS_ID); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/test/java/com/epam/reportportal/junit5/features/bug/BeforeEachFailedDuplicate.java: -------------------------------------------------------------------------------- 1 | package com.epam.reportportal.junit5.features.bug; 2 | 3 | import com.epam.reportportal.junit5.bugs.BeforeEachFailedDuplication; 4 | import org.junit.jupiter.api.AfterAll; 5 | import org.junit.jupiter.api.AfterEach; 6 | import org.junit.jupiter.api.BeforeAll; 7 | import org.junit.jupiter.api.BeforeEach; 8 | import org.junit.jupiter.api.extension.ExtendWith; 9 | import org.junit.jupiter.params.ParameterizedTest; 10 | import org.junit.jupiter.params.provider.EnumSource; 11 | 12 | @ExtendWith(BeforeEachFailedDuplication.BeforeEachFailedDuplicationExtension.class) 13 | public class BeforeEachFailedDuplicate { 14 | 15 | public enum TestParams { 16 | ONE, 17 | TWO 18 | } 19 | 20 | @BeforeAll 21 | public static void beforeAll() { 22 | System.out.println("Before all"); 23 | } 24 | 25 | @BeforeEach 26 | public void beforeEach() throws InterruptedException { 27 | System.out.println("Before each"); 28 | Thread.sleep(100); 29 | } 30 | 31 | @ParameterizedTest 32 | @EnumSource(TestParams.class) 33 | public void testFirstBeforeAfterAllBeforeAfterEach(TestParams param) throws InterruptedException { 34 | System.out.println("First Test: " + param.name()); 35 | Thread.sleep(100); 36 | } 37 | 38 | @ParameterizedTest 39 | @EnumSource(TestParams.class) 40 | public void testSecondBeforeAfterAllBeforeAfterEach(TestParams param) throws InterruptedException { 41 | System.out.println("Second Test: " + param.name()); 42 | Thread.sleep(100); 43 | } 44 | 45 | @AfterEach 46 | public void afterEach() throws InterruptedException { 47 | System.out.println("After each"); 48 | Thread.sleep(100); 49 | } 50 | 51 | @AfterAll 52 | public static void afterAll() { 53 | System.out.println("After all"); 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /src/test/java/com/epam/reportportal/junit5/features/bug/TestIncorrectStartTime.java: -------------------------------------------------------------------------------- 1 | package com.epam.reportportal.junit5.features.bug; 2 | 3 | import com.epam.reportportal.junit5.bugs.LaunchStartTimeTest; 4 | import com.epam.reportportal.util.test.CommonUtils; 5 | import org.junit.jupiter.api.Test; 6 | import org.junit.jupiter.api.extension.ExtendWith; 7 | 8 | @ExtendWith(LaunchStartTimeTest.TestExtension.class) 9 | public class TestIncorrectStartTime { 10 | 11 | @Test 12 | public void test_start_time() throws InterruptedException { 13 | Thread.sleep(CommonUtils.MINIMAL_TEST_PAUSE); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /src/test/java/com/epam/reportportal/junit5/features/callback/CallbackFeatureTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 EPAM Systems 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 com.epam.reportportal.junit5.features.callback; 18 | 19 | import com.epam.reportportal.junit5.CallbackReportingTest; 20 | import com.epam.reportportal.junit5.utils.ItemTreeUtils; 21 | import com.epam.reportportal.service.tree.ItemTreeReporter; 22 | import com.epam.reportportal.service.tree.TestItemTree; 23 | import com.epam.ta.reportportal.ws.model.FinishTestItemRQ; 24 | import org.junit.jupiter.api.AfterEach; 25 | import org.junit.jupiter.api.Assertions; 26 | import org.junit.jupiter.api.Test; 27 | import org.junit.jupiter.api.TestInfo; 28 | import org.junit.jupiter.api.extension.ExtendWith; 29 | 30 | import java.util.Calendar; 31 | 32 | import static com.epam.reportportal.junit5.CallbackReportingTest.ITEM_CALLBACK_FINISH_STATUS; 33 | import static com.epam.reportportal.junit5.ReportPortalExtension.REPORT_PORTAL; 34 | import static com.epam.reportportal.junit5.ReportPortalExtension.TEST_ITEM_TREE; 35 | 36 | /** 37 | * @author Ivan Budayeu 38 | */ 39 | @ExtendWith(CallbackReportingTest.CallbackReportingExtension.class) 40 | public class CallbackFeatureTest { 41 | 42 | @Test 43 | void someTest() { 44 | Assertions.assertEquals(1, 1); 45 | } 46 | 47 | @AfterEach 48 | void afterMethod(TestInfo testInfo) { 49 | TestItemTree.TestItemLeaf testItemLeaf = ItemTreeUtils.retrieveLeaf(testInfo, TEST_ITEM_TREE); 50 | if (testItemLeaf != null) { 51 | finishWithStatus(ITEM_CALLBACK_FINISH_STATUS, testItemLeaf); 52 | } 53 | } 54 | 55 | private void finishWithStatus(String status, TestItemTree.TestItemLeaf testItemLeaf) { 56 | FinishTestItemRQ finishTestItemRQ = new FinishTestItemRQ(); 57 | finishTestItemRQ.setStatus(status); 58 | finishTestItemRQ.setEndTime(Calendar.getInstance().getTime()); 59 | ItemTreeReporter.finishItem(REPORT_PORTAL.getClient(), finishTestItemRQ, TEST_ITEM_TREE.getLaunchId(), testItemLeaf) 60 | .cache() 61 | .blockingGet(); 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /src/test/java/com/epam/reportportal/junit5/features/callback/CallbackLogFeatureTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 EPAM Systems 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 com.epam.reportportal.junit5.features.callback; 18 | 19 | import com.epam.reportportal.junit5.CallbackReportingTest; 20 | import com.epam.reportportal.junit5.utils.ItemTreeUtils; 21 | import com.epam.reportportal.service.tree.ItemTreeReporter; 22 | import com.epam.reportportal.service.tree.TestItemTree; 23 | import org.junit.jupiter.api.AfterEach; 24 | import org.junit.jupiter.api.Assertions; 25 | import org.junit.jupiter.api.Test; 26 | import org.junit.jupiter.api.TestInfo; 27 | import org.junit.jupiter.api.extension.ExtendWith; 28 | 29 | import static com.epam.reportportal.junit5.CallbackReportingTest.*; 30 | import static com.epam.reportportal.junit5.ReportPortalExtension.REPORT_PORTAL; 31 | import static com.epam.reportportal.junit5.ReportPortalExtension.TEST_ITEM_TREE; 32 | 33 | /** 34 | * @author Ivan Budayeu 35 | */ 36 | @ExtendWith(CallbackReportingTest.CallbackReportingExtension.class) 37 | public class CallbackLogFeatureTest { 38 | 39 | @Test 40 | void someTest() { 41 | Assertions.assertEquals(1, 1); 42 | } 43 | 44 | @AfterEach 45 | void afterMethod(TestInfo testInfo) { 46 | TestItemTree.TestItemLeaf testItemLeaf = ItemTreeUtils.retrieveLeaf(testInfo, TEST_ITEM_TREE); 47 | if (testItemLeaf != null) { 48 | attachLog(testItemLeaf); 49 | } 50 | } 51 | 52 | private static void attachLog(TestItemTree.TestItemLeaf testItemLeaf) { 53 | ItemTreeReporter.sendLog(REPORT_PORTAL.getClient(), 54 | ERROR_LOG_LEVEL, 55 | LOG_MESSAGE, 56 | LOG_TIME, 57 | TEST_ITEM_TREE.getLaunchId(), 58 | testItemLeaf 59 | ); 60 | } 61 | 62 | } 63 | -------------------------------------------------------------------------------- /src/test/java/com/epam/reportportal/junit5/features/coderef/SingleDynamicTest.java: -------------------------------------------------------------------------------- 1 | package com.epam.reportportal.junit5.features.coderef; 2 | 3 | import com.epam.reportportal.junit5.CodeReferenceTest; 4 | import org.junit.jupiter.api.DynamicTest; 5 | import org.junit.jupiter.api.TestFactory; 6 | import org.junit.jupiter.api.extension.ExtendWith; 7 | 8 | import java.util.UUID; 9 | import java.util.stream.Stream; 10 | 11 | import static org.junit.jupiter.api.DynamicTest.dynamicTest; 12 | 13 | @ExtendWith(CodeReferenceTest.CodeReferenceTestExtension.class) 14 | public class SingleDynamicTest { 15 | 16 | public static final String TEST_CASE_DISPLAY_NAME = UUID.randomUUID().toString(); 17 | 18 | @TestFactory 19 | Stream testForTestFactory() { 20 | return Stream.of(dynamicTest(TEST_CASE_DISPLAY_NAME, () -> System.out.println("Test factory test: " + TEST_CASE_DISPLAY_NAME))); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/test/java/com/epam/reportportal/junit5/features/coderef/SingleTest.java: -------------------------------------------------------------------------------- 1 | package com.epam.reportportal.junit5.features.coderef; 2 | 3 | import com.epam.reportportal.junit5.CodeReferenceTest; 4 | import org.junit.jupiter.api.DisplayName; 5 | import org.junit.jupiter.api.Test; 6 | import org.junit.jupiter.api.extension.ExtendWith; 7 | 8 | @ExtendWith(CodeReferenceTest.CodeReferenceTestExtension.class) 9 | public class SingleTest { 10 | 11 | public static final String TEST_CASE_DISPLAY_NAME = "0c6b91e-623d-498d-a56d-fae1f2bbcbe4"; 12 | 13 | @Test() 14 | @DisplayName("0c6b91e-623d-498d-a56d-fae1f2bbcbe4") 15 | public void singleTest() { 16 | System.out.println("Test factory test: " + TEST_CASE_DISPLAY_NAME); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/test/java/com/epam/reportportal/junit5/features/configname/ConfigurationMethodsDefaultDisplayNameTest.java: -------------------------------------------------------------------------------- 1 | package com.epam.reportportal.junit5.features.configname; 2 | 3 | import com.epam.reportportal.junit5.miscellaneous.DisplayNamesForConfigurationItemsTest; 4 | import org.junit.jupiter.api.*; 5 | import org.junit.jupiter.api.extension.ExtendWith; 6 | 7 | @ExtendWith(DisplayNamesForConfigurationItemsTest.TestExtension.class) 8 | public class ConfigurationMethodsDefaultDisplayNameTest { 9 | public static final String DISPLAY_NAME = "My custom display name"; 10 | 11 | @BeforeAll 12 | public static void beforeAll() { 13 | System.out.println("Before all"); 14 | } 15 | 16 | @BeforeEach 17 | public void beforeEach() { 18 | System.out.println("Before each"); 19 | } 20 | 21 | @Test 22 | public void testBeforeAfterAll() { 23 | System.out.println("Test"); 24 | } 25 | 26 | @AfterEach 27 | public void afterEach() { 28 | System.out.println("After each"); 29 | } 30 | 31 | @AfterAll 32 | public static void afterAll() { 33 | System.out.println("After all"); 34 | } 35 | 36 | } 37 | -------------------------------------------------------------------------------- /src/test/java/com/epam/reportportal/junit5/features/configname/ConfigurationMethodsDisplayNameGeneratorTest.java: -------------------------------------------------------------------------------- 1 | package com.epam.reportportal.junit5.features.configname; 2 | 3 | import com.epam.reportportal.junit5.miscellaneous.DisplayNamesForConfigurationItemsTest; 4 | import org.junit.jupiter.api.*; 5 | import org.junit.jupiter.api.extension.ExtendWith; 6 | 7 | @ExtendWith(DisplayNamesForConfigurationItemsTest.TestExtension.class) 8 | @DisplayNameGeneration(CustomDisplayNameGenerator.class) 9 | public class ConfigurationMethodsDisplayNameGeneratorTest { 10 | 11 | @BeforeAll 12 | public static void beforeAll() { 13 | System.out.println("Before all"); 14 | } 15 | 16 | @BeforeEach 17 | public void beforeEach() { 18 | System.out.println("Before each"); 19 | } 20 | 21 | @Test 22 | public void testBeforeAfterAll() { 23 | System.out.println("Test"); 24 | } 25 | 26 | @AfterEach 27 | public void afterEach() { 28 | System.out.println("After each"); 29 | } 30 | 31 | @AfterAll 32 | public static void afterAll() { 33 | System.out.println("After all"); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/test/java/com/epam/reportportal/junit5/features/configname/ConfigurationMethodsDisplayNameTest.java: -------------------------------------------------------------------------------- 1 | package com.epam.reportportal.junit5.features.configname; 2 | 3 | import com.epam.reportportal.junit5.miscellaneous.DisplayNamesForConfigurationItemsTest; 4 | import org.junit.jupiter.api.*; 5 | import org.junit.jupiter.api.extension.ExtendWith; 6 | 7 | @ExtendWith(DisplayNamesForConfigurationItemsTest.TestExtension.class) 8 | public class ConfigurationMethodsDisplayNameTest { 9 | public static final String DISPLAY_NAME = "My custom display name"; 10 | 11 | @DisplayName(DISPLAY_NAME) 12 | @BeforeAll 13 | public static void beforeAll() { 14 | System.out.println("Before all"); 15 | } 16 | 17 | @DisplayName(DISPLAY_NAME) 18 | @BeforeEach 19 | public void beforeEach() { 20 | System.out.println("Before each"); 21 | } 22 | 23 | @DisplayName(DISPLAY_NAME) 24 | @Test 25 | public void testBeforeAfterAll() { 26 | System.out.println("Test"); 27 | } 28 | 29 | @DisplayName(DISPLAY_NAME) 30 | @AfterEach 31 | public void afterEach() { 32 | System.out.println("After each"); 33 | } 34 | 35 | @DisplayName(DISPLAY_NAME) 36 | @AfterAll 37 | public static void afterAll() { 38 | System.out.println("After all"); 39 | } 40 | 41 | } 42 | -------------------------------------------------------------------------------- /src/test/java/com/epam/reportportal/junit5/features/configname/CustomDisplayNameGenerator.java: -------------------------------------------------------------------------------- 1 | package com.epam.reportportal.junit5.features.configname; 2 | 3 | import org.junit.jupiter.api.DisplayNameGenerator; 4 | 5 | import java.lang.reflect.Method; 6 | 7 | public class CustomDisplayNameGenerator implements DisplayNameGenerator { 8 | public static final String DISPLAY_NAME_CLASS = "My custom display name for class"; 9 | public static final String DISPLAY_NAME_NESTED_CLASS = "My custom display name for nested class"; 10 | public static final String DISPLAY_NAME_METHOD = "My custom display name for method"; 11 | 12 | @Override 13 | public String generateDisplayNameForClass(Class testClass) { 14 | return DISPLAY_NAME_CLASS; 15 | } 16 | 17 | @Override 18 | public String generateDisplayNameForNestedClass(Class nestedClass) { 19 | return DISPLAY_NAME_NESTED_CLASS; 20 | } 21 | 22 | @Override 23 | public String generateDisplayNameForMethod(Class testClass, Method testMethod) { 24 | return DISPLAY_NAME_METHOD; 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/test/java/com/epam/reportportal/junit5/features/description/DescriptionAnnotatedClassDynamicTest.java: -------------------------------------------------------------------------------- 1 | package com.epam.reportportal.junit5.features.description; 2 | 3 | import com.epam.reportportal.annotations.Description; 4 | import com.epam.reportportal.junit5.DescriptionTest; 5 | import org.junit.jupiter.api.DynamicTest; 6 | import org.junit.jupiter.api.TestFactory; 7 | import org.junit.jupiter.api.extension.ExtendWith; 8 | 9 | import java.util.stream.Stream; 10 | 11 | import static org.junit.jupiter.api.DynamicTest.dynamicTest; 12 | 13 | @ExtendWith(DescriptionTest.TestExtension.class) 14 | @Description(DescriptionAnnotatedClassDynamicTest.TEST_DESCRIPTION_DYNAMIC_CLASS) 15 | public class DescriptionAnnotatedClassDynamicTest { 16 | public static final String TEST_DESCRIPTION_DYNAMIC_CLASS = "My test description on the dynamic class"; 17 | @TestFactory 18 | 19 | Stream testForTestFactory() { 20 | return Stream.of(dynamicTest("My dynamic test", () -> System.out.println("Inside dynamic test"))); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/test/java/com/epam/reportportal/junit5/features/description/DescriptionAnnotatedClassTest.java: -------------------------------------------------------------------------------- 1 | package com.epam.reportportal.junit5.features.description; 2 | 3 | import com.epam.reportportal.annotations.Description; 4 | import com.epam.reportportal.junit5.DescriptionTest; 5 | import org.junit.jupiter.api.Test; 6 | import org.junit.jupiter.api.extension.ExtendWith; 7 | 8 | @Description(DescriptionAnnotatedClassTest.TEST_DESCRIPTION_CLASS) 9 | @ExtendWith(DescriptionTest.TestExtension.class) 10 | public class DescriptionAnnotatedClassTest { 11 | public static final String TEST_DESCRIPTION_CLASS = "My test description on the class"; 12 | @Test 13 | public void testDescriptionTest() { 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /src/test/java/com/epam/reportportal/junit5/features/description/DescriptionAnnotatedMethodAndClassDynamicTest.java: -------------------------------------------------------------------------------- 1 | package com.epam.reportportal.junit5.features.description; 2 | 3 | import com.epam.reportportal.annotations.Description; 4 | import com.epam.reportportal.junit5.DescriptionTest; 5 | import org.junit.jupiter.api.DynamicTest; 6 | import org.junit.jupiter.api.TestFactory; 7 | import org.junit.jupiter.api.extension.ExtendWith; 8 | 9 | import java.util.stream.Stream; 10 | 11 | import static org.junit.jupiter.api.DynamicTest.dynamicTest; 12 | 13 | @ExtendWith(DescriptionTest.TestExtension.class) 14 | @Description(DescriptionAnnotatedClassDynamicTest.TEST_DESCRIPTION_DYNAMIC_CLASS) 15 | public class DescriptionAnnotatedMethodAndClassDynamicTest { 16 | @TestFactory 17 | @Description(DescriptionAnnotatedMethodDynamicTest.TEST_DESCRIPTION_DYNAMIC_METHOD) 18 | Stream testForTestFactory() { 19 | return Stream.of(dynamicTest("My dynamic test", () -> System.out.println("Inside dynamic test"))); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/test/java/com/epam/reportportal/junit5/features/description/DescriptionAnnotatedMethodAndClassTest.java: -------------------------------------------------------------------------------- 1 | package com.epam.reportportal.junit5.features.description; 2 | 3 | import com.epam.reportportal.annotations.Description; 4 | import com.epam.reportportal.junit5.DescriptionTest; 5 | import org.junit.jupiter.api.Test; 6 | import org.junit.jupiter.api.extension.ExtendWith; 7 | 8 | @ExtendWith(DescriptionTest.TestExtension.class) 9 | @Description(DescriptionAnnotatedClassTest.TEST_DESCRIPTION_CLASS) 10 | public class DescriptionAnnotatedMethodAndClassTest { 11 | @Test 12 | @Description(DescriptionAnnotatedMethodTest.TEST_DESCRIPTION_METHOD) 13 | public void testDescriptionTest() { 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /src/test/java/com/epam/reportportal/junit5/features/description/DescriptionAnnotatedMethodDynamicTest.java: -------------------------------------------------------------------------------- 1 | package com.epam.reportportal.junit5.features.description; 2 | 3 | import com.epam.reportportal.annotations.Description; 4 | import com.epam.reportportal.junit5.DescriptionTest; 5 | import org.junit.jupiter.api.DynamicTest; 6 | import org.junit.jupiter.api.TestFactory; 7 | import org.junit.jupiter.api.extension.ExtendWith; 8 | 9 | import java.util.stream.Stream; 10 | 11 | import static org.junit.jupiter.api.DynamicTest.dynamicTest; 12 | 13 | @ExtendWith(DescriptionTest.TestExtension.class) 14 | public class DescriptionAnnotatedMethodDynamicTest { 15 | public static final String TEST_DESCRIPTION_DYNAMIC_METHOD = "My test description on the dynamic method"; 16 | @TestFactory 17 | @Description(TEST_DESCRIPTION_DYNAMIC_METHOD) 18 | Stream testForTestFactory() { 19 | return Stream.of(dynamicTest("My dynamic test", () -> System.out.println("Inside dynamic test"))); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/test/java/com/epam/reportportal/junit5/features/description/DescriptionAnnotatedMethodTest.java: -------------------------------------------------------------------------------- 1 | package com.epam.reportportal.junit5.features.description; 2 | 3 | import com.epam.reportportal.annotations.Description; 4 | import com.epam.reportportal.junit5.DescriptionTest; 5 | import org.junit.jupiter.api.Test; 6 | import org.junit.jupiter.api.extension.ExtendWith; 7 | 8 | @ExtendWith(DescriptionTest.TestExtension.class) 9 | public class DescriptionAnnotatedMethodTest { 10 | public static final String TEST_DESCRIPTION_METHOD = "My test description on the method"; 11 | @Test 12 | @Description(TEST_DESCRIPTION_METHOD) 13 | public void testDescriptionTest() { 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /src/test/java/com/epam/reportportal/junit5/features/disabled/OneDisabledOneEnabledTest.java: -------------------------------------------------------------------------------- 1 | package com.epam.reportportal.junit5.features.disabled; 2 | 3 | import com.epam.reportportal.junit5.DisabledTestTest; 4 | import org.junit.jupiter.api.Disabled; 5 | import org.junit.jupiter.api.DisplayName; 6 | import org.junit.jupiter.api.Test; 7 | import org.junit.jupiter.api.extension.ExtendWith; 8 | 9 | @ExtendWith(DisabledTestTest.DisabledTestExtension.class) 10 | public class OneDisabledOneEnabledTest { 11 | 12 | public static final String DISPLAY_NAME = "My enabled display name"; 13 | 14 | // JUnit 5 executes test in alphabetical order, so names matters 15 | @Disabled 16 | @Test 17 | void testADisabledTest() { 18 | System.out.println("disabled"); 19 | } 20 | 21 | @Test 22 | @DisplayName(DISPLAY_NAME) 23 | void testBEnabledTest() { 24 | System.out.println("enabled"); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/test/java/com/epam/reportportal/junit5/features/disabled/OneDisabledTest.java: -------------------------------------------------------------------------------- 1 | package com.epam.reportportal.junit5.features.disabled; 2 | 3 | import com.epam.reportportal.junit5.DisabledTestTest; 4 | import org.junit.jupiter.api.Disabled; 5 | import org.junit.jupiter.api.Test; 6 | import org.junit.jupiter.api.extension.ExtendWith; 7 | 8 | @ExtendWith(DisabledTestTest.DisabledTestExtension.class) 9 | public class OneDisabledTest { 10 | 11 | @Disabled 12 | @Test 13 | void disabledTest() { 14 | System.out.println("disabled"); 15 | } 16 | 17 | } 18 | -------------------------------------------------------------------------------- /src/test/java/com/epam/reportportal/junit5/features/disabled/OneDisabledWithReasonDescriptionTest.java: -------------------------------------------------------------------------------- 1 | package com.epam.reportportal.junit5.features.disabled; 2 | 3 | import com.epam.reportportal.annotations.Description; 4 | import com.epam.reportportal.junit5.DisabledTestTest; 5 | import org.junit.jupiter.api.Disabled; 6 | import org.junit.jupiter.api.Test; 7 | import org.junit.jupiter.api.extension.ExtendWith; 8 | 9 | @ExtendWith(DisabledTestTest.DisabledTestExtension.class) 10 | public class OneDisabledWithReasonDescriptionTest { 11 | public static final String TEST_DESCRIPTION_METHOD = "My test description on the method"; 12 | public static final String REASON = "My reason to disable test"; 13 | 14 | @Disabled(REASON) 15 | @Description(TEST_DESCRIPTION_METHOD) 16 | @Test 17 | void disabledTest() { 18 | System.out.println("disabled"); 19 | } 20 | 21 | } 22 | -------------------------------------------------------------------------------- /src/test/java/com/epam/reportportal/junit5/features/disabled/OneDisabledWithReasonTest.java: -------------------------------------------------------------------------------- 1 | package com.epam.reportportal.junit5.features.disabled; 2 | 3 | import com.epam.reportportal.junit5.DisabledTestTest; 4 | import org.junit.jupiter.api.Disabled; 5 | import org.junit.jupiter.api.Test; 6 | import org.junit.jupiter.api.extension.ExtendWith; 7 | 8 | @ExtendWith(DisabledTestTest.DisabledTestExtension.class) 9 | public class OneDisabledWithReasonTest { 10 | 11 | public static final String REASON = "My reason to disable test"; 12 | 13 | @Disabled(REASON) 14 | @Test 15 | void disabledTest() { 16 | System.out.println("disabled"); 17 | } 18 | 19 | } 20 | -------------------------------------------------------------------------------- /src/test/java/com/epam/reportportal/junit5/features/displayname/DisplayNameAnnotatedClassDynamicTest.java: -------------------------------------------------------------------------------- 1 | package com.epam.reportportal.junit5.features.displayname; 2 | 3 | import com.epam.reportportal.annotations.DisplayName; 4 | import com.epam.reportportal.junit5.DisplayNameTest; 5 | import org.junit.jupiter.api.DynamicTest; 6 | import org.junit.jupiter.api.TestFactory; 7 | import org.junit.jupiter.api.extension.ExtendWith; 8 | 9 | import java.util.stream.Stream; 10 | 11 | import static org.junit.jupiter.api.DynamicTest.dynamicTest; 12 | 13 | @ExtendWith(DisplayNameTest.TestExtension.class) 14 | @DisplayName(DisplayNameAnnotatedClassDynamicTest.TEST_DISPLAY_NAME_DYNAMIC_CLASS) 15 | public class DisplayNameAnnotatedClassDynamicTest { 16 | public static final String TEST_DISPLAY_NAME_DYNAMIC_CLASS = "My test displayName on the dynamic class"; 17 | @TestFactory 18 | Stream testForTestFactory() { 19 | return Stream.of(dynamicTest("My dynamic test", () -> System.out.println("Inside dynamic test"))); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/test/java/com/epam/reportportal/junit5/features/displayname/DisplayNameAnnotatedClassTest.java: -------------------------------------------------------------------------------- 1 | package com.epam.reportportal.junit5.features.displayname; 2 | 3 | import com.epam.reportportal.junit5.DisplayNameTest; 4 | import org.junit.jupiter.api.Test; 5 | import org.junit.jupiter.api.extension.ExtendWith; 6 | 7 | @com.epam.reportportal.annotations.DisplayName(DisplayNameAnnotatedClassTest.TEST_DISPLAY_NAME_CLASS) 8 | @ExtendWith(DisplayNameTest.TestExtension.class) 9 | public class DisplayNameAnnotatedClassTest { 10 | public static final String TEST_DISPLAY_NAME_CLASS = "My display name"; 11 | @Test 12 | public void testDisplayNameTest() { 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /src/test/java/com/epam/reportportal/junit5/features/displayname/DisplayNameAnnotatedClassWithEmptyValueTest.java: -------------------------------------------------------------------------------- 1 | package com.epam.reportportal.junit5.features.displayname; 2 | 3 | import com.epam.reportportal.junit5.DisplayNameTest; 4 | import org.junit.jupiter.api.Test; 5 | import org.junit.jupiter.api.extension.ExtendWith; 6 | 7 | @com.epam.reportportal.annotations.DisplayName(DisplayNameAnnotatedClassWithEmptyValueTest.TEST_DISPLAY_NAME_CLASS) 8 | @ExtendWith(DisplayNameTest.TestExtension.class) 9 | public class DisplayNameAnnotatedClassWithEmptyValueTest { 10 | public static final String TEST_DISPLAY_NAME_CLASS = ""; 11 | @Test 12 | public void testDisplayNameTest() { 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /src/test/java/com/epam/reportportal/junit5/features/displayname/DisplayNameAnnotatedMethodAndClassDynamicTest.java: -------------------------------------------------------------------------------- 1 | package com.epam.reportportal.junit5.features.displayname; 2 | 3 | import com.epam.reportportal.annotations.DisplayName; 4 | import com.epam.reportportal.junit5.DisplayNameTest; 5 | import org.junit.jupiter.api.DynamicTest; 6 | import org.junit.jupiter.api.TestFactory; 7 | import org.junit.jupiter.api.extension.ExtendWith; 8 | 9 | import java.util.stream.Stream; 10 | 11 | import static org.junit.jupiter.api.DynamicTest.dynamicTest; 12 | 13 | @ExtendWith(DisplayNameTest.TestExtension.class) 14 | @DisplayName(DisplayNameAnnotatedClassDynamicTest.TEST_DISPLAY_NAME_DYNAMIC_CLASS) 15 | public class DisplayNameAnnotatedMethodAndClassDynamicTest { 16 | @TestFactory 17 | @DisplayName(DisplayNameAnnotatedMethodDynamicTest.TEST_DISPLAY_NAME_DYNAMIC_METHOD) 18 | Stream testForTestFactory() { 19 | return Stream.of(dynamicTest("My dynamic test", () -> System.out.println("Inside dynamic test"))); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/test/java/com/epam/reportportal/junit5/features/displayname/DisplayNameAnnotatedMethodAndClassTest.java: -------------------------------------------------------------------------------- 1 | package com.epam.reportportal.junit5.features.displayname; 2 | 3 | import com.epam.reportportal.annotations.DisplayName; 4 | import com.epam.reportportal.junit5.DisplayNameTest; 5 | import org.junit.jupiter.api.Test; 6 | import org.junit.jupiter.api.extension.ExtendWith; 7 | 8 | @ExtendWith(DisplayNameTest.TestExtension.class) 9 | @DisplayName(DisplayNameAnnotatedClassTest.TEST_DISPLAY_NAME_CLASS) 10 | public class DisplayNameAnnotatedMethodAndClassTest { 11 | @Test 12 | @DisplayName(DisplayNameAnnotatedMethodTest.TEST_DISPLAY_NAME_METHOD) 13 | public void testDisplayNameTest() { 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /src/test/java/com/epam/reportportal/junit5/features/displayname/DisplayNameAnnotatedMethodDynamicTest.java: -------------------------------------------------------------------------------- 1 | package com.epam.reportportal.junit5.features.displayname; 2 | 3 | import com.epam.reportportal.annotations.DisplayName; 4 | import com.epam.reportportal.junit5.DisplayNameTest; 5 | import org.junit.jupiter.api.DynamicTest; 6 | import org.junit.jupiter.api.TestFactory; 7 | import org.junit.jupiter.api.extension.ExtendWith; 8 | 9 | import java.util.stream.Stream; 10 | 11 | import static org.junit.jupiter.api.DynamicTest.dynamicTest; 12 | 13 | @ExtendWith(DisplayNameTest.TestExtension.class) 14 | public class DisplayNameAnnotatedMethodDynamicTest { 15 | public static final String TEST_DISPLAY_NAME_DYNAMIC_METHOD = "My test displayName on the dynamic method"; 16 | @TestFactory 17 | @DisplayName(TEST_DISPLAY_NAME_DYNAMIC_METHOD) 18 | Stream testForTestFactory() { 19 | return Stream.of(dynamicTest("My dynamic test", () -> System.out.println("Inside dynamic test"))); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/test/java/com/epam/reportportal/junit5/features/displayname/DisplayNameAnnotatedMethodTest.java: -------------------------------------------------------------------------------- 1 | package com.epam.reportportal.junit5.features.displayname; 2 | 3 | import com.epam.reportportal.annotations.DisplayName; 4 | import com.epam.reportportal.junit5.DisplayNameTest; 5 | import org.junit.jupiter.api.Test; 6 | import org.junit.jupiter.api.extension.ExtendWith; 7 | 8 | @ExtendWith(DisplayNameTest.TestExtension.class) 9 | public class DisplayNameAnnotatedMethodTest { 10 | public static final String TEST_DISPLAY_NAME_METHOD = "My test displayName on the method"; 11 | @Test 12 | @DisplayName(TEST_DISPLAY_NAME_METHOD) 13 | public void testDisplayNameTest() { 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /src/test/java/com/epam/reportportal/junit5/features/displayname/DisplayNameAnnotatedMethodWithEmptyValueTest.java: -------------------------------------------------------------------------------- 1 | package com.epam.reportportal.junit5.features.displayname; 2 | 3 | import com.epam.reportportal.annotations.DisplayName; 4 | import com.epam.reportportal.junit5.DisplayNameTest; 5 | import org.junit.jupiter.api.Test; 6 | import org.junit.jupiter.api.extension.ExtendWith; 7 | 8 | @ExtendWith(DisplayNameTest.TestExtension.class) 9 | public class DisplayNameAnnotatedMethodWithEmptyValueTest { 10 | public static final String TEST_DISPLAY_NAME_METHOD = ""; 11 | @Test 12 | @DisplayName(TEST_DISPLAY_NAME_METHOD) 13 | public void testDisplayNameTest() { 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /src/test/java/com/epam/reportportal/junit5/features/displayname/DisplayNameBothJunitAndRPAnnotatedClassDynamicTest.java: -------------------------------------------------------------------------------- 1 | package com.epam.reportportal.junit5.features.displayname; 2 | 3 | import com.epam.reportportal.annotations.DisplayName; 4 | import com.epam.reportportal.junit5.DisplayNameTest; 5 | import org.junit.jupiter.api.DynamicTest; 6 | import org.junit.jupiter.api.TestFactory; 7 | import org.junit.jupiter.api.extension.ExtendWith; 8 | 9 | import java.util.stream.Stream; 10 | 11 | import static org.junit.jupiter.api.DynamicTest.dynamicTest; 12 | 13 | @ExtendWith(DisplayNameTest.TestExtension.class) 14 | @DisplayName(DisplayNameBothJunitAndRPAnnotatedClassDynamicTest.TEST_DISPLAY_NAME_DYNAMIC_CLASS) 15 | @org.junit.jupiter.api.DisplayName("Junit") 16 | public class DisplayNameBothJunitAndRPAnnotatedClassDynamicTest { 17 | public static final String TEST_DISPLAY_NAME_DYNAMIC_CLASS = "My test displayName on the dynamic class"; 18 | @TestFactory 19 | Stream testForTestFactory() { 20 | return Stream.of(dynamicTest("My dynamic test", () -> System.out.println("Inside dynamic test"))); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/test/java/com/epam/reportportal/junit5/features/displayname/DisplayNameBothJunitAndRPAnnotatedClassTest.java: -------------------------------------------------------------------------------- 1 | package com.epam.reportportal.junit5.features.displayname; 2 | 3 | import com.epam.reportportal.junit5.DisplayNameTest; 4 | import org.junit.jupiter.api.DisplayName; 5 | import org.junit.jupiter.api.Test; 6 | import org.junit.jupiter.api.extension.ExtendWith; 7 | 8 | @com.epam.reportportal.annotations.DisplayName(DisplayNameBothJunitAndRPAnnotatedClassTest.TEST_DISPLAY_NAME_CLASS) 9 | @ExtendWith(DisplayNameTest.TestExtension.class) 10 | @DisplayName("Junit") 11 | public class DisplayNameBothJunitAndRPAnnotatedClassTest { 12 | public static final String TEST_DISPLAY_NAME_CLASS = "My display name"; 13 | @Test 14 | public void testDisplayNameTest() { 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /src/test/java/com/epam/reportportal/junit5/features/displayname/DisplayNameBothJunitAndRPAnnotatedMethodAndClassDynamicTest.java: -------------------------------------------------------------------------------- 1 | package com.epam.reportportal.junit5.features.displayname; 2 | 3 | import com.epam.reportportal.annotations.DisplayName; 4 | import com.epam.reportportal.junit5.DisplayNameTest; 5 | import org.junit.jupiter.api.DynamicTest; 6 | import org.junit.jupiter.api.TestFactory; 7 | import org.junit.jupiter.api.extension.ExtendWith; 8 | 9 | import java.util.stream.Stream; 10 | 11 | import static org.junit.jupiter.api.DynamicTest.dynamicTest; 12 | 13 | @ExtendWith(DisplayNameTest.TestExtension.class) 14 | @DisplayName(DisplayNameAnnotatedClassDynamicTest.TEST_DISPLAY_NAME_DYNAMIC_CLASS) 15 | @org.junit.jupiter.api.DisplayName("Junit class") 16 | public class DisplayNameBothJunitAndRPAnnotatedMethodAndClassDynamicTest { 17 | @TestFactory 18 | @DisplayName(DisplayNameAnnotatedMethodDynamicTest.TEST_DISPLAY_NAME_DYNAMIC_METHOD) 19 | @org.junit.jupiter.api.DisplayName("Junit method") 20 | Stream testForTestFactory() { 21 | return Stream.of(dynamicTest("My dynamic test", () -> System.out.println("Inside dynamic test"))); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/test/java/com/epam/reportportal/junit5/features/displayname/DisplayNameBothJunitAndRPAnnotatedMethodAndClassTest.java: -------------------------------------------------------------------------------- 1 | package com.epam.reportportal.junit5.features.displayname; 2 | 3 | import com.epam.reportportal.annotations.DisplayName; 4 | import com.epam.reportportal.junit5.DisplayNameTest; 5 | import org.junit.jupiter.api.Test; 6 | import org.junit.jupiter.api.extension.ExtendWith; 7 | 8 | @ExtendWith(DisplayNameTest.TestExtension.class) 9 | @DisplayName(DisplayNameAnnotatedClassTest.TEST_DISPLAY_NAME_CLASS) 10 | @org.junit.jupiter.api.DisplayName("Junit class") 11 | public class DisplayNameBothJunitAndRPAnnotatedMethodAndClassTest { 12 | @Test 13 | @DisplayName(DisplayNameAnnotatedMethodTest.TEST_DISPLAY_NAME_METHOD) 14 | @org.junit.jupiter.api.DisplayName("Junit method") 15 | public void testDisplayNameTest() { 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /src/test/java/com/epam/reportportal/junit5/features/displayname/DisplayNameBothJunitAndRPAnnotatedMethodDynamicTest.java: -------------------------------------------------------------------------------- 1 | package com.epam.reportportal.junit5.features.displayname; 2 | 3 | import com.epam.reportportal.annotations.DisplayName; 4 | import com.epam.reportportal.junit5.DisplayNameTest; 5 | import org.junit.jupiter.api.DynamicTest; 6 | import org.junit.jupiter.api.TestFactory; 7 | import org.junit.jupiter.api.extension.ExtendWith; 8 | 9 | import java.util.stream.Stream; 10 | 11 | import static org.junit.jupiter.api.DynamicTest.dynamicTest; 12 | 13 | @ExtendWith(DisplayNameTest.TestExtension.class) 14 | public class DisplayNameBothJunitAndRPAnnotatedMethodDynamicTest { 15 | public static final String TEST_DISPLAY_NAME_DYNAMIC_METHOD = "My test displayName on the dynamic method"; 16 | @TestFactory 17 | @DisplayName(TEST_DISPLAY_NAME_DYNAMIC_METHOD) 18 | @org.junit.jupiter.api.DisplayName("Junit") 19 | Stream testForTestFactory() { 20 | return Stream.of(dynamicTest("My dynamic test", () -> System.out.println("Inside dynamic test"))); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/test/java/com/epam/reportportal/junit5/features/displayname/DisplayNameBothJunitAndRPAnnotatedMethodTest.java: -------------------------------------------------------------------------------- 1 | package com.epam.reportportal.junit5.features.displayname; 2 | 3 | import com.epam.reportportal.annotations.DisplayName; 4 | import com.epam.reportportal.junit5.DisplayNameTest; 5 | import org.junit.jupiter.api.Test; 6 | import org.junit.jupiter.api.extension.ExtendWith; 7 | 8 | @ExtendWith(DisplayNameTest.TestExtension.class) 9 | public class DisplayNameBothJunitAndRPAnnotatedMethodTest { 10 | public static final String TEST_DISPLAY_NAME_METHOD = "My test displayName on the method"; 11 | @Test 12 | @DisplayName(TEST_DISPLAY_NAME_METHOD) 13 | @org.junit.jupiter.api.DisplayName("Junit") 14 | public void testDisplayNameTest() { 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /src/test/java/com/epam/reportportal/junit5/features/issue/DynamicIssueTest.java: -------------------------------------------------------------------------------- 1 | package com.epam.reportportal.junit5.features.issue; 2 | 3 | import com.epam.reportportal.annotations.Issue; 4 | import com.epam.reportportal.junit5.IssueReportingTest; 5 | import org.junit.jupiter.api.DynamicTest; 6 | import org.junit.jupiter.api.TestFactory; 7 | import org.junit.jupiter.api.extension.ExtendWith; 8 | 9 | import java.util.stream.Stream; 10 | 11 | import static org.junit.jupiter.api.DynamicTest.dynamicTest; 12 | 13 | @ExtendWith(IssueReportingTest.TestExtension.class) 14 | public class DynamicIssueTest { 15 | public static final String FAILURE_MESSAGE = "This test is expected to fail"; 16 | 17 | @TestFactory 18 | @Issue(value = "ab001", comment = FAILURE_MESSAGE) 19 | Stream testForTestFactory() { 20 | return Stream.of(dynamicTest("My dynamic test", () -> { 21 | throw new IllegalStateException(FAILURE_MESSAGE); 22 | })); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/test/java/com/epam/reportportal/junit5/features/issue/ParameterizedWithOneIssueTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2024 EPAM Systems 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 | * https://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 com.epam.reportportal.junit5.features.issue; 18 | 19 | import com.epam.reportportal.annotations.Issue; 20 | import com.epam.reportportal.annotations.TestFilter; 21 | import com.epam.reportportal.annotations.TestParamFilter; 22 | import com.epam.reportportal.junit5.IssueReportingTest; 23 | import org.junit.jupiter.api.extension.ExtendWith; 24 | import org.junit.jupiter.params.ParameterizedTest; 25 | import org.junit.jupiter.params.provider.ValueSource; 26 | 27 | @ExtendWith(IssueReportingTest.TestExtension.class) 28 | public class ParameterizedWithOneIssueTest { 29 | 30 | public static final String FAILURE_MESSAGE = "This parameterized test is expected to fail: "; 31 | public static final String ISSUE_MESSAGE = "This test is expected to fail"; 32 | 33 | @ParameterizedTest 34 | @ValueSource(booleans = { true, false }) 35 | @Issue(value = "ab001", comment = ISSUE_MESSAGE, filter = @TestFilter(param = { @TestParamFilter(valueStartsWith = "false") })) 36 | public void failureTest(boolean param) { 37 | throw new IllegalStateException(FAILURE_MESSAGE + param); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/test/java/com/epam/reportportal/junit5/features/issue/ParameterizedWithTwoIssueTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2024 EPAM Systems 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 | * https://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 com.epam.reportportal.junit5.features.issue; 18 | 19 | import com.epam.reportportal.annotations.Issue; 20 | import com.epam.reportportal.annotations.TestFilter; 21 | import com.epam.reportportal.annotations.TestParamFilter; 22 | import com.epam.reportportal.junit5.IssueReportingTest; 23 | import org.junit.jupiter.api.extension.ExtendWith; 24 | import org.junit.jupiter.params.ParameterizedTest; 25 | import org.junit.jupiter.params.provider.ValueSource; 26 | 27 | @ExtendWith(IssueReportingTest.TestExtension.class) 28 | public class ParameterizedWithTwoIssueTest { 29 | 30 | public static final String FAILURE_MESSAGE = "This parameterized test is expected to fail: "; 31 | public static final String ISSUE_MESSAGE = "This test is expected to fail"; 32 | 33 | @ParameterizedTest 34 | @ValueSource(booleans = { true, false }) 35 | @Issue(value = "ab001", comment = ISSUE_MESSAGE, filter = @TestFilter(param = { @TestParamFilter(valueStartsWith = "true") })) 36 | @Issue(value = "pb001", comment = ISSUE_MESSAGE, filter = @TestFilter(param = { @TestParamFilter(valueStartsWith = "false") })) 37 | public void failureTest(boolean param) { 38 | throw new IllegalStateException(FAILURE_MESSAGE + param); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/test/java/com/epam/reportportal/junit5/features/issue/SimpleIssueTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2024 EPAM Systems 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 | * https://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 com.epam.reportportal.junit5.features.issue; 18 | 19 | import com.epam.reportportal.annotations.Issue; 20 | import com.epam.reportportal.junit5.IssueReportingTest; 21 | import org.junit.jupiter.api.Test; 22 | import org.junit.jupiter.api.extension.ExtendWith; 23 | 24 | @ExtendWith(IssueReportingTest.TestExtension.class) 25 | public class SimpleIssueTest { 26 | 27 | public static final String FAILURE_MESSAGE = "This test is expected to fail"; 28 | 29 | @Test 30 | @Issue(value = "pb001", comment = FAILURE_MESSAGE) 31 | public void failureTest() { 32 | throw new IllegalStateException(FAILURE_MESSAGE); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/test/java/com/epam/reportportal/junit5/features/issue/SimpleSkippedIssueTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2024 EPAM Systems 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 | * https://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 com.epam.reportportal.junit5.features.issue; 18 | 19 | import com.epam.reportportal.annotations.Issue; 20 | import com.epam.reportportal.junit5.IssueReportingTest; 21 | import org.junit.jupiter.api.Disabled; 22 | import org.junit.jupiter.api.Test; 23 | import org.junit.jupiter.api.extension.ExtendWith; 24 | 25 | @ExtendWith(IssueReportingTest.TestExtension.class) 26 | public class SimpleSkippedIssueTest { 27 | 28 | public static final String FAILURE_MESSAGE = "This test is expected to fail"; 29 | 30 | @Test 31 | @Issue(value = "pb001", comment = FAILURE_MESSAGE) 32 | @Disabled 33 | public void failureTest() { 34 | throw new IllegalStateException(FAILURE_MESSAGE); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/test/java/com/epam/reportportal/junit5/features/issue/SimpleTwoIssuesTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2024 EPAM Systems 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 | * https://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 com.epam.reportportal.junit5.features.issue; 18 | 19 | import com.epam.reportportal.annotations.Issue; 20 | import com.epam.reportportal.junit5.IssueReportingTest; 21 | import org.junit.jupiter.api.Test; 22 | import org.junit.jupiter.api.extension.ExtendWith; 23 | 24 | @ExtendWith(IssueReportingTest.TestExtension.class) 25 | public class SimpleTwoIssuesTest { 26 | 27 | public static final String FAILURE_MESSAGE = "This test is expected to fail"; 28 | 29 | @Test 30 | @Issue(value = "ab001", comment = FAILURE_MESSAGE) 31 | @Issue(value = "pb001", comment = FAILURE_MESSAGE) 32 | public void failureTest() { 33 | throw new IllegalStateException(FAILURE_MESSAGE); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/test/java/com/epam/reportportal/junit5/features/issue/TwoDynamicIssueTest.java: -------------------------------------------------------------------------------- 1 | package com.epam.reportportal.junit5.features.issue; 2 | 3 | import com.epam.reportportal.annotations.Issue; 4 | import com.epam.reportportal.junit5.IssueReportingTest; 5 | import org.junit.jupiter.api.DynamicTest; 6 | import org.junit.jupiter.api.TestFactory; 7 | import org.junit.jupiter.api.extension.ExtendWith; 8 | 9 | import java.util.stream.Stream; 10 | 11 | import static org.junit.jupiter.api.DynamicTest.dynamicTest; 12 | 13 | @ExtendWith(IssueReportingTest.TestExtension.class) 14 | public class TwoDynamicIssueTest { 15 | public static final String FAILURE_MESSAGE = "This test is expected to fail"; 16 | 17 | @TestFactory 18 | @Issue(value = "ab001", comment = FAILURE_MESSAGE) 19 | Stream testForTestFactory() { 20 | return Stream.of(dynamicTest("My dynamic test", () -> { 21 | throw new IllegalStateException(FAILURE_MESSAGE); 22 | }), dynamicTest("My dynamic test 2", () -> { 23 | throw new IllegalStateException(FAILURE_MESSAGE); 24 | })); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/test/java/com/epam/reportportal/junit5/features/issue/TwoDynamicTwoIssueTest.java: -------------------------------------------------------------------------------- 1 | package com.epam.reportportal.junit5.features.issue; 2 | 3 | import com.epam.reportportal.annotations.Issue; 4 | import com.epam.reportportal.annotations.TestFilter; 5 | import com.epam.reportportal.annotations.TestNameFilter; 6 | import com.epam.reportportal.junit5.IssueReportingTest; 7 | import org.junit.jupiter.api.DynamicTest; 8 | import org.junit.jupiter.api.TestFactory; 9 | import org.junit.jupiter.api.extension.ExtendWith; 10 | 11 | import java.util.stream.Stream; 12 | 13 | import static org.junit.jupiter.api.DynamicTest.dynamicTest; 14 | 15 | @ExtendWith(IssueReportingTest.TestExtension.class) 16 | public class TwoDynamicTwoIssueTest { 17 | public static final String FAILURE_MESSAGE = "This test is expected to fail"; 18 | 19 | @TestFactory 20 | @Issue(value = "ab001", comment = FAILURE_MESSAGE, filter = { @TestFilter(name = @TestNameFilter(endsWith = "test")) }) 21 | @Issue(value = "pb001", comment = FAILURE_MESSAGE, filter = { @TestFilter(name = @TestNameFilter(contains = "test 2")) }) 22 | Stream testForTestFactory() { 23 | return Stream.of(dynamicTest("My dynamic test", () -> { 24 | throw new IllegalStateException(FAILURE_MESSAGE); 25 | }), dynamicTest("My dynamic test 2", () -> { 26 | throw new IllegalStateException(FAILURE_MESSAGE); 27 | })); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/test/java/com/epam/reportportal/junit5/features/lasterrorlog/ErrorLastLogFeatureWithAssertionErrorTest.java: -------------------------------------------------------------------------------- 1 | package com.epam.reportportal.junit5.features.lasterrorlog; 2 | 3 | import com.epam.reportportal.annotations.Description; 4 | import com.epam.reportportal.junit5.ErrorLastLogTest; 5 | import org.junit.jupiter.api.Assertions; 6 | import org.junit.jupiter.api.Test; 7 | import org.junit.jupiter.api.extension.ExtendWith; 8 | 9 | 10 | @ExtendWith(ErrorLastLogTest.ErrorDescriptionTestExtension.class) 11 | public class ErrorLastLogFeatureWithAssertionErrorTest { 12 | 13 | @Test 14 | @Description("0 and 1 is not equal") 15 | public void testWithAssertException() { 16 | Assertions.assertEquals(0, 1); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/test/java/com/epam/reportportal/junit5/features/lasterrorlog/ErrorLastLogFeatureWithAssertionPassedTest.java: -------------------------------------------------------------------------------- 1 | package com.epam.reportportal.junit5.features.lasterrorlog; 2 | 3 | import com.epam.reportportal.annotations.Description; 4 | import com.epam.reportportal.annotations.Step; 5 | import com.epam.reportportal.junit5.ErrorLastLogTest; 6 | import org.junit.jupiter.api.Assertions; 7 | import org.junit.jupiter.api.Test; 8 | import org.junit.jupiter.api.extension.ExtendWith; 9 | 10 | @ExtendWith(ErrorLastLogTest.ErrorDescriptionTestExtension.class) 11 | public class ErrorLastLogFeatureWithAssertionPassedTest { 12 | 13 | @Test 14 | @Description("successful test") 15 | public void testWithDescriptionAndPassed() { 16 | login(); 17 | Assertions.assertTrue(true); 18 | } 19 | 20 | @Step 21 | public void login() { 22 | System.out.println("Login successful"); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/test/java/com/epam/reportportal/junit5/features/lasterrorlog/ErrorLastLogFeatureWithExceptionTest.java: -------------------------------------------------------------------------------- 1 | package com.epam.reportportal.junit5.features.lasterrorlog; 2 | 3 | import com.epam.reportportal.junit5.ErrorLastLogTest; 4 | import org.junit.jupiter.api.Test; 5 | import org.junit.jupiter.api.extension.ExtendWith; 6 | 7 | @ExtendWith(ErrorLastLogTest.ErrorDescriptionTestExtension.class) 8 | public class ErrorLastLogFeatureWithExceptionTest { 9 | 10 | 11 | @Test 12 | public void testWithException() { 13 | throw new RuntimeException("Critical error"); 14 | } 15 | 16 | 17 | } 18 | -------------------------------------------------------------------------------- /src/test/java/com/epam/reportportal/junit5/features/lasterrorlog/ErrorLastLogFeatureWithStepTest.java: -------------------------------------------------------------------------------- 1 | package com.epam.reportportal.junit5.features.lasterrorlog; 2 | 3 | import com.epam.reportportal.annotations.Description; 4 | import com.epam.reportportal.annotations.Step; 5 | import com.epam.reportportal.junit5.ErrorLastLogTest; 6 | import org.junit.jupiter.api.Assertions; 7 | import org.junit.jupiter.api.Test; 8 | import org.junit.jupiter.api.extension.ExtendWith; 9 | 10 | import java.util.NoSuchElementException; 11 | 12 | @ExtendWith(ErrorLastLogTest.ErrorDescriptionTestExtension.class) 13 | public class ErrorLastLogFeatureWithStepTest { 14 | 15 | @Test 16 | @Description("Login issue") 17 | public void testWithStepError() { 18 | enterCredentials(); 19 | System.out.println("Username is not correct"); 20 | loginWithException(); 21 | Assertions.assertTrue(Boolean.TRUE); 22 | } 23 | 24 | @Step 25 | @Description("Credentials entered") 26 | public void enterCredentials() { 27 | Assertions.assertTrue(Boolean.TRUE); 28 | } 29 | @Step 30 | public void loginWithException() { 31 | throw new NoSuchElementException("Error message"); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/test/java/com/epam/reportportal/junit5/features/nested/JunitClassNestedTests.java: -------------------------------------------------------------------------------- 1 | package com.epam.reportportal.junit5.features.nested; 2 | 3 | import com.epam.reportportal.junit5.JunitNestedTestTest; 4 | import org.junit.jupiter.api.Assertions; 5 | import org.junit.jupiter.api.Nested; 6 | import org.junit.jupiter.api.Test; 7 | import org.junit.jupiter.api.extension.ExtendWith; 8 | import org.slf4j.Logger; 9 | import org.slf4j.LoggerFactory; 10 | 11 | @ExtendWith(JunitNestedTestTest.TestExtension.class) 12 | public class JunitClassNestedTests { 13 | private static final Logger LOGGER = LoggerFactory.getLogger(JunitClassNestedTests.class); 14 | 15 | @Nested 16 | class Outer { 17 | @Nested 18 | class Inner { 19 | @Test 20 | void aTest() { 21 | LOGGER.info("executing aTest"); 22 | Assertions.assertEquals(1, 1); 23 | } 24 | 25 | @Test 26 | void anotherTest() { 27 | LOGGER.info("executing anotherTest"); 28 | Assertions.assertEquals(1, 1); 29 | } 30 | } 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/test/java/com/epam/reportportal/junit5/features/nested/JunitClassNestedTestsLongDepth.java: -------------------------------------------------------------------------------- 1 | package com.epam.reportportal.junit5.features.nested; 2 | 3 | import com.epam.reportportal.junit5.JunitNestedTestTest; 4 | import org.junit.jupiter.api.Assertions; 5 | import org.junit.jupiter.api.Nested; 6 | import org.junit.jupiter.api.Test; 7 | import org.junit.jupiter.api.extension.ExtendWith; 8 | import org.slf4j.Logger; 9 | import org.slf4j.LoggerFactory; 10 | 11 | @ExtendWith(JunitNestedTestTest.TestExtension.class) 12 | public class JunitClassNestedTestsLongDepth { 13 | private static final Logger LOGGER = LoggerFactory.getLogger(JunitClassNestedTests.class); 14 | 15 | @Nested 16 | class Outer { 17 | @Nested 18 | class Inner { 19 | @Nested 20 | class TestOuter { 21 | @Nested 22 | class TestInner { 23 | @Test 24 | void aTest() { 25 | LOGGER.info("executing aTest"); 26 | Assertions.assertEquals(1, 1); 27 | } 28 | } 29 | } 30 | 31 | @Test 32 | void bTest() { 33 | LOGGER.info("executing bTest"); 34 | Assertions.assertEquals(1, 1); 35 | } 36 | } 37 | } 38 | 39 | @Nested 40 | class SecondOuter { 41 | @Nested 42 | class SecondInner { 43 | @Nested 44 | class SecondTestOuter { 45 | @Nested 46 | class SecondTestInner { 47 | @Test 48 | void cTest() { 49 | LOGGER.info("executing cTest"); 50 | Assertions.assertEquals(1, 1); 51 | } 52 | } 53 | } 54 | } 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /src/test/java/com/epam/reportportal/junit5/features/nested/JunitDynamicNestedTest.java: -------------------------------------------------------------------------------- 1 | package com.epam.reportportal.junit5.features.nested; 2 | 3 | import com.epam.reportportal.junit5.JunitNestedTestTest; 4 | import org.junit.jupiter.api.DynamicContainer; 5 | import org.junit.jupiter.api.DynamicNode; 6 | import org.junit.jupiter.api.DynamicTest; 7 | import org.junit.jupiter.api.TestFactory; 8 | import org.junit.jupiter.api.extension.ExtendWith; 9 | import org.slf4j.Logger; 10 | import org.slf4j.LoggerFactory; 11 | 12 | import java.util.stream.Stream; 13 | 14 | import static org.hamcrest.MatcherAssert.assertThat; 15 | import static org.hamcrest.Matchers.*; 16 | 17 | @ExtendWith(JunitNestedTestTest.TestExtension.class) 18 | public class JunitDynamicNestedTest { 19 | private static final Logger LOGGER = LoggerFactory.getLogger(JunitDynamicNestedTest.class); 20 | 21 | @TestFactory 22 | Stream dynamicTestsWithContainers() { 23 | return Stream.of("A", "B") 24 | .map(input -> DynamicContainer.dynamicContainer(input, 25 | Stream.of(DynamicContainer.dynamicContainer(input + " inner container", 26 | Stream.of(DynamicTest.dynamicTest(input + " Test 1", () -> { 27 | LOGGER.info("Checking length == 1"); 28 | assertThat(input, hasLength(1)); 29 | }), DynamicTest.dynamicTest(input + " Test 2", () -> { 30 | LOGGER.info("Checking not empty"); 31 | assertThat(input, not(emptyOrNullString())); 32 | })) 33 | )) 34 | )); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/test/java/com/epam/reportportal/junit5/features/nested/NestedStepFeatureFailedTest.java: -------------------------------------------------------------------------------- 1 | package com.epam.reportportal.junit5.features.nested; 2 | 3 | import com.epam.reportportal.annotations.Step; 4 | import com.epam.reportportal.junit5.NestedStepTest; 5 | import org.junit.jupiter.api.Test; 6 | import org.junit.jupiter.api.extension.ExtendWith; 7 | 8 | import static com.epam.reportportal.junit5.NestedStepTest.NESTED_STEP_NAME_TEMPLATE; 9 | import static com.epam.reportportal.junit5.NestedStepTest.PARAM; 10 | 11 | /** 12 | * @author Ivan Budayeu 13 | */ 14 | @ExtendWith(NestedStepTest.TestExtension.class) 15 | public class NestedStepFeatureFailedTest { 16 | 17 | @Test 18 | public void test() { 19 | failedMethod(PARAM); 20 | } 21 | 22 | @Step(NESTED_STEP_NAME_TEMPLATE) 23 | public void failedMethod(String param) { 24 | throw new RuntimeException("Some random error"); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/test/java/com/epam/reportportal/junit5/features/nested/NestedStepFeaturePassedTest.java: -------------------------------------------------------------------------------- 1 | package com.epam.reportportal.junit5.features.nested; 2 | 3 | import com.epam.reportportal.annotations.Step; 4 | import com.epam.reportportal.junit5.NestedStepTest; 5 | import org.junit.jupiter.api.Test; 6 | import org.junit.jupiter.api.extension.ExtendWith; 7 | 8 | import static com.epam.reportportal.junit5.NestedStepTest.NESTED_STEP_NAME_TEMPLATE; 9 | import static com.epam.reportportal.junit5.NestedStepTest.PARAM; 10 | 11 | /** 12 | * @author Ivan Budayeu 13 | */ 14 | @ExtendWith(NestedStepTest.TestExtension.class) 15 | public class NestedStepFeaturePassedTest { 16 | @Test 17 | public void test() { 18 | method(PARAM); 19 | } 20 | 21 | @Step(NESTED_STEP_NAME_TEMPLATE) 22 | public void method(String param) { 23 | 24 | } 25 | 26 | } 27 | -------------------------------------------------------------------------------- /src/test/java/com/epam/reportportal/junit5/features/nested/NestedStepMultiLevelTest.java: -------------------------------------------------------------------------------- 1 | package com.epam.reportportal.junit5.features.nested; 2 | 3 | import com.epam.reportportal.annotations.Step; 4 | import com.epam.reportportal.junit5.NestedStepTest; 5 | import org.junit.jupiter.api.Test; 6 | import org.junit.jupiter.api.extension.ExtendWith; 7 | 8 | import static com.epam.reportportal.junit5.NestedStepTest.INNER_METHOD_NAME_TEMPLATE; 9 | import static com.epam.reportportal.junit5.NestedStepTest.METHOD_WITH_INNER_METHOD_NAME_TEMPLATE; 10 | 11 | /** 12 | * @author Ivan Budayeu 13 | */ 14 | @ExtendWith(NestedStepTest.TestExtension.class) 15 | public class NestedStepMultiLevelTest { 16 | 17 | @Test 18 | public void test() { 19 | methodWithInnerMethod(); 20 | } 21 | 22 | @Step(METHOD_WITH_INNER_METHOD_NAME_TEMPLATE) 23 | public void methodWithInnerMethod() { 24 | innerMethod(); 25 | } 26 | 27 | @Step(INNER_METHOD_NAME_TEMPLATE) 28 | public void innerMethod() { 29 | 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/test/java/com/epam/reportportal/junit5/features/nested/NestedStepWithBeforeEachTest.java: -------------------------------------------------------------------------------- 1 | package com.epam.reportportal.junit5.features.nested; 2 | 3 | import com.epam.reportportal.annotations.Step; 4 | import com.epam.reportportal.junit5.NestedStepTest; 5 | import com.epam.reportportal.util.test.CommonUtils; 6 | import org.junit.jupiter.api.BeforeEach; 7 | import org.junit.jupiter.api.Test; 8 | import org.junit.jupiter.api.extension.ExtendWith; 9 | 10 | import static com.epam.reportportal.junit5.NestedStepTest.NESTED_STEP_NAME_TEMPLATE; 11 | import static com.epam.reportportal.junit5.NestedStepTest.PARAM; 12 | 13 | /** 14 | * @author Ivan Budayeu 15 | */ 16 | @ExtendWith(NestedStepTest.TestExtension.class) 17 | public class NestedStepWithBeforeEachTest { 18 | 19 | @BeforeEach 20 | public void before() throws InterruptedException { 21 | method(PARAM); 22 | } 23 | 24 | @Test() 25 | public void test() { 26 | 27 | } 28 | 29 | @Step(NESTED_STEP_NAME_TEMPLATE) 30 | public void method(String param) throws InterruptedException { 31 | Thread.sleep(CommonUtils.MINIMAL_TEST_PAUSE); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/test/java/com/epam/reportportal/junit5/features/parameters/CsvParametersTest.java: -------------------------------------------------------------------------------- 1 | package com.epam.reportportal.junit5.features.parameters; 2 | 3 | import com.epam.reportportal.junit5.ParametersTest; 4 | import org.junit.jupiter.api.extension.ExtendWith; 5 | import org.junit.jupiter.params.ParameterizedTest; 6 | import org.junit.jupiter.params.provider.CsvSource; 7 | 8 | @ExtendWith(ParametersTest.ParameterTestExtension.class) 9 | public class CsvParametersTest { 10 | 11 | @ParameterizedTest 12 | @CsvSource({"one", "two, three"}) 13 | public void testParameters(String param) { 14 | System.out.println("Csv parameter test: " + param); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /src/test/java/com/epam/reportportal/junit5/features/parameters/EnumParametersFailedTest.java: -------------------------------------------------------------------------------- 1 | package com.epam.reportportal.junit5.features.parameters; 2 | 3 | import com.epam.reportportal.junit5.ParametersTest; 4 | import org.junit.jupiter.api.Assertions; 5 | import org.junit.jupiter.api.extension.ExtendWith; 6 | import org.junit.jupiter.params.ParameterizedTest; 7 | import org.junit.jupiter.params.provider.EnumSource; 8 | 9 | @ExtendWith(ParametersTest.ParameterTestExtension.class) 10 | public class EnumParametersFailedTest { 11 | 12 | public enum TestParams { 13 | ONE, 14 | TWO 15 | } 16 | 17 | @ParameterizedTest 18 | @EnumSource(TestParams.class) 19 | public void testParameters(TestParams param) { 20 | System.out.println("Test: " + param.name()); 21 | if (param == TestParams.ONE) { 22 | Assertions.fail("Failure parameter passed: " + param); 23 | } 24 | } 25 | 26 | } 27 | -------------------------------------------------------------------------------- /src/test/java/com/epam/reportportal/junit5/features/parameters/EnumParametersTest.java: -------------------------------------------------------------------------------- 1 | package com.epam.reportportal.junit5.features.parameters; 2 | 3 | import com.epam.reportportal.junit5.ParametersTest; 4 | import org.junit.jupiter.api.extension.ExtendWith; 5 | import org.junit.jupiter.params.ParameterizedTest; 6 | import org.junit.jupiter.params.provider.EnumSource; 7 | 8 | @ExtendWith(ParametersTest.ParameterTestExtension.class) 9 | public class EnumParametersTest { 10 | 11 | public enum TestParams { 12 | ONE, 13 | TWO 14 | } 15 | 16 | @ParameterizedTest 17 | @EnumSource(TestParams.class) 18 | public void testParameters(TestParams param) { 19 | System.out.println("Test: " + param.name()); 20 | } 21 | 22 | } 23 | -------------------------------------------------------------------------------- /src/test/java/com/epam/reportportal/junit5/features/parameters/NullParameterTest.java: -------------------------------------------------------------------------------- 1 | package com.epam.reportportal.junit5.features.parameters; 2 | 3 | import com.epam.reportportal.junit5.ParametersTest; 4 | import org.junit.jupiter.api.extension.ExtendWith; 5 | import org.junit.jupiter.params.ParameterizedTest; 6 | import org.junit.jupiter.params.provider.NullSource; 7 | import org.junit.jupiter.params.provider.ValueSource; 8 | 9 | @ExtendWith(ParametersTest.ParameterTestExtension.class) 10 | public class NullParameterTest { 11 | 12 | @ParameterizedTest 13 | @NullSource 14 | @ValueSource(strings = {"one"}) 15 | public void testParameters(String param) { 16 | System.out.println("Csv parameter test: " + param); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/test/java/com/epam/reportportal/junit5/features/parameters/ParameterNamesNotAllNamedTest.java: -------------------------------------------------------------------------------- 1 | package com.epam.reportportal.junit5.features.parameters; 2 | 3 | import com.epam.reportportal.annotations.ParameterKey; 4 | import com.epam.reportportal.junit5.ParametersTest; 5 | import org.junit.jupiter.api.extension.ExtendWith; 6 | import org.junit.jupiter.params.ParameterizedTest; 7 | import org.junit.jupiter.params.provider.CsvSource; 8 | 9 | @ExtendWith(ParametersTest.ParameterTestExtension.class) 10 | public class ParameterNamesNotAllNamedTest { 11 | public static final String SECOND_PARAMETER_NAME = "second_parameter"; 12 | 13 | @ParameterizedTest 14 | @CsvSource({"1, two", "3, four"}) 15 | public void testTwoParameters(int param1, @ParameterKey(SECOND_PARAMETER_NAME) String param2) { 16 | System.out.println("Two parameters test: " + param1 + " - " + param2); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/test/java/com/epam/reportportal/junit5/features/parameters/ParameterNamesTest.java: -------------------------------------------------------------------------------- 1 | package com.epam.reportportal.junit5.features.parameters; 2 | 3 | import com.epam.reportportal.annotations.ParameterKey; 4 | import com.epam.reportportal.junit5.ParametersTest; 5 | import org.junit.jupiter.api.extension.ExtendWith; 6 | import org.junit.jupiter.params.ParameterizedTest; 7 | import org.junit.jupiter.params.provider.CsvSource; 8 | 9 | @ExtendWith(ParametersTest.ParameterTestExtension.class) 10 | public class ParameterNamesTest { 11 | 12 | public static final String FIRST_PARAMETER_NAME = "first_parameter"; 13 | public static final String SECOND_PARAMETER_NAME = "second_parameter"; 14 | 15 | @ParameterizedTest 16 | @CsvSource({"one, two", "three, four"}) 17 | public void testTwoParameters(@ParameterKey(FIRST_PARAMETER_NAME) String param1, @ParameterKey(SECOND_PARAMETER_NAME) String param2) { 18 | System.out.println("Two parameters test: " + param1 + " - " + param2); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /src/test/java/com/epam/reportportal/junit5/features/parameters/TwoParametersTest.java: -------------------------------------------------------------------------------- 1 | package com.epam.reportportal.junit5.features.parameters; 2 | 3 | import com.epam.reportportal.junit5.ParametersTest; 4 | import org.junit.jupiter.api.extension.ExtendWith; 5 | import org.junit.jupiter.params.ParameterizedTest; 6 | import org.junit.jupiter.params.provider.CsvSource; 7 | 8 | @ExtendWith(ParametersTest.ParameterTestExtension.class) 9 | public class TwoParametersTest { 10 | 11 | @ParameterizedTest 12 | @CsvSource({"one, two", "three, four"}) 13 | public void testTwoParameters(String param1, String param2) { 14 | System.out.println("Two parameters test: " + param1 + " - " + param2); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /src/test/java/com/epam/reportportal/junit5/features/skipped/AfterEachFailedTest.java: -------------------------------------------------------------------------------- 1 | package com.epam.reportportal.junit5.features.skipped; 2 | 3 | import com.epam.reportportal.junit5.miscellaneous.FailedBeforeEachReportsSkippedTestTest; 4 | import org.junit.jupiter.api.AfterEach; 5 | import org.junit.jupiter.api.BeforeEach; 6 | import org.junit.jupiter.api.Test; 7 | import org.junit.jupiter.api.extension.ExtendWith; 8 | 9 | @ExtendWith(FailedBeforeEachReportsSkippedTestTest.SkippedTestExtension.class) 10 | public class AfterEachFailedTest { 11 | 12 | @BeforeEach 13 | public void beforeEachFailed() { 14 | System.out.println("Before each"); 15 | } 16 | 17 | @Test 18 | public void testAfterEachFailed() { 19 | System.out.println("Test: testAfterEachFailed"); 20 | } 21 | 22 | @AfterEach 23 | public void afterEachFailed() { 24 | throw new IllegalStateException("After each"); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/test/java/com/epam/reportportal/junit5/features/skipped/AssertJAssumptionFailedTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 EPAM Systems 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 com.epam.reportportal.junit5.features.skipped; 18 | 19 | import com.epam.reportportal.junit5.AssumptionsTest; 20 | import org.assertj.core.api.Assumptions; 21 | import org.junit.jupiter.api.Test; 22 | import org.junit.jupiter.api.extension.ExtendWith; 23 | 24 | @ExtendWith(AssumptionsTest.AssumptionsTestExtension.class) 25 | public class AssertJAssumptionFailedTest { 26 | 27 | @Test 28 | public void testAssumptionFailed() { 29 | Assumptions.assumeThat(true).isFalse(); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/test/java/com/epam/reportportal/junit5/features/skipped/AssumptionFailedTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 EPAM Systems 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 com.epam.reportportal.junit5.features.skipped; 18 | 19 | import com.epam.reportportal.junit5.AssumptionsTest; 20 | import org.junit.jupiter.api.Assumptions; 21 | import org.junit.jupiter.api.Test; 22 | import org.junit.jupiter.api.extension.ExtendWith; 23 | 24 | @ExtendWith(AssumptionsTest.AssumptionsTestExtension.class) 25 | public class AssumptionFailedTest { 26 | 27 | @Test 28 | public void testAssumptionFailed() { 29 | //noinspection ConstantConditions 30 | Assumptions.assumeFalse(true, "Test failed assumption"); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/test/java/com/epam/reportportal/junit5/features/skipped/BeforeEachAssumptionFailedTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 EPAM Systems 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 com.epam.reportportal.junit5.features.skipped; 18 | 19 | import com.epam.reportportal.junit5.AssumptionsTest; 20 | import org.junit.jupiter.api.Assumptions; 21 | import org.junit.jupiter.api.BeforeEach; 22 | import org.junit.jupiter.api.Test; 23 | import org.junit.jupiter.api.extension.ExtendWith; 24 | 25 | @ExtendWith(AssumptionsTest.AssumptionsTestExtension.class) 26 | public class BeforeEachAssumptionFailedTest { 27 | 28 | @BeforeEach 29 | public void setup() { 30 | //noinspection ConstantConditions 31 | Assumptions.assumeFalse(true, "Test failed assumption"); 32 | } 33 | 34 | @Test 35 | public void testBeforeEachAssumptionFailed() { 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/test/java/com/epam/reportportal/junit5/features/skipped/BeforeEachFailedParametrizedTest.java: -------------------------------------------------------------------------------- 1 | package com.epam.reportportal.junit5.features.skipped; 2 | 3 | import com.epam.reportportal.junit5.miscellaneous.FailedBeforeEachReportsSkippedTestTest; 4 | import org.junit.jupiter.api.BeforeEach; 5 | import org.junit.jupiter.api.extension.ExtendWith; 6 | import org.junit.jupiter.params.ParameterizedTest; 7 | import org.junit.jupiter.params.provider.EnumSource; 8 | 9 | @ExtendWith(FailedBeforeEachReportsSkippedTestTest.SkippedTestExtension.class) 10 | public class BeforeEachFailedParametrizedTest { 11 | 12 | public enum TestParams { 13 | ONE, 14 | TWO 15 | } 16 | 17 | @BeforeEach 18 | public void beforeEachFailed() { 19 | throw new IllegalStateException("Before each"); 20 | } 21 | 22 | @ParameterizedTest 23 | @EnumSource(TestParams.class) 24 | public void testBeforeEachFailed(TestParams param) { 25 | System.out.println("Test: testBeforeEachFailed - " + param.name()); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/test/java/com/epam/reportportal/junit5/features/skipped/BeforeEachFailedTest.java: -------------------------------------------------------------------------------- 1 | package com.epam.reportportal.junit5.features.skipped; 2 | 3 | import com.epam.reportportal.junit5.miscellaneous.FailedBeforeEachReportsSkippedTestTest; 4 | import org.junit.jupiter.api.BeforeEach; 5 | import org.junit.jupiter.api.Test; 6 | import org.junit.jupiter.api.extension.ExtendWith; 7 | 8 | @ExtendWith(FailedBeforeEachReportsSkippedTestTest.SkippedTestExtension.class) 9 | public class BeforeEachFailedTest { 10 | 11 | @BeforeEach 12 | public void beforeEachFailed() { 13 | throw new IllegalStateException("Before each"); 14 | } 15 | 16 | @Test 17 | public void testBeforeEachFailed() { 18 | System.out.println("Test: testBeforeEachFailed"); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /src/test/java/com/epam/reportportal/junit5/features/skipped/BeforeEachFailedWithAfterEach.java: -------------------------------------------------------------------------------- 1 | package com.epam.reportportal.junit5.features.skipped; 2 | 3 | import com.epam.reportportal.junit5.miscellaneous.FailedBeforeEachSkippedTestOrder; 4 | import org.junit.jupiter.api.AfterEach; 5 | import org.junit.jupiter.api.BeforeEach; 6 | import org.junit.jupiter.api.Test; 7 | import org.junit.jupiter.api.extension.ExtendWith; 8 | 9 | @ExtendWith(FailedBeforeEachSkippedTestOrder.SkippedTestExtension.class) 10 | public class BeforeEachFailedWithAfterEach { 11 | @BeforeEach 12 | public void beforeEachFailed() throws InterruptedException { 13 | Thread.sleep(2); 14 | throw new IllegalStateException("Before each"); 15 | } 16 | 17 | @Test 18 | public void testBeforeEachFailed() { 19 | System.out.println("Test: testBeforeEachFailed"); 20 | } 21 | 22 | @AfterEach 23 | public void afterEach() { 24 | System.out.println("After Each"); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/test/java/com/epam/reportportal/junit5/features/skipped/Junit4AssumptionFailedTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 EPAM Systems 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 com.epam.reportportal.junit5.features.skipped; 18 | 19 | import com.epam.reportportal.junit5.AssumptionsTest; 20 | import org.junit.AssumptionViolatedException; 21 | import org.junit.jupiter.api.Test; 22 | import org.junit.jupiter.api.extension.ExtendWith; 23 | 24 | @ExtendWith(AssumptionsTest.AssumptionsTestExtension.class) 25 | public class Junit4AssumptionFailedTest { 26 | 27 | @Test 28 | public void testAssumptionFailed() { 29 | throw new AssumptionViolatedException("Test"); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/test/java/com/epam/reportportal/junit5/features/skipped/Junit4ExtendedAssumptionFailedTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 EPAM Systems 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 com.epam.reportportal.junit5.features.skipped; 18 | 19 | import com.epam.reportportal.junit5.AssumptionsTest; 20 | import org.junit.AssumptionViolatedException; 21 | import org.junit.jupiter.api.Test; 22 | import org.junit.jupiter.api.extension.ExtendWith; 23 | 24 | @ExtendWith(AssumptionsTest.AssumptionsTestExtension.class) 25 | public class Junit4ExtendedAssumptionFailedTest { 26 | 27 | private static class MyAssumptionException extends AssumptionViolatedException { 28 | public MyAssumptionException(String message) { 29 | super(message); 30 | } 31 | } 32 | 33 | @Test 34 | public void testAssumptionFailed() { 35 | throw new MyAssumptionException("Test"); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/test/java/com/epam/reportportal/junit5/features/step/ManualStepReporterFeatureTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 EPAM Systems 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 com.epam.reportportal.junit5.features.step; 18 | 19 | import com.epam.reportportal.junit5.StepReporterTest; 20 | import com.epam.reportportal.listeners.ItemStatus; 21 | import com.epam.reportportal.service.Launch; 22 | import com.epam.reportportal.service.step.StepReporter; 23 | import org.junit.jupiter.api.Test; 24 | import org.junit.jupiter.api.extension.ExtendWith; 25 | import org.slf4j.Logger; 26 | import org.slf4j.LoggerFactory; 27 | 28 | import java.io.File; 29 | 30 | /** 31 | * @author Ihar Kahadouski 32 | */ 33 | @ExtendWith(StepReporterTest.TestExtension.class) 34 | public class ManualStepReporterFeatureTest { 35 | 36 | public static final String FIRST_NAME = "I am the first nested step"; 37 | public static final String SECOND_NAME = "I am the second nested step"; 38 | public static final String THIRD_NAME = "I am the third nested step"; 39 | 40 | private static final Logger LOGGER = LoggerFactory.getLogger(ManualStepReporterFeatureTest.class); 41 | 42 | @Test 43 | public void manualStepTest() throws InterruptedException { 44 | 45 | StepReporter stepReporter = Launch.currentLaunch().getStepReporter(); 46 | stepReporter.sendStep(FIRST_NAME); 47 | LOGGER.info("First info log of the first step"); 48 | LOGGER.info("Second info log of the first step"); 49 | Thread.sleep(100); 50 | 51 | stepReporter.sendStep(SECOND_NAME); 52 | LOGGER.error("First error log of the second step"); 53 | 54 | Thread.sleep(100); 55 | stepReporter.sendStep(ItemStatus.FAILED, THIRD_NAME, new File("pug/unlucky.jpg")); 56 | LOGGER.error("Second error log of the second step"); 57 | 58 | Thread.sleep(100); 59 | stepReporter.finishPreviousStep(); 60 | 61 | LOGGER.error("Main test method error log"); 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /src/test/java/com/epam/reportportal/junit5/features/step/ManualStepReporterSimpleTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 EPAM Systems 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 com.epam.reportportal.junit5.features.step; 18 | 19 | import com.epam.reportportal.junit5.StepReporterTest; 20 | import com.epam.reportportal.service.Launch; 21 | import com.epam.reportportal.service.step.StepReporter; 22 | import org.junit.jupiter.api.Test; 23 | import org.junit.jupiter.api.extension.ExtendWith; 24 | import org.slf4j.Logger; 25 | import org.slf4j.LoggerFactory; 26 | 27 | @ExtendWith(StepReporterTest.TestExtension.class) 28 | public class ManualStepReporterSimpleTest { 29 | 30 | public static final String FIRST_NAME = "I am the first nested step"; 31 | 32 | private static final Logger LOGGER = LoggerFactory.getLogger(ManualStepReporterSimpleTest.class); 33 | 34 | @Test 35 | public void manualStepTest() { 36 | 37 | StepReporter stepReporter = Launch.currentLaunch().getStepReporter(); 38 | 39 | stepReporter.sendStep(FIRST_NAME); 40 | LOGGER.info("Inside first nested step"); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/test/java/com/epam/reportportal/junit5/features/testcaseid/SingleDynamicAnnotatedTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 EPAM Systems 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 com.epam.reportportal.junit5.features.testcaseid; 18 | 19 | import com.epam.reportportal.annotations.TestCaseId; 20 | import com.epam.reportportal.junit5.TestCaseIdTest; 21 | import org.junit.jupiter.api.DynamicTest; 22 | import org.junit.jupiter.api.TestFactory; 23 | import org.junit.jupiter.api.extension.ExtendWith; 24 | 25 | import java.util.UUID; 26 | import java.util.stream.Stream; 27 | 28 | import static org.junit.jupiter.api.DynamicTest.dynamicTest; 29 | 30 | /** 31 | * @author Ihar Kahadouski 32 | */ 33 | @ExtendWith(TestCaseIdTest.TestCaseIdExtension.class) 34 | public class SingleDynamicAnnotatedTest { 35 | 36 | public static final String TEST_CASE_DISPLAY_NAME = UUID.randomUUID().toString(); 37 | public static final String TEST_CASE_ID_VALUE = "test-case-id"; 38 | 39 | @TestFactory 40 | @TestCaseId(TEST_CASE_ID_VALUE) 41 | Stream testForTestFactory() { 42 | return Stream.of(dynamicTest(TEST_CASE_DISPLAY_NAME, () -> System.out.println("Test factory test: " + TEST_CASE_DISPLAY_NAME))); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /src/test/java/com/epam/reportportal/junit5/features/testcaseid/SingleDynamicTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 EPAM Systems 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 com.epam.reportportal.junit5.features.testcaseid; 18 | 19 | import com.epam.reportportal.junit5.TestCaseIdTest; 20 | import org.junit.jupiter.api.DynamicTest; 21 | import org.junit.jupiter.api.TestFactory; 22 | import org.junit.jupiter.api.extension.ExtendWith; 23 | 24 | import java.util.UUID; 25 | import java.util.stream.Stream; 26 | 27 | import static org.junit.jupiter.api.DynamicTest.dynamicTest; 28 | 29 | /** 30 | * @author Ihar Kahadouski 31 | */ 32 | @ExtendWith(TestCaseIdTest.TestCaseIdExtension.class) 33 | public class SingleDynamicTest { 34 | public static final String TEST_CASE_DISPLAY_NAME = UUID.randomUUID().toString(); 35 | 36 | @TestFactory 37 | Stream testForTestFactory() { 38 | return Stream.of(dynamicTest(TEST_CASE_DISPLAY_NAME, () -> System.out.println("Test factory test: " + TEST_CASE_DISPLAY_NAME))); 39 | } 40 | 41 | } 42 | -------------------------------------------------------------------------------- /src/test/java/com/epam/reportportal/junit5/features/testcaseid/TestCaseIdFromAnnotationTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 EPAM Systems 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 com.epam.reportportal.junit5.features.testcaseid; 18 | 19 | import com.epam.reportportal.annotations.TestCaseId; 20 | import com.epam.reportportal.junit5.TestCaseIdTest; 21 | import org.junit.jupiter.api.Test; 22 | import org.junit.jupiter.api.extension.ExtendWith; 23 | 24 | /** 25 | * @author Ihar Kahadouski 26 | */ 27 | @ExtendWith(TestCaseIdTest.TestCaseIdExtension.class) 28 | public class TestCaseIdFromAnnotationTest { 29 | 30 | public static final String TEST_CASE_ID_VALUE = "test-case-id"; 31 | 32 | @TestCaseId(TEST_CASE_ID_VALUE) 33 | @Test 34 | void test() { 35 | 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/test/java/com/epam/reportportal/junit5/features/testcaseid/TestCaseIdFromCodeRefAndParamsTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 EPAM Systems 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 com.epam.reportportal.junit5.features.testcaseid; 18 | 19 | import com.epam.reportportal.junit5.TestCaseIdTest; 20 | import org.junit.jupiter.api.extension.ExtendWith; 21 | import org.junit.jupiter.params.ParameterizedTest; 22 | import org.junit.jupiter.params.provider.ValueSource; 23 | 24 | /** 25 | * @author Ihar Kahadouski 26 | */ 27 | @ExtendWith(TestCaseIdTest.TestCaseIdExtension.class) 28 | public class TestCaseIdFromCodeRefAndParamsTest { 29 | 30 | @ParameterizedTest 31 | @ValueSource(ints = {101, 0}) 32 | void parametrized(int value) { 33 | System.out.println("Parameter: " + value); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/test/java/com/epam/reportportal/junit5/features/testcaseid/TestCaseIdFromCodeRefTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 EPAM Systems 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 com.epam.reportportal.junit5.features.testcaseid; 18 | 19 | import com.epam.reportportal.junit5.TestCaseIdTest; 20 | import org.junit.jupiter.api.Test; 21 | import org.junit.jupiter.api.extension.ExtendWith; 22 | 23 | /** 24 | * @author Ihar Kahadouski 25 | */ 26 | @ExtendWith(TestCaseIdTest.TestCaseIdExtension.class) 27 | public class TestCaseIdFromCodeRefTest { 28 | 29 | @Test 30 | void test() { 31 | 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/test/java/com/epam/reportportal/junit5/features/testcaseid/TestCaseIdFromParametrizedAnnotationTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 EPAM Systems 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 com.epam.reportportal.junit5.features.testcaseid; 18 | 19 | import com.epam.reportportal.annotations.TestCaseId; 20 | import com.epam.reportportal.annotations.TestCaseIdKey; 21 | import com.epam.reportportal.junit5.TestCaseIdTest; 22 | import org.junit.jupiter.api.extension.ExtendWith; 23 | import org.junit.jupiter.params.ParameterizedTest; 24 | import org.junit.jupiter.params.provider.ValueSource; 25 | 26 | /** 27 | * @author Ihar Kahadouski 28 | */ 29 | @ExtendWith(TestCaseIdTest.TestCaseIdExtension.class) 30 | public class TestCaseIdFromParametrizedAnnotationTest { 31 | 32 | @TestCaseId(parametrized = true) 33 | @ParameterizedTest 34 | @ValueSource(strings = {"one", "two"}) 35 | void test(@TestCaseIdKey String parameter) { 36 | System.out.println("Parameter: " + parameter); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/test/java/com/epam/reportportal/junit5/features/testcaseid/TestCaseIdTemplateTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 EPAM Systems 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 com.epam.reportportal.junit5.features.testcaseid; 18 | 19 | import com.epam.reportportal.annotations.TestCaseId; 20 | import com.epam.reportportal.junit5.TestCaseIdTest; 21 | import org.junit.jupiter.api.Test; 22 | import org.junit.jupiter.api.extension.ExtendWith; 23 | 24 | @ExtendWith(TestCaseIdTest.TestCaseIdExtension.class) 25 | public class TestCaseIdTemplateTest { 26 | 27 | public static final String FIELD = "template"; 28 | 29 | public static final String TEST_CASE_ID_VALUE = "test-case-id-{this.FIELD}"; 30 | 31 | @TestCaseId(TEST_CASE_ID_VALUE) 32 | @Test 33 | void test() { 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/test/java/com/epam/reportportal/junit5/miscellaneous/DisplayNamesForConfigurationItemsTest.java: -------------------------------------------------------------------------------- 1 | package com.epam.reportportal.junit5.miscellaneous; 2 | 3 | import com.epam.reportportal.junit5.ReportPortalExtension; 4 | import com.epam.reportportal.junit5.features.configname.ConfigurationMethodsDefaultDisplayNameTest; 5 | import com.epam.reportportal.junit5.features.configname.ConfigurationMethodsDisplayNameGeneratorTest; 6 | import com.epam.reportportal.junit5.features.configname.ConfigurationMethodsDisplayNameTest; 7 | import com.epam.reportportal.junit5.features.configname.CustomDisplayNameGenerator; 8 | import com.epam.reportportal.junit5.util.TestUtils; 9 | import com.epam.reportportal.service.Launch; 10 | import com.epam.reportportal.service.step.StepReporter; 11 | import com.epam.reportportal.util.test.CommonUtils; 12 | import com.epam.ta.reportportal.ws.model.StartTestItemRQ; 13 | import io.reactivex.Maybe; 14 | import org.junit.jupiter.api.BeforeEach; 15 | import org.junit.jupiter.api.Test; 16 | import org.junit.jupiter.api.TestInstance; 17 | import org.junit.jupiter.api.extension.ExtensionContext; 18 | import org.mockito.ArgumentCaptor; 19 | import org.mockito.stubbing.Answer; 20 | 21 | import java.lang.reflect.Method; 22 | import java.util.Arrays; 23 | import java.util.List; 24 | import java.util.stream.Collectors; 25 | import java.util.stream.IntStream; 26 | 27 | import static com.epam.reportportal.junit5.miscellaneous.DisplayNamesForConfigurationItemsTest.TestExtension.LAUNCH; 28 | import static org.hamcrest.MatcherAssert.assertThat; 29 | import static org.hamcrest.Matchers.equalTo; 30 | import static org.mockito.ArgumentMatchers.any; 31 | import static org.mockito.ArgumentMatchers.notNull; 32 | import static org.mockito.Mockito.*; 33 | 34 | @TestInstance(TestInstance.Lifecycle.PER_CLASS) 35 | public class DisplayNamesForConfigurationItemsTest { 36 | 37 | public static class TestExtension extends ReportPortalExtension { 38 | static Launch LAUNCH; 39 | 40 | @Override 41 | protected Launch getLaunch(ExtensionContext context) { 42 | return LAUNCH; 43 | } 44 | } 45 | 46 | @BeforeEach 47 | public void setupMock() { 48 | LAUNCH = mock(Launch.class); 49 | when(LAUNCH.getStepReporter()).thenReturn(StepReporter.NOOP_STEP_REPORTER); 50 | when(LAUNCH.startTestItem(any())).thenAnswer((Answer>) invocation -> CommonUtils.createMaybeUuid()); 51 | when(LAUNCH.startTestItem(any(), any())).thenAnswer((Answer>) invocation -> CommonUtils.createMaybeUuid()); 52 | } 53 | 54 | @Test 55 | public void test_configuration_method_display_name_annotation() { 56 | TestUtils.runClasses(ConfigurationMethodsDisplayNameTest.class); 57 | 58 | verify(LAUNCH, times(1)).startTestItem(any()); // Start parent Suite 59 | ArgumentCaptor captorStart = ArgumentCaptor.forClass(StartTestItemRQ.class); 60 | verify(LAUNCH, times(5)).startTestItem(notNull(), captorStart.capture()); // Start a suite and two tests 61 | 62 | captorStart.getAllValues().forEach(i -> assertThat(i.getName(), equalTo(ConfigurationMethodsDisplayNameTest.DISPLAY_NAME))); 63 | } 64 | 65 | @Test 66 | public void test_configuration_method_display_name_generator() { 67 | TestUtils.runClasses(ConfigurationMethodsDisplayNameGeneratorTest.class); 68 | 69 | ArgumentCaptor startSuiteCaptor = ArgumentCaptor.forClass(StartTestItemRQ.class); 70 | verify(LAUNCH, times(1)).startTestItem(startSuiteCaptor.capture()); // Start parent Suite 71 | ArgumentCaptor startItemCaptor = ArgumentCaptor.forClass(StartTestItemRQ.class); 72 | verify(LAUNCH, times(5)).startTestItem(notNull(), startItemCaptor.capture()); // Start a suite and two tests 73 | 74 | assertThat(startSuiteCaptor.getValue().getName(), equalTo(CustomDisplayNameGenerator.DISPLAY_NAME_CLASS)); 75 | 76 | startItemCaptor.getAllValues().forEach(i -> assertThat(i.getName(), equalTo(CustomDisplayNameGenerator.DISPLAY_NAME_METHOD))); 77 | } 78 | 79 | @Test 80 | public void test_configuration_method_display_name_default_values() { 81 | TestUtils.runClasses(ConfigurationMethodsDefaultDisplayNameTest.class); 82 | 83 | verify(LAUNCH, times(1)).startTestItem(any()); // Start parent Suite 84 | ArgumentCaptor startItemCaptor = ArgumentCaptor.forClass(StartTestItemRQ.class); 85 | verify(LAUNCH, times(5)).startTestItem(notNull(), startItemCaptor.capture()); // Start a suite and two tests 86 | 87 | List itemNames = startItemCaptor.getAllValues() 88 | .stream() 89 | .map(StartTestItemRQ::getName) 90 | .filter(e -> !e.startsWith("test")) 91 | .sorted() 92 | .collect(Collectors.toList()); 93 | List methodNames = Arrays.stream(ConfigurationMethodsDefaultDisplayNameTest.class.getMethods()) 94 | .map(Method::getName) 95 | .filter(e -> e.startsWith("before") || e.startsWith("after")) 96 | .sorted() 97 | .collect(Collectors.toList()); 98 | 99 | IntStream.range(0, itemNames.size()).forEach(i -> assertThat(itemNames.get(i), equalTo(methodNames.get(i) + "()"))); 100 | } 101 | } 102 | -------------------------------------------------------------------------------- /src/test/java/com/epam/reportportal/junit5/miscellaneous/FailedBeforeEachReportsSkippedTestTest.java: -------------------------------------------------------------------------------- 1 | package com.epam.reportportal.junit5.miscellaneous; 2 | 3 | import com.epam.reportportal.junit5.ReportPortalExtension; 4 | import com.epam.reportportal.junit5.features.skipped.AfterEachFailedTest; 5 | import com.epam.reportportal.junit5.features.skipped.BeforeEachFailedParametrizedTest; 6 | import com.epam.reportportal.junit5.features.skipped.BeforeEachFailedTest; 7 | import com.epam.reportportal.junit5.util.TestUtils; 8 | import com.epam.reportportal.listeners.ItemStatus; 9 | import com.epam.reportportal.service.Launch; 10 | import com.epam.reportportal.service.step.StepReporter; 11 | import com.epam.reportportal.util.test.CommonUtils; 12 | import com.epam.ta.reportportal.ws.model.FinishTestItemRQ; 13 | import com.epam.ta.reportportal.ws.model.StartTestItemRQ; 14 | import io.reactivex.Maybe; 15 | import org.apache.commons.lang3.tuple.Pair; 16 | import org.junit.jupiter.api.BeforeEach; 17 | import org.junit.jupiter.api.Test; 18 | import org.junit.jupiter.api.extension.ExtensionContext; 19 | import org.mockito.stubbing.Answer; 20 | 21 | import java.util.ArrayList; 22 | import java.util.Date; 23 | import java.util.List; 24 | import java.util.Map; 25 | import java.util.stream.IntStream; 26 | 27 | import static com.epam.reportportal.junit5.miscellaneous.FailedBeforeEachReportsSkippedTestTest.SkippedTestExtension.ITEMS; 28 | import static com.epam.reportportal.junit5.miscellaneous.FailedBeforeEachReportsSkippedTestTest.SkippedTestExtension.LAUNCH; 29 | import static com.epam.reportportal.junit5.util.Verifications.verify_call_number_and_capture_arguments; 30 | import static org.hamcrest.MatcherAssert.assertThat; 31 | import static org.hamcrest.Matchers.*; 32 | import static org.mockito.ArgumentMatchers.any; 33 | import static org.mockito.Mockito.*; 34 | 35 | public class FailedBeforeEachReportsSkippedTestTest { 36 | public static class SkippedTestExtension extends ReportPortalExtension { 37 | 38 | final static List ITEMS = new ArrayList<>(); 39 | static Launch LAUNCH; 40 | 41 | @Override 42 | protected Launch getLaunch(ExtensionContext context) { 43 | return LAUNCH; 44 | } 45 | } 46 | 47 | @BeforeEach 48 | public void setupMock() { 49 | ITEMS.clear(); 50 | LAUNCH = mock(Launch.class); 51 | when(LAUNCH.getStepReporter()).thenReturn(StepReporter.NOOP_STEP_REPORTER); 52 | when(LAUNCH.startTestItem(any())).thenAnswer((Answer>) invocation -> { 53 | Maybe result = CommonUtils.createMaybeUuid(); 54 | ITEMS.add(result.blockingGet()); 55 | return result; 56 | }); 57 | when(LAUNCH.startTestItem(any(), any())).thenAnswer((Answer>) invocation -> { 58 | Maybe result = CommonUtils.createMaybeUuid(); 59 | ITEMS.add(result.blockingGet()); 60 | return result; 61 | }); 62 | } 63 | 64 | @Test 65 | public void agent_should_report_skipped_test_in_case_of_failed_before_each() { 66 | TestUtils.runClasses(BeforeEachFailedTest.class); 67 | Pair>, Map> calls = verify_call_number_and_capture_arguments(3, 68 | LAUNCH 69 | ); 70 | verifyNoMoreInteractions(LAUNCH); 71 | 72 | assertThat("There are 3 item created: suite, @BeforeEach and @Test", ITEMS, hasSize(3)); 73 | 74 | FinishTestItemRQ beforeEachFinish = calls.getValue().get(ITEMS.get(1)); 75 | 76 | assertThat("@BeforeEach failed", beforeEachFinish.getStatus(), equalTo("FAILED")); 77 | 78 | StartTestItemRQ testStart = calls.getKey().get(2).getValue(); 79 | assertThat("@Test has correct code reference", 80 | testStart.getCodeRef(), 81 | equalTo(BeforeEachFailedTest.class.getCanonicalName() + ".testBeforeEachFailed") 82 | ); 83 | 84 | assertThat("@Test has correct name", testStart.getName(), equalTo("testBeforeEachFailed()")); 85 | 86 | FinishTestItemRQ testFinish = calls.getValue().get(ITEMS.get(2)); 87 | assertThat("@Test reported as skipped", testFinish.getStatus(), equalTo(ItemStatus.SKIPPED.name())); 88 | assertThat("@Test issue muted", testFinish.getIssue(), sameInstance(Launch.NOT_ISSUE)); 89 | Date currentDate = new Date(); 90 | assertThat(testFinish.getEndTime(), lessThanOrEqualTo(currentDate)); 91 | } 92 | 93 | @Test 94 | public void agent_should_report_skipped_parametrized_tests_in_case_of_failed_before_each() { 95 | TestUtils.runClasses(BeforeEachFailedParametrizedTest.class); 96 | Pair>, Map> calls = verify_call_number_and_capture_arguments(6, 97 | 1, 98 | LAUNCH 99 | ); 100 | verifyNoMoreInteractions(LAUNCH); 101 | 102 | assertThat("There are 6 item created: parent suite, suite, 2 @BeforeEach, @Test 1 and @Test 2", ITEMS, hasSize(6)); 103 | 104 | FinishTestItemRQ beforeEachFinish = calls.getValue().get(ITEMS.get(2)); 105 | 106 | assertThat("@BeforeEach failed", beforeEachFinish.getStatus(), equalTo("FAILED")); 107 | 108 | Date currentDate = new Date(); 109 | IntStream.rangeClosed(0, 1).boxed().forEach(i -> { 110 | StartTestItemRQ testStart = calls.getKey().get(3 + (i * 2)).getValue(); 111 | assertThat("@Test has correct code reference", 112 | testStart.getCodeRef(), 113 | equalTo(BeforeEachFailedParametrizedTest.class.getCanonicalName() + ".testBeforeEachFailed") 114 | ); 115 | 116 | assertThat("@Test has correct name", 117 | testStart.getName(), 118 | equalTo("[" + (i + 1) + "] " + BeforeEachFailedParametrizedTest.TestParams.values()[i]) 119 | ); 120 | 121 | FinishTestItemRQ testFinish = calls.getValue().get(ITEMS.get(3 + (i * 2))); 122 | assertThat("@Test reported as skipped", testFinish.getStatus(), equalTo(ItemStatus.SKIPPED.name())); 123 | assertThat("@Test issue muted", testFinish.getIssue(), sameInstance(Launch.NOT_ISSUE)); 124 | assertThat(testFinish.getEndTime(), lessThanOrEqualTo(currentDate)); 125 | }); 126 | } 127 | 128 | @Test 129 | public void agent_should_not_report_skipped_test_in_case_of_failed_after_each() { 130 | TestUtils.runClasses(AfterEachFailedTest.class); 131 | Pair>, Map> calls = verify_call_number_and_capture_arguments(4, 132 | LAUNCH 133 | ); 134 | verifyNoMoreInteractions(LAUNCH); 135 | 136 | assertThat("There are 4 item created: suite, @BeforeEach, @Test and @AfterEach", ITEMS, hasSize(4)); 137 | 138 | FinishTestItemRQ beforeEachFinish = calls.getValue().get(ITEMS.get(1)); 139 | 140 | assertThat("@BeforeEach passed", beforeEachFinish.getStatus(), equalTo("PASSED")); 141 | 142 | FinishTestItemRQ testFinish = calls.getValue().get(ITEMS.get(2)); 143 | assertThat("@Test passed", testFinish.getStatus(), equalTo("PASSED")); 144 | 145 | FinishTestItemRQ afterEachFinish = calls.getValue().get(ITEMS.get(3)); 146 | assertThat("@AfterEach failed", afterEachFinish.getStatus(), equalTo("FAILED")); 147 | } 148 | } 149 | -------------------------------------------------------------------------------- /src/test/java/com/epam/reportportal/junit5/miscellaneous/FailedBeforeEachSkippedTestOrder.java: -------------------------------------------------------------------------------- 1 | package com.epam.reportportal.junit5.miscellaneous; 2 | 3 | import com.epam.reportportal.junit5.ReportPortalExtension; 4 | import com.epam.reportportal.junit5.features.skipped.BeforeEachFailedWithAfterEach; 5 | import com.epam.reportportal.junit5.util.TestUtils; 6 | import com.epam.reportportal.service.Launch; 7 | import com.epam.ta.reportportal.ws.model.StartTestItemRQ; 8 | import org.junit.jupiter.api.BeforeEach; 9 | import org.junit.jupiter.api.RepeatedTest; 10 | import org.junit.jupiter.api.Test; 11 | import org.junit.jupiter.api.extension.ExtensionContext; 12 | import org.mockito.ArgumentCaptor; 13 | 14 | import java.util.Date; 15 | import java.util.List; 16 | 17 | import static com.epam.reportportal.junit5.miscellaneous.FailedBeforeEachSkippedTestOrder.SkippedTestExtension.LAUNCH; 18 | import static org.hamcrest.MatcherAssert.assertThat; 19 | import static org.hamcrest.Matchers.greaterThan; 20 | import static org.mockito.ArgumentMatchers.notNull; 21 | import static org.mockito.Mockito.times; 22 | import static org.mockito.Mockito.verify; 23 | 24 | public class FailedBeforeEachSkippedTestOrder { 25 | public static class SkippedTestExtension extends ReportPortalExtension { 26 | static Launch LAUNCH; 27 | 28 | @Override 29 | protected Launch getLaunch(ExtensionContext context) { 30 | return LAUNCH; 31 | } 32 | } 33 | 34 | @BeforeEach 35 | public void setupMock() { 36 | LAUNCH = TestUtils.getBasicMockedLaunch(); 37 | } 38 | 39 | @Test 40 | @RepeatedTest(10) 41 | public void test_skipped_test_order_by_start_time_after_failed_before_each() { 42 | TestUtils.runClasses(BeforeEachFailedWithAfterEach.class); 43 | 44 | ArgumentCaptor captor = ArgumentCaptor.forClass(StartTestItemRQ.class); 45 | verify(LAUNCH, times(3)).startTestItem(notNull(), captor.capture()); // Start a before, a test, an after 46 | 47 | List rqValues = captor.getAllValues(); 48 | Date firstDate = rqValues.get(0).getStartTime(); 49 | for (int i = 1; i < rqValues.size(); i++) { 50 | Date itemDate = rqValues.get(i).getStartTime(); 51 | assertThat(itemDate, greaterThan(firstDate)); 52 | firstDate = itemDate; 53 | } 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /src/test/java/com/epam/reportportal/junit5/util/TestUtils.java: -------------------------------------------------------------------------------- 1 | package com.epam.reportportal.junit5.util; 2 | 3 | import com.epam.reportportal.listeners.ListenerParameters; 4 | import com.epam.reportportal.service.Launch; 5 | import com.epam.reportportal.service.ReportPortalClient; 6 | import com.epam.reportportal.util.test.CommonUtils; 7 | import com.epam.ta.reportportal.ws.model.BatchSaveOperatingRS; 8 | import com.epam.ta.reportportal.ws.model.OperationCompletionRS; 9 | import com.epam.ta.reportportal.ws.model.StartTestItemRQ; 10 | import com.epam.ta.reportportal.ws.model.item.ItemCreatedRS; 11 | import com.epam.ta.reportportal.ws.model.launch.StartLaunchRQ; 12 | import com.epam.ta.reportportal.ws.model.launch.StartLaunchRS; 13 | import io.reactivex.Maybe; 14 | import org.apache.commons.lang3.tuple.Pair; 15 | import org.junit.platform.engine.discovery.ClassSelector; 16 | import org.junit.platform.engine.discovery.DiscoverySelectors; 17 | import org.junit.platform.launcher.LauncherDiscoveryRequest; 18 | import org.junit.platform.launcher.TestExecutionListener; 19 | import org.junit.platform.launcher.core.LauncherConfig; 20 | import org.junit.platform.launcher.core.LauncherDiscoveryRequestBuilder; 21 | import org.junit.platform.launcher.core.LauncherFactory; 22 | import org.mockito.ArgumentCaptor; 23 | import org.mockito.stubbing.Answer; 24 | 25 | import java.util.*; 26 | import java.util.stream.Collectors; 27 | import java.util.stream.Stream; 28 | 29 | import static com.epam.reportportal.util.test.CommonUtils.createMaybeUuid; 30 | import static org.mockito.ArgumentMatchers.*; 31 | import static org.mockito.Mockito.mock; 32 | import static org.mockito.Mockito.when; 33 | 34 | public class TestUtils { 35 | 36 | private TestUtils() { 37 | } 38 | 39 | public static ListenerParameters standardParameters() { 40 | ListenerParameters result = new ListenerParameters(); 41 | result.setClientJoin(false); 42 | result.setBatchLogsSize(1); 43 | result.setLaunchName("My-test-launch-" + CommonUtils.generateUniqueId()); 44 | result.setProjectName("unit-test"); 45 | result.setEnable(true); 46 | return result; 47 | } 48 | 49 | public static void runClasses(final Class... testClasses) { 50 | runClasses(null, testClasses); 51 | } 52 | 53 | public static void runClasses(final TestExecutionListener listener, final Class... testClasses) { 54 | ClassSelector[] classSelectors = Stream.of(testClasses).map(DiscoverySelectors::selectClass).toArray(ClassSelector[]::new); 55 | LauncherDiscoveryRequest request = LauncherDiscoveryRequestBuilder.request().selectors(classSelectors).build(); 56 | LauncherConfig.Builder builder = LauncherConfig.builder(); 57 | if (listener != null) { 58 | builder.addTestExecutionListeners(listener); 59 | } 60 | LauncherConfig config = builder.enableTestExecutionListenerAutoRegistration(false).build(); 61 | LauncherFactory.create(config).execute(request); 62 | } 63 | 64 | public static Launch getBasicMockedLaunch() { 65 | Launch result = mock(Launch.class); 66 | when(result.startTestItem(any())).thenAnswer((Answer>) invocation -> createMaybeUuid()); 67 | when(result.startTestItem(any(), any())).thenAnswer((Answer>) invocation -> createMaybeUuid()); 68 | return result; 69 | } 70 | 71 | public static void mockLaunch(ReportPortalClient client, String launchUuid, String testClassUuid, String testMethodUuid) { 72 | mockLaunch(client, launchUuid, testClassUuid, Collections.singleton(testMethodUuid)); 73 | } 74 | 75 | @SuppressWarnings("unchecked") 76 | public static void mockLaunch(ReportPortalClient client, String launchUuid, String testClassUuid, 77 | Collection testMethodUuidList) { 78 | when(client.startLaunch(any())).thenReturn(Maybe.just(new StartLaunchRS(launchUuid, 1L))); 79 | 80 | Maybe testClassMaybe = Maybe.just(new ItemCreatedRS(testClassUuid, testClassUuid)); 81 | when(client.startTestItem(any())).thenReturn(testClassMaybe); 82 | 83 | List> responses = testMethodUuidList.stream() 84 | .map(uuid -> Maybe.just(new ItemCreatedRS(uuid, uuid))) 85 | .collect(Collectors.toList()); 86 | Maybe first = responses.get(0); 87 | Maybe[] other = responses.subList(1, responses.size()).toArray(new Maybe[0]); 88 | when(client.startTestItem(eq(testClassUuid), any())).thenReturn(first, other); 89 | new HashSet<>(testMethodUuidList).forEach(testMethodUuid -> when(client.finishTestItem( 90 | eq(testMethodUuid), 91 | any() 92 | )).thenReturn(Maybe.just(new OperationCompletionRS()))); 93 | 94 | Maybe testClassFinishMaybe = Maybe.just(new OperationCompletionRS()); 95 | when(client.finishTestItem(eq(testClassUuid), any())).thenReturn(testClassFinishMaybe); 96 | 97 | when(client.finishLaunch(eq(launchUuid), any())).thenReturn(Maybe.just(new OperationCompletionRS())); 98 | } 99 | 100 | public static StartLaunchRQ launchRQ(ListenerParameters parameters) { 101 | StartLaunchRQ result = new StartLaunchRQ(); 102 | result.setName(parameters.getLaunchName()); 103 | result.setStartTime(Calendar.getInstance().getTime()); 104 | return result; 105 | } 106 | 107 | public static void mockNestedSteps(ReportPortalClient client, Pair parentNestedPair) { 108 | mockNestedSteps(client, Collections.singletonList(parentNestedPair)); 109 | } 110 | 111 | @SuppressWarnings("unchecked") 112 | public static void mockNestedSteps(final ReportPortalClient client, final List> parentNestedPairs) { 113 | Map> responseOrders = parentNestedPairs.stream() 114 | .collect(Collectors.groupingBy(Pair::getKey, Collectors.mapping(Pair::getValue, Collectors.toList()))); 115 | responseOrders.forEach((k, v) -> { 116 | List> responses = v.stream() 117 | .map(uuid -> Maybe.just(new ItemCreatedRS(uuid, uuid))) 118 | .collect(Collectors.toList()); 119 | 120 | Maybe first = responses.get(0); 121 | Maybe[] other = responses.subList(1, responses.size()).toArray(new Maybe[0]); 122 | when(client.startTestItem(same(k), any())).thenReturn(first, other); 123 | }); 124 | parentNestedPairs.forEach(p -> when(client.finishTestItem(same(p.getValue()), 125 | any() 126 | )).thenAnswer((Answer>) invocation -> Maybe.just(new OperationCompletionRS()))); 127 | } 128 | 129 | @SuppressWarnings("unchecked") 130 | public static void mockLogging(ReportPortalClient client) { 131 | when(client.log(any(List.class))).thenReturn(Maybe.just(new BatchSaveOperatingRS())); 132 | } 133 | 134 | public static StartTestItemRQ extractRequest(ArgumentCaptor captor, String methodType) { 135 | return captor.getAllValues() 136 | .stream() 137 | .filter(it -> methodType.equalsIgnoreCase(it.getType())) 138 | .findAny() 139 | .orElseThrow(() -> new AssertionError(String.format("Method type '%s' should be present among requests", methodType))); 140 | } 141 | } 142 | -------------------------------------------------------------------------------- /src/test/java/com/epam/reportportal/junit5/utils/ItemTreeUtilsTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 EPAM Systems 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 com.epam.reportportal.junit5.utils; 18 | 19 | import com.epam.reportportal.service.tree.TestItemTree; 20 | import io.reactivex.Maybe; 21 | import org.junit.jupiter.api.BeforeEach; 22 | import org.junit.jupiter.api.Test; 23 | import org.junit.jupiter.api.TestInfo; 24 | import org.junit.jupiter.api.extension.ExtensionContext; 25 | import org.mockito.Mock; 26 | import org.mockito.MockitoAnnotations; 27 | 28 | import static org.hamcrest.MatcherAssert.assertThat; 29 | import static org.hamcrest.Matchers.equalTo; 30 | import static org.hamcrest.Matchers.notNullValue; 31 | import static org.mockito.Mockito.when; 32 | 33 | /** 34 | * @author Ivan Budayeu 35 | */ 36 | class ItemTreeUtilsTest { 37 | 38 | private static final String NAME = "Simple name"; 39 | private static final int ANOTHER_HASH = NAME.hashCode() - 1; 40 | 41 | @Mock 42 | private TestInfo testInfo; 43 | 44 | @Mock 45 | private ExtensionContext extensionContext; 46 | 47 | private TestItemTree testItemTree; 48 | 49 | @BeforeEach 50 | void init() { 51 | MockitoAnnotations.initMocks(this); 52 | when(testInfo.getDisplayName()).thenReturn(NAME); 53 | when(extensionContext.getDisplayName()).thenReturn(NAME); 54 | 55 | testItemTree = new TestItemTree(); 56 | } 57 | 58 | @Test 59 | void createKeyFromString() { 60 | TestItemTree.ItemTreeKey itemTreeKey = ItemTreeUtils.createItemTreeKey(NAME); 61 | 62 | assertThat(itemTreeKey.getName(), equalTo(NAME)); 63 | assertThat(itemTreeKey.getHash(), equalTo(NAME.hashCode())); 64 | } 65 | 66 | @Test 67 | void createKeyFromStringAndHash() { 68 | TestItemTree.ItemTreeKey itemTreeKey = ItemTreeUtils.createItemTreeKey(NAME, ANOTHER_HASH); 69 | 70 | assertThat(itemTreeKey.getName(), equalTo(NAME)); 71 | assertThat(itemTreeKey.getHash(), equalTo(ANOTHER_HASH)); 72 | } 73 | 74 | @Test 75 | void createKeyFromTestInfo() { 76 | TestItemTree.ItemTreeKey itemTreeKey = ItemTreeUtils.createItemTreeKey(testInfo); 77 | 78 | assertThat(itemTreeKey.getName(), equalTo(NAME)); 79 | assertThat(itemTreeKey.getHash(), equalTo(NAME.hashCode())); 80 | } 81 | 82 | @Test 83 | void createKeyFromTestInfoAndHash() { 84 | TestItemTree.ItemTreeKey itemTreeKey = ItemTreeUtils.createItemTreeKey(testInfo, ANOTHER_HASH); 85 | 86 | assertThat(itemTreeKey.getName(), equalTo(NAME)); 87 | assertThat(itemTreeKey.getHash(), equalTo(ANOTHER_HASH)); 88 | } 89 | 90 | @Test 91 | void createKeyFromExtensionContext() { 92 | TestItemTree.ItemTreeKey itemTreeKey = ItemTreeUtils.createItemTreeKey(extensionContext); 93 | 94 | assertThat(itemTreeKey.getName(), equalTo(NAME)); 95 | assertThat(itemTreeKey.getHash(), equalTo(NAME.hashCode())); 96 | } 97 | 98 | @Test 99 | void createKeyFromExtensionContextAndHash() { 100 | TestItemTree.ItemTreeKey itemTreeKey = ItemTreeUtils.createItemTreeKey(extensionContext, ANOTHER_HASH); 101 | 102 | assertThat(itemTreeKey.getName(), equalTo(NAME)); 103 | assertThat(itemTreeKey.getHash(), equalTo(ANOTHER_HASH)); 104 | } 105 | 106 | @Test 107 | void retrieveLeafByName() { 108 | 109 | TestItemTree.ItemTreeKey treeKey = TestItemTree.ItemTreeKey.of(NAME); 110 | Maybe itemId = createIdMaybe("first"); 111 | TestItemTree.TestItemLeaf itemLeaf = TestItemTree.createTestItemLeaf(itemId); 112 | 113 | testItemTree.getTestItems().put(treeKey, itemLeaf); 114 | 115 | TestItemTree.TestItemLeaf retrievedLeaf = ItemTreeUtils.retrieveLeaf(NAME, testItemTree); 116 | 117 | assertThat(retrievedLeaf.getItemId(), notNullValue()); 118 | assertThat(retrievedLeaf.getItemId(), equalTo(itemId)); 119 | } 120 | 121 | @Test 122 | void retrieveLeafByTestInfo() { 123 | TestItemTree.ItemTreeKey treeKey = TestItemTree.ItemTreeKey.of(NAME); 124 | Maybe itemId = createIdMaybe("first"); 125 | TestItemTree.TestItemLeaf itemLeaf = TestItemTree.createTestItemLeaf(itemId); 126 | 127 | testItemTree.getTestItems().put(treeKey, itemLeaf); 128 | 129 | TestItemTree.TestItemLeaf retrievedLeaf = ItemTreeUtils.retrieveLeaf(testInfo, testItemTree); 130 | 131 | assertThat(retrievedLeaf.getItemId(), notNullValue()); 132 | assertThat(retrievedLeaf.getItemId(), equalTo(itemId)); 133 | } 134 | 135 | public static Maybe createIdMaybe(String id) { 136 | return Maybe.create(emitter -> { 137 | emitter.onSuccess(id); 138 | emitter.onComplete(); 139 | }); 140 | } 141 | } -------------------------------------------------------------------------------- /src/test/resources/META-INF/aop-ajc.xml: -------------------------------------------------------------------------------- 1 | 16 | 17 | 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /src/test/resources/agent.properties: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright 2019 EPAM Systems 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 | agent.name=TestAgent 17 | agent.version=TestVersion -------------------------------------------------------------------------------- /src/test/resources/files/css.css: -------------------------------------------------------------------------------- 1 | p { 2 | font-family: arial, helvetica, sans-serif; 3 | } 4 | 5 | h2 { 6 | font-size: 20pt; 7 | color: red; 8 | background: white; 9 | } 10 | 11 | .note { 12 | color: red; 13 | background-color: yellow; 14 | font-weight: bold; 15 | } 16 | 17 | p#paragraph1 { 18 | padding-left: 10px; 19 | } 20 | 21 | a:hover { 22 | text-decoration: none; 23 | } 24 | 25 | #news p { 26 | color: blue; 27 | } 28 | 29 | [type="button"] { 30 | background-color: green; 31 | } 32 | -------------------------------------------------------------------------------- /src/test/resources/logback-test.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | %d{HH:mm:ss.SSS} %-5level %logger{5} - %thread - %msg%n 9 | 10 | 11 | 12 | 13 | 14 | 15 | %d{HH:mm:ss.SSS} [%t] %-5level - %msg%n 16 | [%t] - %msg%n 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | -------------------------------------------------------------------------------- /src/test/resources/pug/unlucky.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/reportportal/agent-java-junit5/72bb2f10b35124a6a6c6e25842196ef2566a3682/src/test/resources/pug/unlucky.jpg --------------------------------------------------------------------------------