Skip to content

Conversation

@dhonti-axpe
Copy link
Contributor

@dhonti-axpe dhonti-axpe commented Nov 25, 2025

🎟️ Jira ticket

ANDROID-17148

🥅 What's the goal?

Fix an issue in the library that generates recorded log files with a duplicated .txt extension (e.g. TestClass_testMethod.txt.txt).
This duplicated extension breaks the comparison against the corresponding golden files, which are correctly defined with a single .txt extension.

🚧 How do we do it?

To fix this behaviour, it was updated the file-naming logic inside LogsRule so that the temporary log file generated during test execution no longer includes the .txt suffix.
This allows the Gradle plugin (AndroidSnaptestingPlugin) to correctly rename the latest generated recording to .txt without producing a double extension.

Implementation steps:

  • Remove the .txt suffix from the temporary filename created in LogsRule.
    • Before: ${testName}.txt.${System.nanoTime()}
    • After: ${testName}.${System.nanoTime()}
  • Keep the golden file name resolution untouched (<testName>.txt), ensuring full backwards compatibility.
  • Run connected tests to validate that recorded files now appear as <testName>.txt without duplication.
  • Verify that the plugin correctly groups and renames recordings without generating .txt.txt.

📘 Documentation changes?

  • No docs to update nor create

🧪 How can I test this?

  • Run any instrumented test that uses LogsRule, for example:
    ./gradlew :app:connectedDebugAndroidTest
  • After execution, inspect:
    app/build/reports/androidTests/connected/debug/androidSnapTesting/recorded/
  • Confirm that the generated file name has the format: <TestClass>_<method>.txt

@dhonti-axpe dhonti-axpe self-assigned this Nov 25, 2025
@dhonti-axpe dhonti-axpe marked this pull request as ready for review November 25, 2025 14:25
@dhonti-axpe dhonti-axpe requested review from a team, jeslat and juangardi21 and removed request for a team November 25, 2025 14:25
@jeslat
Copy link
Contributor

jeslat commented Nov 26, 2025

After moving Loggerazzi fixes to this library, we introduced some bugs. I've done two changes:

@pmartinbTEF pmartinbTEF self-requested a review November 26, 2025 08:37
val goldenFile = directories.context.assets.open("${directories.goldenFilesDir}/${testName}.txt")
val goldenStringLogs = String(goldenFile.readBytes()).takeIf { it.isNotEmpty() }?.split("\n") ?: emptyList()
val comparison = compare(goldenStringLogs)
writeRecordedLogsToFile(fileName, comparison.recordedLogs)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should it be reviewed screenshot tests too? they have similar logic

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've double-checked it, the ScreenshotsRule is saving the screenshots before failing the test so there isn't any problem in that case https://github.com/Telefonica/android-snaptesting/blob/main/android-snaptesting/src/main/java/com/telefonica/androidsnaptesting/screenshots/ScreenshotsRule.kt#L99

Copy link

@juangardi21 juangardi21 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice catch

Copy link

@pmartinbTEF pmartinbTEF left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good job!

@jeslat jeslat added the bug Something isn't working label Nov 26, 2025
@dhonti-axpe dhonti-axpe merged commit 37a4df0 into main Nov 26, 2025
1 check passed
@dhonti-axpe dhonti-axpe deleted the ANDROID-17148/fix-double-extension branch November 26, 2025 15:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants