{"id":13665229,"url":"https://github.com/allure-framework/allure-kotlin","last_synced_at":"2025-04-16T08:54:42.330Z","repository":{"id":43117250,"uuid":"250581163","full_name":"allure-framework/allure-kotlin","owner":"allure-framework","description":"Allure integrations for test frameworks targeting Kotlin and Java with 1.6 source compatibility.","archived":false,"fork":false,"pushed_at":"2022-04-18T09:17:36.000Z","size":299,"stargazers_count":58,"open_issues_count":17,"forks_count":23,"subscribers_count":10,"default_branch":"master","last_synced_at":"2025-04-11T14:40:52.043Z","etag":null,"topics":["allure","android","automation","espresso","kotlin","robolectric"],"latest_commit_sha":null,"homepage":"","language":"Kotlin","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/allure-framework.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":".github/CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":".github/CODEOWNERS","security":null,"support":null}},"created_at":"2020-03-27T16:10:13.000Z","updated_at":"2025-01-20T16:11:26.000Z","dependencies_parsed_at":"2022-08-23T22:40:19.541Z","dependency_job_id":null,"html_url":"https://github.com/allure-framework/allure-kotlin","commit_stats":null,"previous_names":[],"tags_count":19,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/allure-framework%2Fallure-kotlin","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/allure-framework%2Fallure-kotlin/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/allure-framework%2Fallure-kotlin/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/allure-framework%2Fallure-kotlin/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/allure-framework","download_url":"https://codeload.github.com/allure-framework/allure-kotlin/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248799251,"owners_count":21163397,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["allure","android","automation","espresso","kotlin","robolectric"],"created_at":"2024-08-02T06:00:29.996Z","updated_at":"2025-04-16T08:54:42.310Z","avatar_url":"https://github.com/allure-framework.png","language":"Kotlin","funding_links":[],"categories":["Programming languages and frameworks"],"sub_categories":["Kotlin and Android"],"readme":"[build]: https://github.com/allure-framework/allure-kotlin/actions\n[build-badge]: https://github.com/allure-framework/allure-kotlin/workflows/Build/badge.svg\n[release]: https://github.com/allure-framework/allure-kotlin/releases/latest \"Latest release\"\n[release-badge]: https://img.shields.io/github/release/allure-framework/allure-kotlin.svg?style=flat\n[maven]: https://repo.maven.apache.org/maven2/io/qameta/allure/allure-kotlin-android/ \"Maven Central\"\n[maven-badge]: https://img.shields.io/maven-central/v/io.qameta.allure/allure-kotlin-android.svg?style=flat\n[license]: http://www.apache.org/licenses/LICENSE-2.0\n[license-badge]: https://img.shields.io/badge/License-Apache%202.0-blue.svg\n\n[![build-badge][]][build] [![release-badge][]][release] [![maven-badge][]][maven] [![License][license-badge]][license]\n\n# Allure Kotlin Integrations\n\nThe repository contains Allure2 adaptors for JVM-based test frameworks targeting Kotlin and Java with 1.6 source compatibility. \n\nThe core of this library was ported from `allure-java`. Thanks to that `allure-kotlin` has the same API, features, test coverage and solutions as `allure-java`. On top of the core library support for Kotlin and Android test frameworks were added.\n\nCheck out the [Allure Documentation][allure-docs].\n\n## Supported frameworks\n* JUnit4 \n* Android Robolectric (via AndroidX Test)\n* Android Instrumentation (via AndroidX Test)\n\n## Getting started\n\n### JUnit4\n\n#### Setting up the dependency\n```gradle\nrepositories {\n    mavenCentral()\n}\n\ndependencies {\n    testImplementation \"io.qameta.allure:allure-kotlin-model:$LATEST_VERSION\"\n    testImplementation \"io.qameta.allure:allure-kotlin-commons:$LATEST_VERSION\"\n    testImplementation \"io.qameta.allure:allure-kotlin-junit4:$LATEST_VERSION\"\n}\n```\n#### Attaching listener\n\nAttach the `AllureJunit4` run listener using one of available methods: \n\n- Attach the listener in build tool\n    - **Maven** - use [Maven Surfire Plugin][maven-surfire-plugin]\n    - **Gradle** - use [JUnit Foundation][junit-foundation] ([example][gradle-test-listener]) \n- Use predefined test runner \n\n```kotlin\n@RunWith(AllureRunner::class)\nclass MyTest {\n    ...\n}\n\n@RunWith(AllureParametrizedRunner::class)\nclass MyParameterizedTest {\n    ...\n}\n```\n\n### Android tests\n\n#### Setting up the dependency\n```gradle\nrepositories {\n    mavenCentral()\n}\n\ndependencies {\n    androidTestImplementation \"io.qameta.allure:allure-kotlin-model:$LATEST_VERSION\"\n    androidTestImplementation \"io.qameta.allure:allure-kotlin-commons:$LATEST_VERSION\"\n    androidTestImplementation \"io.qameta.allure:allure-kotlin-junit4:$LATEST_VERSION\"\n    androidTestImplementation \"io.qameta.allure:allure-kotlin-android:$LATEST_VERSION\"\n}\n```\n\n#### Attaching listener\n\nAndroidX Test introduced a new `AndroidJUnit4` class runner that can be used for both **Robolectric** and **on-device instrumentation tests**. The same pattern is used for `AllureAndroidJUnit4` class runner. It attaches the allure listener to current class runner, but under the hood it uses `AndroidJUnit4`. All you need to do is to add `@RunWith(AllureAndroidJUnit4::class)` annotation to your test. \n\n```kotlin\n@RunWith(AllureAndroidJUnit4::class)\nclass MyInstrumentationTest {\n    ...\n}\n```\n\nUsing AllureAndroidJUnit4 over class - works for both robolectric and on-device tests.\n\n#### Robolectric tests\n\nRobolectric tests are simple unit tests, hence the API is the same. The report data will be placed in the same place as for unit tests. \n\n#### On-device instrumentation tests\n\nYou can also use testInstrumentationRunner for setting up runner.\n\n```\nandroid {\n    defaultConfig {\n        testInstrumentationRunner \"io.qameta.allure.android.runners.AllureAndroidJUnitRunner\"\n    }\n}\n```\n\n##### Integration\nAs on-device instrumentation test run on an actual device, the results have to be saved there as well. \nYou don't need to add any permissions to manifest: results are saved in an app files directory, e.g.\n`/data/data/com.example/files/allure-results`.\n\n\nAfter the tests are finished you can move the results to the external storage and pull the files using an **adb** like this one:\n```\n# Assuming your package is com.example\nadb exec-out run-as com.example sh -c 'cd /data/data/com.example/files \u0026\u0026 tar cf - allure-results' \u003e allure-results.tar\n\n# Or using pull\n$ adb shell\n$ run-as com.example sh -c 'cd /data/data/com.example/files \u0026\u0026 tar cf - allure-results' | tar xvf - -C /data/local/tmp\n# Ignore the permission errors\n$ exit\n$ adb pull /data/local/tmp/allure-results\n```\nFinally, you can generate the report via Allure CLI (see the [Allure Documentation][allure-cli]) or generate report with [allure-gradle][allure-gradle-plugin] plugin.\n\n##### **Orchestrator TestStorage**\nWhen tests clears app data between each tests then saving test results in app storage will not work because old test results will be cleared when app data is cleared.\nTo save test results directly on sdcard new TestStorage from androidx.test.services can be used.\n\nEnabling test storage for automation tests:\n - add `allure.results.useTestStorage=true` to `allure.properties` in androidTest resources\n - add `androidTestUtil(\"androidx.test:orchestrator:VERSION}` to your app dependencies (if you do not have it already)\n\nAfter that allure will use TestStorage to save test results. Test results will be saved by default into `/sdcard/googletest/test_outputfiles/allure-results` \nTo get those files from device you can use e.g `adb exec-out sh -c 'cd  /sdcard/googletest/test_outputfiles \u0026\u0026 tar cf - allure-results' | tar xvf - -C /output/dir`\n\n*NOTE: allure-results folder name can be changed using `allure.results.directory` property.*\n\n##### Features\n\nThe Allure Android API includes couple of features to make your reports a bit better.\n\n###### Screenshot attachment\n\nScreenshot can be taken and appended as an attachment to step or test in which they were executed:\n```kotlin\n@Test\nfun screenshotExample() {\n    step(\"Step screenshot\") {\n        allureScreenshot(name = \"ss_step\", quality = 90, scale = 1.0f)\n    }\n    allureScreenshot(name = \"ss_test\", quality = 50, scale = 1.0f)\n}\n```\n\n###### Screenshot rule\n\nTest rule to make the screenshot after each test and attach it to the test report. It includes a `mode` parameter which decides for which tests to make a screenshot:\n* SUCCESS - only successful tests\n* FAILURE - only failed tests\n* END - all tests\n\n```kotlin\n@get:Rule\nval logcatRule = ScreenshotRule(mode = ScreenshotRule.Mode.END, screenshotName = \"ss_end\")\n```\n\n###### Logcat rule\n\nTest rule that clears the logcat before each test and appends the log dump as an attachment in case of failure.\n\n```kotlin\n@get:Rule\nval logcatRule = LogcatRule()\n```\n\n###### Window hierarchy rule\n\nYou can use WindowHierarchyRule to capture a window hierarchy via uiautomator in case of Throwable during test.\n```kotlin\n@get:Rule\nval windowHierarchyRule = WindowHierarchyRule()\n```\n\n## Samples\n\nDifferent examples of `allure-kotlin` usage are presented in `samples` directory. This includes:\n- `junit4-android` - complete Android sample with unit tests, robolectric tests and on device instrumentation tests\n\n## Connection with allure-java\n\nFollowing modules have been migrated:\n\n* `allure-model` -\u003e `allure-kotlin-model`\n* `allure-java-commons` -\u003e `allure-kotlin-commons`\n* `allure-java-commons-test` -\u003e `allure-kotlin-commons-test`\n\nFollowing changes have to be made in order to keep the compatibility with Java 1.6: \n* `java.util.Optional` (Java 1.8+) -\u003e Kotlin null type \u0026 safe call operators\n* `java.util.stream.*` (Java 1.8+) -\u003e Kotlin collection operators\n* `java.nio.file.*` (Java 1.7+) -\u003e migrating form `Path` to `File`\n* repeatable annotations (Java 1.8+) -\u003e no alternatives, feature not supported by JVM 1.6 \n\n*The only part that was not migrated is aspects support.*\n\n## Contributing\n\nThanks to all people who contributed. Especially [@kamildziadek](https://github.com/kamildziadek) who started allure-kotlin. [Contribute](.github/CONTRIBUTING.md).\n\n## License\n\nThe Allure Framework is released under version 2.0 of the [Apache License][license].\n\n[allure-gradle-plugin]: https://github.com/allure-framework/allure-gradle\n[allure-cli]: https://docs.qameta.io/allure/#_reporting\n[gradle-test-listener]: https://discuss.gradle.org/t/how-to-attach-a-runlistener-to-your-junit-4-tests-in-gradle/30788\n[junit-foundation]: https://github.com/Nordstrom/JUnit-Foundation\n[allure-docs]: https://docs.qameta.io/allure/\n[maven-surfire-plugin]: https://maven.apache.org/surefire/maven-surefire-plugin/examples/junit.html\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fallure-framework%2Fallure-kotlin","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fallure-framework%2Fallure-kotlin","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fallure-framework%2Fallure-kotlin/lists"}