Reputation: 161
I had issues creating the report and finally was able to solve it and generate an Allure report (with the help of ChatGPT). The issue is that no matter what I do, I can't see any annotations data like Step/DisaplayName/Description.
What I did is:
rm -rf build/allure-results/*
"this content of this file is:
<?xml version='1.0' encoding='UTF-8' ?>
<testsuite name="com.companyName.con.tests.PlayAds" tests="1" failures="0" errors="0" skipped="0" time="14.025" timestamp="2024-12-23T11:22:12" hostname="localhost">
<properties>
<property name="device" value="HD1900 - 11" />
<property name="flavor" value="" />
<property name="project" value=":app" />
</properties>
<testcase name="adOnLockScreenTest" classname="com.companyName.con.tests.PlayAds" time="11.617" />
</testsuite>
cp build/allure-results/debug/* build/allure-results/
This command creates another file with the same data
allure serve build/allure-results
This command opens the allure report with the correct result but without the annotations data
This is my gradle file:
plugins {
id 'com.android.application'
id 'kotlin-android'
id 'io.qameta.allure' version '2.12.0'
}
allure {
version = "2.29.1"
useJUnit4 {
version = "2.29.1"
}
}
tasks.register('copyTestResults', Copy) {
from(layout.buildDirectory.dir("test-results")) {
include '**/*.xml'
}
into layout.buildDirectory.dir("allure-results")
}
tasks.register('copyAndroidTestResults', Copy) {
from(layout.buildDirectory.dir("outputs/androidTest-results/connected")) {
include '**/*.xml'
}
into layout.buildDirectory.dir("allure-results")
}
tasks.withType(Test).configureEach {
finalizedBy 'copyTestResults' // Unit test results
}
tasks.matching { it.name == "connectedDebugAndroidTest" }.configureEach {
finalizedBy 'copyAndroidTestResults' // Instrumentation test results
}
tasks.withType(Test) {
useJUnit()
}
configurations {
allureCommandline
}
dependencies {
implementation project(':ads')
// Allure dependencies
// allureCommandline group: "io.qameta.allure", name: "allure-commandline", version: "2.32.0", ext: "zip"
implementation 'io.qameta.allure:allure-gradle:2.8.1'
implementation 'io.qameta.allure:allure-junit4-aspect:2.29.1'
/////////
androidTestImplementation 'io.qameta.allure:allure-kotlin-commons:2.4.0'
// implementation 'io.qameta.allure:allure-junit4-aspect:2.29.1'
androidTestImplementation 'io.qameta.allure:allure-kotlin-android:2.4.0'
androidTestImplementation 'io.qameta.allure:allure-junit4:2.29.1'
// Other dependencies
implementation ('ch.qos.logback:logback-classic:1.3.14') {
exclude group: 'META-INF', module: 'INDEX.LIST'
}
implementation ('ch.qos.logback:logback-core:1.3.14') {
exclude group: 'META-INF', module: 'INDEX.LIST'
}
// Kotlin dependencies
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.8.21"
runtimeOnly 'org.jetbrains.kotlin:kotlin-reflect:2.1.0'
// Android dependencies
implementation 'androidx.appcompat:appcompat:1.7.0'
implementation 'com.google.android.material:material:1.12.0'
androidTestImplementation 'androidx.test.ext:junit:1.2.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.6.1'
androidTestImplementation 'androidx.test:core:1.6.1'
androidTestImplementation 'androidx.test.uiautomator:uiautomator:2.3.0'
androidTestImplementation 'androidx.test:runner:1.6.2'
// JSON parsing
implementation "com.fasterxml.jackson.core:jackson-databind:2.15.2"
implementation "com.fasterxml.jackson.core:jackson-annotations:2.15.2"
implementation "com.fasterxml.jackson.module:jackson-module-kotlin:2.15.2"
implementation "com.fasterxml.jackson.core:jackson-core:2.15.2"
// Testing
testImplementation 'junit:junit:4.13.2'
}
android {
namespace 'com.callapp.contacts'
compileSdk 35
defaultConfig {
applicationId "com.callapp.contacts"
minSdk 26
targetSdk 34
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
testInstrumentationRunnerArguments clearPackageData: 'true'
}
buildFeatures {
buildConfig = true
}
packaging {
resources {
excludes += [
'META-INF/FastDoubleParser-LICENSE',
'META-INF/FastDoubleParser-NOTICE',
'META-INF/NOTICE.txt',
'META-INF/thirdparty-LICENSE',
'META-INF/INDEX.LIST',
'META-INF/DEPENDENCIES'
]
merges += ['META-INF/INDEX.LIST']
}
}
buildTypes {
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
signingConfig signingConfigs.debug
}
debug {
minifyEnabled false
signingConfig signingConfigs.debug
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_17
targetCompatibility JavaVersion.VERSION_17
}
kotlinOptions {
jvmTarget = '17'
}
lint {
abortOnError false
}
configurations.all {
resolutionStrategy.cacheChangingModulesFor 0, 'seconds'
exclude group: 'javax.activation', module: 'javax.activation-api'
}
}
This is my test class (It's messy because of all the things I tried using chatGpt:
package com.compamyName.con.tests
import android.graphics.Bitmap
import android.util.Log
import androidx.test.platform.app.InstrumentationRegistry
import com.callapp.contacts.BaseTest
import io.qameta.allure.kotlin.Attachment
import io.qameta.allure.kotlin.Description
import io.qameta.allure.kotlin.junit4.DisplayName
import org.junit.Before
import java.io.ByteArrayOutputStream
import io.qameta.allure.Allure
import io.qameta.allure.kotlin.Step
import org.junit.Test
class PlayAds : BaseTest(){
@Before
fun logAnnotations() {
Log.d("PlayAdsTest","Setting up Allure annotations for test")
Allure.getLifecycle().updateTestCase {
Log.d("PlayAdsTest","Updating test case: ${it.name}")
}
}
@Before
fun setupDebugging() {
val lifecycle = Allure.getLifecycle()
val currentTestCase = try {
lifecycle.getCurrentTestCase()
} catch (e: Exception) {
Log.e("PlayAdsTest", "Error getting current test case", e)
null
}
Log.d("PlayAdsTest", "Current lifecycle: $lifecycle")
Log.d("PlayAdsTest", "Current test case: $currentTestCase")
}
@Test
@DisplayName("Test no impression")
@Description("This test verifies that no impression")
fun adOnLockScreenTest() {
Allure.step("Step 1: Verify Allure works")
Log.d("PlayAdsTest", "Inside simpleTest")
Allure.step("Setting up test case details") { _: Allure.StepContext ->
Allure.getLifecycle().updateTestCase {
it.name = "Test no impression when device is locked"
it.description = "This test verifies that no impression"
}
}
Log.d("PlayAdsTest", "Entering testAdOnLockScreen")
try {
Allure.getLifecycle().updateTestCase {
Log.d("PlayAdsTest", "Updating test annotations inside test")
it.name = "Test no impression"
it.description = "This test verifies that no impression"
}
} catch (e: Exception) {
Log.e("PlayAdsTest", "Error updating test annotations in test", e)
}
Log.d("PlayAdsTest", "Exiting testAdOnLockScreen")
val adBider = getRandomBidder()
val layouts = nativeLayouts.random()
chooseAndRunAd(adBider, rndAdTypeNoInterstitial(), layouts)
Allure.step("Step 2: Lock device", Allure.ThrowableRunnable {
Log.d("PlayAdsTest", "Performing lock device")
lockDevice()
})
// lockDevice()
//Give time for first impression to be presented
Thread.sleep(5000)
val startTime = System.currentTimeMillis()
// Thread.sleep(20000)
Allure.step("Step 2: is device lock?", Allure.ThrowableRunnable {
Log.d("PlayAdsTest", "Performing check if device is locked")
isDeviceLocked()
})
handleMessages(startTime)
attachScreenshot()
}
@Attachment(value = "Screenshot", type = "image/png")
fun attachScreenshot(): ByteArray {
val device = InstrumentationRegistry.getInstrumentation().uiAutomation
val bitmap = device.takeScreenshot()
val stream = ByteArrayOutputStream()
bitmap.compress(Bitmap.CompressFormat.PNG, 100, stream)
return stream.toByteArray()
}
Upvotes: 0
Views: 84