Skip to content

Commit

Permalink
Merge pull request #66 from rubensousa/release_report
Browse files Browse the repository at this point in the history
Update docs
  • Loading branch information
rubensousa authored Sep 29, 2024
2 parents 8dbc57e + ebbd6bf commit 10d1129
Show file tree
Hide file tree
Showing 13 changed files with 64 additions and 79 deletions.
2 changes: 1 addition & 1 deletion build-logic/settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ dependencyResolutionManagement {

rootProject.name = "build-logic"
include(":allure-gradle-plugin")
project(":allure-gradle-plugin").projectDir = File("../carioca-report/report-android-allure-gradle-plugin")
project(":allure-gradle-plugin").projectDir = File("../carioca-report-allure-gradle-plugin")

This file was deleted.

17 changes: 17 additions & 0 deletions docs/changelog/reports.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,23 @@ Libraries with the same version:

## Version 1.0.0

### 1.0.0-alpha03

2024-09-30

#### API changes

- Removed `dumpOnSuccess` from `DumpViewHierarchyInterceptor`

#### Improvements

- Decreased default delays for screen recordings, which decreases the total test execution time by around 25% [#63](https://github.com/rubensousa/Carioca/pull/63)
- Added `RecordingOrientation` to `RecordingOptions` to allow overriding the default orientation of the video [#65](https://github.com/rubensousa/Carioca/pull/65)

#### Bug fixes

- Fixed screenshot options inside steps or scenarios not using the provided options [#62](https://github.com/rubensousa/Carioca/pull/62)

### 1.0.0-alpha02

2024-09-27
Expand Down
35 changes: 14 additions & 21 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,18 @@

A collection of testing tools for Android that include flexible reporting capabilities

Artifacts available for test reports:
Motivation for these libraries:

1. I kept copying some of these classes around in multiple projects
2. Analysing the standard junit test reports when you have long UI tests gets frustrating
3. Consistent screen recording and screenshots across different screen resolutions
4. Flexible APIs for any test report format
5. No enforced inheritance in test classes unlike other testing libraries


Libraries currently available:

1. [Instrumented test reports](test-reports-android.md) and [Allure Plugin](android-allure-plugin.md)
```groovy
// Test reports for android tests
androidTestImplementation "com.rubensousa.carioca:report-android:{{ report.version }}"
Expand All @@ -15,9 +25,7 @@ androidTestImplementation "com.rubensousa.carioca:report-android-coroutines:{{ r
androidTestImplementation "com.rubensousa.carioca:report-json:{{ report.version }}"
androidTestImplementation "com.rubensousa.carioca:report-runtime:{{ report.version }}"
```

Artifacts available for hilt tests:

2. [Instrumented tests with Hilt](hilt.md)
```groovy
// Contains HiltFragmentScenario
androidTestImplementation "com.rubensousa.carioca:hilt-fragment:{{ hilt.version }}"
Expand All @@ -32,26 +40,11 @@ debugImplementation "com.rubensousa.carioca:hilt-manifest:{{ hilt.version }}"
// Optional: default HiltTestRunner if you don't have your own
androidTestImplementation "com.rubensousa.carioca:hilt-runner:{{ hilt.version }}"
```

Other artifacts:

3. Junit4 rules
```groovy
// Contains RepeatTest and RetryTest
implementation "com.rubensousa.carioca:junit4-rules:{{ junit4_rules.version }}"
testImplementation "com.rubensousa.carioca:junit4-rules:{{ junit4_rules.version }}"
```

Jump to [this guide](test-reports-android.md) for how to integrate this library.


Motivation for this library:

1. I kept copying some of these classes around in multiple projects
2. Analysing the standard junit test reports when you have long UI tests gets frustrating
3. Consistent screen recording and screenshots across different screen resolutions
4. Flexible APIs for any test report format
5. No enforced inheritance in test classes unlike other testing libraries


## License

Copyright 2024 Rúben Sousa
Expand Down
71 changes: 31 additions & 40 deletions docs/test-reports-android.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,22 +33,31 @@ class SampleTest {
!!! note
Use different orders for your rules in case you have multiple of them and assign the lowest value to `TestReportRule`.
This ensures that it starts before all other rules you have in your test suite.
Example: `@get:Rule(order = Int.MIN_VALUE)`
Example: `@get:Rule(order = 0)` for the report rule and `order = 1` for the next rule

This basic setup will achieve this out of the box:

1. Automatic screen recordings for every test
2. Automatic screenshot when the test fails
3. Automatic dumps of the view hierarchy if the test fails

## Visualize reports

The test reports are generated automatically after running any task like `connectedDebugAndroidTest`
and can be found in `build/outputs/connected_android_test_additional_output/**/carioca-report`.

By default, those reports are in json format and are not really easily readable.
To visualize them properly, this library ships with an [Allure](https://allurereport.org/) plugin that can be used to generate test reports based on
the metadata collected through each test execution. Check it out in [this page](android-allure-plugin.md).


## Test structure

### Test body

You can decorate your tests with individual reports for every execution step:

```kotlin
```kotlin linenums="1"
@Test
fun testHomeIsDisplayedAfterQuickSettings() = report {

Expand All @@ -71,7 +80,7 @@ fun testHomeIsDisplayedAfterQuickSettings() = report {

Optionally, `Given`, `When`, `Then` statements from BDD are also available to describe your tests:

```kotlin
```kotlin linenums="1"
@Test
fun testHomeIsDisplayedAfterQuickSettings() = report {

Expand All @@ -96,7 +105,7 @@ fun testHomeIsDisplayedAfterQuickSettings() = report {
If you have re-usable logic in `@Before` or `@After` that you want to include in your reports,
just use the following APIs:

```kotlin
```kotlin linenums="1"
@Before
fun before() = report.before {
step("Press home") {
Expand All @@ -119,7 +128,7 @@ fun after() = report.after {

The library includes an `InstrumentedScenario` which allows you to re-use a set of steps across multiple tests:

```kotlin
```kotlin linenums="1"
class ClickNotification : InstrumentedScenario("Click Notification") {

private val device = UiDevice.getInstance(
Expand Down Expand Up @@ -152,7 +161,7 @@ class ClickNotification : InstrumentedScenario("Click Notification") {

Then, in your tests, can use it like so:

```kotlin
```kotlin linenums="1" hl_lines="9"
@Test
fun testAppOpensHomeAfterClickingNotification() = report {

Expand All @@ -170,11 +179,11 @@ fun testAppOpensHomeAfterClickingNotification() = report {
}
```

## Test descriptions
### Extra metadata

Using `@TestReport` allows you to describe your tests in more detail:

```kotlin
```kotlin linenums="1"
@TestReport(
id = "TicketID",
title = "App opens home after notification click",
Expand All @@ -187,42 +196,35 @@ Using `@TestReport` allows you to describe your tests in more detail:
)
@Test
fun testAppOpensHomeAfterClickingNotification() = report {

step("Trigger notification") {
sendNotificationIntent()
}

// Or When(ClickNotification())
scenario(ClickNotification())

step("Home screen is visible") {
assertHomeScreenDisplayed()
}

// Test body
}
```

## Recording options

To override the recording options for individual tests, use `@TestRecording`:

```kotlin
```kotlin linenums="1"
// Disables screen recording for this test only
@TestRecording(
scale = 1.0f,
keepOnSuccess = true,
enabled = false
)
@Test
fun testSomething() {
fun fastTestThatShouldFinishInLessThan1Second() {
}
```

```kotlin
// Disables screen recording for this test only
Or also:

```kotlin linenums="1"
// Records this test in landscape mode
// and keeps the recording file even if the test passes
@TestRecording(
enabled = false
keepOnSuccess = true,
orientation = RecordingOrientation.LANDSCAPE
)
@Test
fun fastTestThatShouldFinishInLessThan1Second() {
fun testInLandscape() {
}
```

Expand All @@ -233,7 +235,7 @@ This configuration will replace the `RecordingOptions` from `InstrumentedReportR

To override the screenshot options for individual tests, use `@TestScreenshot`:

```kotlin
```kotlin linenums="1"
@TestScreenshot(
scale = 1.0f,
format = Bitmap.CompressFormat.PNG,
Expand All @@ -244,14 +246,3 @@ fun testSomething() {
```

This configuration will replace the `ScreenshotOptions` from `InstrumentedReportRule`

## Test reports

The test reports are generated automatically after running any task like `connectedDebugAndroidTest`
and can be found in `build/outputs/connected_android_test_additional_output/**/carioca-report`.

By default, those reports are in json format and are not really easily readable.
To visualize them properly, this library ships with an [Allure](https://allurereport.org/) plugin that can be used to generate test reports based on
the metadata collected through each test execution. Check it out in [this page](android-allure-plugin.md).


2 changes: 1 addition & 1 deletion settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ include(":carioca-hilt:carioca-hilt-runner")
include(":carioca-junit4-rules")
include(":carioca-report:report-junit4")
include(":carioca-report:report-android")
include(":carioca-report:report-android-allure-gradle-plugin")
include(":carioca-report-allure-gradle-plugin")
include(":carioca-report:report-android-coroutines")
include(":carioca-report:report-runtime")
include(":carioca-report:report-json")
Expand Down

0 comments on commit 10d1129

Please sign in to comment.