Skip to content

Commit

Permalink
Fix: Improve test setup for DocSerializationTest
Browse files Browse the repository at this point in the history
This change modifies the test setup for `DocSerializationTest` to improve its robustness and coverage.

-   Removes `showStandardStreams = true` from the roborazzi gradle config, to quiet down the amount of console spam
-   Adds the validation assets directory to the test resources for the common module.
-   Replaces the single `loadSaveLoadHelloWorld` test with a parameterized test `LoadSaveLoadAllDocsTest` to make it easier to see which docs aren't passing
-   Removes the `VariantAnimationTimelineTestDoc_vJRf4zxY4QX4zzSSUd1nJ5.dcf` file. The test is disabled right now ( #1945 ) so the dcf wasn't being updated and was failing to decode.
  • Loading branch information
timothyfroehlich committed Jan 10, 2025
1 parent 355455a commit b48f52d
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 39 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ project.pluginManager.withPlugin("com.android.base") {
showExceptions = true
showStackTraces = true
showCauses = true
showStandardStreams = true
exceptionFormat = TestExceptionFormat.FULL
}
}
Expand Down
4 changes: 1 addition & 3 deletions common/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,8 @@ sourceSets {
test {
resources.srcDirs(rootProject.rootDir.resolve("designcompose/src/main/assets"))
resources.srcDirs(
rootProject.rootDir.resolve("reference-apps/helloworld/helloworld-app/src/main/assets")
rootProject.rootDir.resolve("integration-tests/validation/src/main/assets")
)
// Enable testing of the Validation dcf files once we're able to serialize them again
// resources.srcDirs(rootProject.rootDir.resolve("integration-tests/validation/src/main/assets"))
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,12 @@ package com.android.designcompose.common

import java.io.InputStream
import kotlin.io.path.createTempFile
import kotlin.io.path.inputStream
import kotlin.io.path.toPath
import kotlin.test.assertNotNull
import org.junit.Test
import org.junit.runner.RunWith
import org.junit.runners.Parameterized

class DocSerializationTest {

Expand Down Expand Up @@ -49,50 +52,40 @@ class DocSerializationTest {

assertNotNull(decodeDiskBaseDoc(inputStream, DesignDocId("test_doc"), Feedback))
}
}

@RunWith(Parameterized::class)
class LoadSaveLoadAllDocsTest(private val fileName: String, private val docName: String) {
companion object {
@JvmStatic
@Parameterized.Parameters(name = "{index}: {1}")
fun data(): Collection<Array<String>> {
val resourcesUrl =
LoadSaveLoadAllDocsTest::class.java.classLoader!!.getResource("figma")
val resourcesFile = resourcesUrl?.toURI()?.toPath()?.toFile()

return resourcesFile!!
.walk()
.filter { it.name.endsWith(".dcf") }
.map { it.name }
.toList()
.map { arrayOf(it, it.substringBefore("Doc")) }
}
}

@Test
fun loadSaveLoadHelloWorld() {
fun loadSaveLoad() {
val inputStream: InputStream =
DocSerializationTest::class
LoadSaveLoadAllDocsTest::class
.java
.classLoader!!
.getResourceAsStream("figma/HelloWorldDoc_pxVlixodJqZL95zo2RzTHl.dcf")!!
assertNotNull(inputStream)
val doc = decodeDiskBaseDoc(inputStream, DesignDocId("loadSaveLoad"), Feedback)
.getResourceAsStream("figma/$fileName")!!
val doc = decodeDiskBaseDoc(inputStream, DesignDocId(fileName), Feedback)
assertNotNull(doc)
val savedDoc = createTempFile()
doc.save(savedDoc.toFile(), Feedback)
val loadedDoc =
decodeDiskBaseDoc(
savedDoc.toFile().inputStream(),
DesignDocId("loadSaveLoad"),
Feedback,
)
decodeDiskBaseDoc(savedDoc.toFile().inputStream(), DesignDocId(fileName), Feedback)
assertNotNull(loadedDoc)
}

// Iterate through all dcf files in the figma/ directory and test them
@Test
fun loadSaveLoadAllDocs() {
val resourcesUrl = DocSerializationTest::class.java.classLoader!!.getResource("figma")
val resourcesFile = resourcesUrl?.toURI()?.toPath()?.toFile()

resourcesFile!!
.walkTopDown()
.filter { it.name.endsWith(".dcf") }
.forEach { file ->
println("Testing ${file.name}")
val doc = decodeDiskBaseDoc(file.inputStream(), DesignDocId(file.name), Feedback)
assertNotNull(doc)
val savedDoc = createTempFile()
doc.save(savedDoc.toFile(), Feedback)
val loadedDoc =
decodeDiskBaseDoc(
savedDoc.toFile().inputStream(),
DesignDocId(file.name),
Feedback,
)
assertNotNull(loadedDoc)
}
}
}
Binary file not shown.

0 comments on commit b48f52d

Please sign in to comment.