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

Data scratch - junit test result #1757

Closed
jan-goral opened this issue Mar 29, 2021 · 0 comments · Fixed by #1884
Closed

Data scratch - junit test result #1757

jan-goral opened this issue Mar 29, 2021 · 0 comments · Fixed by #1884

Comments

@jan-goral
Copy link
Contributor

Plan

According to the specification described in epic #1727
add abstraction and implementation for the following part of the data layer:

Abstraction

ftl/data/JUnitTestResult.kt

package ftl.data

val generateJUnitTestResultFromApi: JUnitTest.Result.GenerateFromApi get() = TODO()
val parseJUnitTestResultFromFiles: JUnitTest.Result.ParseFromFiles get() = TODO()

object JUnitTest {

    @JacksonXmlRootElement(localName = "testsuites")
    data class Result(
        @JsonInclude(JsonInclude.Include.NON_EMPTY)
        @JacksonXmlProperty(localName = "testsuite")
        var testsuites: MutableList<Suite>? = null
    ) {
        data class ApiIdentity(
            val projectId: String,
            val matrixIds: List<String>
        )

        interface GenerateFromApi : (ApiIdentity) -> Result

        interface ParseFromFiles : (File) -> Result
    }

    data class Suite(
        @JacksonXmlProperty(isAttribute = true)
        var name: String,

        @JacksonXmlProperty(isAttribute = true)
        var tests: String, // Int

        @JacksonXmlProperty(isAttribute = true)
        var failures: String, // Int

        @JacksonXmlProperty(isAttribute = true)
        var flakes: Int? = null,

        @JacksonXmlProperty(isAttribute = true)
        var errors: String, // Int

        @JsonInclude(JsonInclude.Include.NON_NULL)
        @JacksonXmlProperty(isAttribute = true)
        var skipped: String?, // Int. Android only

        @JacksonXmlProperty(isAttribute = true)
        var time: String, // Double

        @JsonInclude(JsonInclude.Include.NON_NULL)
        @JacksonXmlProperty(isAttribute = true)
        val timestamp: String?, // String. Android only

        @JacksonXmlProperty(isAttribute = true)
        val hostname: String? = "localhost", // String.

        @JsonInclude(JsonInclude.Include.NON_NULL)
        @JacksonXmlProperty(isAttribute = true)
        val testLabExecutionId: String? = null, // String.

        @JacksonXmlProperty(localName = "testcase")
        var testcases: MutableCollection<Case>?,

        // not used
        @JsonInclude(JsonInclude.Include.NON_NULL)
        val properties: Any? = null, // <properties />

        @JsonInclude(JsonInclude.Include.NON_NULL)
        @JacksonXmlProperty(localName = "system-out")
        val systemOut: Any? = null, // <system-out />

        @JsonInclude(JsonInclude.Include.NON_NULL)
        @JacksonXmlProperty(localName = "system-err")
        val systemErr: Any? = null // <system-err />
    )

    data class Case(
        // name, classname, and time are always present except for empty test cases <testcase/>
        @JacksonXmlProperty(isAttribute = true)
        val name: String?,

        @JacksonXmlProperty(isAttribute = true)
        val classname: String?,

        @JacksonXmlProperty(isAttribute = true)
        val time: String?,

        // iOS contains multiple failures for a single test.
        // JUnit XML allows arbitrary amounts of failure/error tags
        @JsonInclude(JsonInclude.Include.NON_NULL)
        @JacksonXmlProperty(localName = "failure")
        val failures: List<String>? = null,

        @JsonInclude(JsonInclude.Include.NON_NULL)
        @JacksonXmlProperty(localName = "error")
        val errors: List<String>? = null,

        @JsonInclude(JsonInclude.Include.CUSTOM, valueFilter = FilterNotNull::class)
        val skipped: String? = "absent" // used by FilterNotNull to filter out absent `skipped` values
    ) {

        // Consider to move all properties to constructor if will doesn't conflict with parser

        @JsonInclude(JsonInclude.Include.NON_NULL)
        var webLink: String? = null

        @JacksonXmlProperty(isAttribute = true)
        var flaky: Boolean? = null // use null instead of false
    }

    @Suppress("UnusedPrivateClass")
    private class FilterNotNull {
        override fun equals(other: Any?): Boolean {
            // other is null     = present
            // other is not null = absent (default value)
            return other != null
        }

        override fun hashCode(): Int {
            return javaClass.hashCode()
        }
    }
}

Target

  • ReportManager/generate -> ReportManager/parseTestSuite
    • ReportManager/processXmlFromFile
    • refreshMatricesAndGetExecutions -> List<TestExecution>/createJUnitTestResult

Adapter

ftl/adapter/GoogleJUnitTestParse.kt
ftl/adapter/GoogleJUnitTestFetch.kt

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants