Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix getInstrumentation() before super.onCreate runner, lazy obtain directory for test results (issue #67) #68

Merged
merged 2 commits into from
Mar 1, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import io.qameta.allure.kotlin.FileSystemResultsWriter
import io.qameta.allure.kotlin.util.PropertiesUtils
import java.io.File

object AllureAndroidLifecycle : AllureLifecycle(writer = FileSystemResultsWriter(obtainResultsDirectory()))
object AllureAndroidLifecycle : AllureLifecycle(writer = FileSystemResultsWriter(::obtainResultsDirectory))

/**
* Obtains results directory as a [File] reference.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -503,7 +503,7 @@ open class AllureLifecycle @JvmOverloads constructor(

private fun getDefaultWriter(): FileSystemResultsWriter {
val path = PropertiesUtils.resultsDirectoryPath
return FileSystemResultsWriter(File(path))
return FileSystemResultsWriter { File(path) }
}

private fun getDefaultNotifier(): LifecycleNotifier {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@ import java.io.IOException
import java.io.InputStream
import java.util.UUID

class FileSystemResultsWriter(private val outputDirectory: File) : AllureResultsWriter {
class FileSystemResultsWriter(private val outputDirectoryProvider: () -> File) : AllureResultsWriter {

private val outputDirectory by lazy { outputDirectoryProvider() }

private val mapper: Json = Json {
prettyPrint = true
useArrayPolymorphism = true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,14 @@ import java.util.*
class FileSystemResultsWriterTest {
@Test
fun shouldNotFailIfNoResultsDirectory(@TempDir folder: File) {
val resolve = folder.resolve("some-directory")
val writer = FileSystemResultsWriter(resolve)
val writer = FileSystemResultsWriter { folder.resolve("some-directory") }
val testResult = generateTestResult()
writer.write(testResult)
}

@Test
fun shouldWriteTestResult(@TempDir folder: File) {
val writer = FileSystemResultsWriter(folder)
val writer = FileSystemResultsWriter { folder }
val uuid = UUID.randomUUID().toString()
val testResult = generateTestResult(uuid)
writer.write(testResult)
Expand Down