-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add test reporting * Simplify Fiebase Test Lab plugin, proper computing of passed property * Bette formatting into method * Error to make tests fail * Fixed failed test * Add passsed and tests count * Asserting on exit code * Intoduce test failure * Print exit code * Extract the Firebase link * Fir error test * Try to fix the TeeOutputStream * Set error streamas well * Setting only error stream
- Loading branch information
Showing
11 changed files
with
464 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 5 additions & 0 deletions
5
plugins/src/main/java/com/jraska/github/client/firebase/TestResultReporter.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package com.jraska.github.client.firebase | ||
|
||
interface TestResultReporter { | ||
fun report(results: TestSuiteResult) | ||
} |
36 changes: 36 additions & 0 deletions
36
plugins/src/main/java/com/jraska/github/client/firebase/TestSuiteResult.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package com.jraska.github.client.firebase | ||
|
||
import com.jraska.gradle.git.GitInfo | ||
|
||
data class TestSuiteResult( | ||
val testResults: List<TestResult>, | ||
val time: Double, | ||
val suitePassed: Boolean, | ||
val testsCount: Int, | ||
val failedCount: Int, | ||
val errorsCount: Int, | ||
val passedCount: Int, | ||
val ignoredCount: Int, | ||
val flakyCount: Int, | ||
val firebaseUrl: String, | ||
val gitInfo: GitInfo, | ||
val device: String | ||
) | ||
|
||
data class TestResult( | ||
val outcome: TestOutcome, | ||
val className: String, | ||
val methodName: String, | ||
val time: Double, | ||
val fullName: String, | ||
val gitInfo: GitInfo, | ||
val firebaseUrl: String, | ||
val failure: String?, | ||
val device: String | ||
) | ||
|
||
enum class TestOutcome { | ||
PASSED, | ||
FAILED, | ||
FLAKY | ||
} |
10 changes: 10 additions & 0 deletions
10
plugins/src/main/java/com/jraska/github/client/firebase/report/ConsoleTestResultReporter.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package com.jraska.github.client.firebase.report | ||
|
||
import com.jraska.github.client.firebase.TestResultReporter | ||
import com.jraska.github.client.firebase.TestSuiteResult | ||
|
||
class ConsoleTestResultReporter : TestResultReporter { | ||
override fun report(results: TestSuiteResult) { | ||
println(results) | ||
} | ||
} |
90 changes: 90 additions & 0 deletions
90
plugins/src/main/java/com/jraska/github/client/firebase/report/FirebaseResultExtractor.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
package com.jraska.github.client.firebase.report | ||
|
||
import com.jraska.github.client.firebase.TestOutcome | ||
import com.jraska.github.client.firebase.TestResult | ||
import com.jraska.github.client.firebase.TestSuiteResult | ||
import com.jraska.gradle.git.GitInfo | ||
import groovy.util.Node | ||
import groovy.util.NodeList | ||
import groovy.util.XmlParser | ||
|
||
class FirebaseResultExtractor( | ||
val firebaseUrl: String, | ||
val gitInfo: GitInfo, | ||
val device: String | ||
) { | ||
fun extract(xml: String): TestSuiteResult { | ||
val testSuiteNode = XmlParser().parseText(xml) | ||
|
||
val testsCount = testSuiteNode.attributeInt("tests") | ||
val flakyTests = testSuiteNode.attributeInt("flakes") | ||
val ignoredCount = testSuiteNode.attributeInt("skipped") | ||
val failedCount = testSuiteNode.attributeInt("failures") | ||
val errorsCount = testSuiteNode.attributeInt("errors") | ||
val time = testSuiteNode.attributeDouble("time") | ||
val passedCount = testsCount - ignoredCount - failedCount - errorsCount | ||
|
||
val tests = (testSuiteNode.get("testcase") as NodeList) | ||
.map { it as Node } | ||
.filter { it.attributeString("name") != "null" } | ||
.map { parseTestResult(it) } | ||
|
||
val suitePassed = errorsCount == 0 && failedCount == 0 | ||
|
||
return TestSuiteResult( | ||
testResults = tests, | ||
time = time, | ||
testsCount = testsCount, | ||
device = device, | ||
gitInfo = gitInfo, | ||
firebaseUrl = firebaseUrl, | ||
errorsCount = errorsCount, | ||
passedCount = passedCount, | ||
failedCount = failedCount, | ||
flakyCount = flakyTests, | ||
ignoredCount = ignoredCount, | ||
suitePassed = suitePassed | ||
) | ||
} | ||
|
||
private fun parseTestResult(testNode: Node): TestResult { | ||
val flaky = testNode.attributeBoolean("flaky") | ||
val failure = ((testNode.get("failure") as NodeList?)?.firstOrNull() as Node?)?.text() ?: "" | ||
|
||
val outcome = when { | ||
flaky -> TestOutcome.FLAKY | ||
failure.isNotEmpty() -> TestOutcome.FAILED | ||
else -> TestOutcome.PASSED | ||
} | ||
|
||
val methodName = testNode.attributeString("name") | ||
val className = testNode.attributeString("classname") | ||
return TestResult( | ||
methodName = methodName, | ||
className = className, | ||
time = testNode.attributeDouble("time"), | ||
failure = failure, | ||
outcome = outcome, | ||
firebaseUrl = firebaseUrl, | ||
gitInfo = gitInfo, | ||
device = device, | ||
fullName = "$className#$methodName" | ||
) | ||
} | ||
|
||
private fun Node.attributeInt(name: String): Int { | ||
return attribute(name)?.toString()?.toInt() ?: 0 | ||
} | ||
|
||
private fun Node.attributeDouble(name: String): Double { | ||
return attribute(name).toString().toDouble() | ||
} | ||
|
||
private fun Node.attributeString(name: String): String { | ||
return attribute(name).toString() | ||
} | ||
|
||
private fun Node.attributeBoolean(name: String): Boolean { | ||
return attribute(name)?.toString()?.toBoolean() ?: false | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
plugins/src/main/java/com/jraska/github/client/firebase/report/FirebaseUrlParser.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package com.jraska.github.client.firebase.report | ||
|
||
object FirebaseUrlParser { | ||
private val urlPattern = """Test results will be streamed to \[(\S*)\]""".toPattern() | ||
|
||
fun parse(output: String): String { | ||
val matcher = urlPattern.matcher(output) | ||
|
||
matcher.find() | ||
return matcher.group(1) | ||
} | ||
} |
69 changes: 69 additions & 0 deletions
69
...ins/src/main/java/com/jraska/github/client/firebase/report/MixpanelTestResultsReporter.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
package com.jraska.github.client.firebase.report | ||
|
||
import com.jraska.github.client.firebase.TestResult | ||
import com.jraska.github.client.firebase.TestResultReporter | ||
import com.jraska.github.client.firebase.TestSuiteResult | ||
import com.mixpanel.mixpanelapi.ClientDelivery | ||
import com.mixpanel.mixpanelapi.MessageBuilder | ||
import com.mixpanel.mixpanelapi.MixpanelAPI | ||
import org.json.JSONObject | ||
|
||
class MixpanelTestResultsReporter( | ||
private val apiKey: String, | ||
private val api: MixpanelAPI | ||
) : TestResultReporter { | ||
override fun report(results: TestSuiteResult) { | ||
val delivery = ClientDelivery() | ||
|
||
val properties = convertTestSuite(results) | ||
val messageBuilder = MessageBuilder(apiKey) | ||
val moduleEvent = messageBuilder | ||
.event(SINGLE_NAME_FOR_TEST_REPORTS_USER, "Android Test Suite Firebase", JSONObject(properties)) | ||
|
||
delivery.addMessage(moduleEvent) | ||
|
||
results.testResults.forEach { | ||
val testProperties = convertSingleTest(it) | ||
|
||
val estateEvent = messageBuilder.event(SINGLE_NAME_FOR_TEST_REPORTS_USER, "Android Test Firebase", JSONObject(testProperties)) | ||
delivery.addMessage(estateEvent) | ||
} | ||
|
||
api.deliver(delivery) | ||
|
||
println("$FLAG_ICON Test result reported to Mixpanel $FLAG_ICON") | ||
} | ||
|
||
private fun convertSingleTest(testResult: TestResult): Map<String, Any?> { | ||
return mutableMapOf<String, Any?>( | ||
"className" to testResult.className, | ||
"methodName" to testResult.methodName, | ||
"device" to testResult.device, | ||
"firebaseUrl" to testResult.firebaseUrl, | ||
"fullName" to testResult.fullName, | ||
"failure" to testResult.failure, | ||
"outcome" to testResult.outcome, | ||
"testTime" to testResult.time | ||
).apply { putAll(testResult.gitInfo.asAnalyticsProperties()) } | ||
} | ||
|
||
private fun convertTestSuite(results: TestSuiteResult): Map<String, Any?> { | ||
return mutableMapOf<String, Any?>( | ||
"passed" to results.suitePassed, | ||
"suiteTime" to results.time, | ||
"device" to results.device, | ||
"firebaseUrl" to results.firebaseUrl, | ||
"passedCount" to results.passedCount, | ||
"testsCount" to results.testsCount, | ||
"ignoredCount" to results.ignoredCount, | ||
"flakyCount" to results.flakyCount, | ||
"failedCount" to results.failedCount, | ||
"errorsCount" to results.errorsCount | ||
).apply { putAll(results.gitInfo.asAnalyticsProperties()) } | ||
} | ||
|
||
companion object { | ||
private val FLAG_ICON = "\uD83C\uDFC1" | ||
private val SINGLE_NAME_FOR_TEST_REPORTS_USER = "Test Reporter" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.