This repository has been archived by the owner on Dec 7, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Generate separate json files per test. (#31)
- Loading branch information
1 parent
d14f3f0
commit 6b6e1b0
Showing
11 changed files
with
224 additions
and
20 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
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
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
41 changes: 41 additions & 0 deletions
41
composer/src/main/kotlin/com/gojuno/composer/html/HtmlShortTest.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,41 @@ | ||
package com.gojuno.composer.html | ||
|
||
import com.google.gson.annotations.SerializedName | ||
|
||
data class HtmlShortTest( | ||
|
||
@SerializedName("id") | ||
val id: String, | ||
|
||
@SerializedName("package_name") | ||
val packageName: String, | ||
|
||
@SerializedName("class_name") | ||
val className: String, | ||
|
||
@SerializedName("name") | ||
val name: String, | ||
|
||
@SerializedName("duration_millis") | ||
val durationMillis: Long, | ||
|
||
@SerializedName("status") | ||
val status: HtmlFullTest.Status, | ||
|
||
@SerializedName("deviceId") | ||
val deviceId: String, | ||
|
||
@SerializedName("properties") | ||
val properties: Map<String, Any> | ||
) | ||
|
||
fun HtmlFullTest.toHtmlShortTest() = HtmlShortTest( | ||
id = id, | ||
packageName = packageName, | ||
className = className, | ||
name = name, | ||
durationMillis = durationMillis, | ||
status = status, | ||
deviceId = deviceId, | ||
properties = properties | ||
) |
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
110 changes: 110 additions & 0 deletions
110
composer/src/test/kotlin/com/gojuno/composer/html/HtmlReportSpec.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,110 @@ | ||
package com.gojuno.composer.html | ||
|
||
import com.gojuno.commander.android.AdbDevice | ||
import com.gojuno.composer.AdbDeviceTest | ||
import com.gojuno.composer.Device | ||
import com.gojuno.composer.Suite | ||
import com.gojuno.composer.perform | ||
import com.google.gson.Gson | ||
import org.assertj.core.api.Assertions.assertThat | ||
import org.jetbrains.spek.api.Spek | ||
import org.jetbrains.spek.api.dsl.context | ||
import org.jetbrains.spek.api.dsl.it | ||
import rx.observers.TestSubscriber | ||
import java.io.File | ||
import java.util.concurrent.TimeUnit.MILLISECONDS | ||
import java.util.concurrent.TimeUnit.SECONDS | ||
|
||
class HtmlReportSpec : Spek({ | ||
|
||
context("writeHtmlReport") { | ||
|
||
val adbDevice1 = AdbDevice( | ||
id = "device1", | ||
online = true | ||
) | ||
|
||
val suites = listOf( | ||
Suite( | ||
testPackage = "com.gojuno.example1", | ||
devices = listOf(Device(id = "device1", logcat = File("device1.logcat"), instrumentationOutput = File("device1.instrumentation"))), | ||
tests = listOf( | ||
AdbDeviceTest( | ||
adbDevice = adbDevice1, | ||
className = "com.gojuno.example1.TestClass", | ||
testName = "test1", | ||
durationNanos = MILLISECONDS.toNanos(1234), | ||
status = AdbDeviceTest.Status.Passed, | ||
logcat = File("com.gojuno.example1.TestClass", "test1.logcat"), | ||
files = listOf(File("com.gojuno.example1.TestClass.test1", "file1"), File("com.gojuno.example1.TestClass.test1", "file2")), | ||
screenshots = listOf(File("com.gojuno.example1.TestClass.test1", "screenshot1"), File("com.gojuno.example1.TestClass.test1", "screenshot2")) | ||
), | ||
AdbDeviceTest( | ||
adbDevice = adbDevice1, | ||
className = "com.gojuno.example1.TestClass", | ||
testName = "test2", | ||
durationNanos = MILLISECONDS.toNanos(1234), | ||
status = AdbDeviceTest.Status.Failed(stacktrace = "abc"), | ||
logcat = File("com.gojuno.example1.TestClass", "test2.logcat"), | ||
files = listOf(File("com.gojuno.example1.TestClass.test2", "file1"), File("com.gojuno.example1.TestClass.test2", "file2")), | ||
screenshots = listOf(File("com.gojuno.example1.TestClass.test2", "screenshot1"), File("com.gojuno.example1.TestClass.test2", "screenshot2")) | ||
) | ||
), | ||
passedCount = 2, | ||
ignoredCount = 0, | ||
failedCount = 1, | ||
durationNanos = MILLISECONDS.toNanos(1234 * 2), | ||
timestampMillis = 1805 | ||
) | ||
) | ||
|
||
val outputDir by memoized { File("${System.nanoTime()}") } | ||
|
||
val subscriber = TestSubscriber<Unit>() | ||
|
||
fun File.deleteOnExitRecursively() { | ||
when (isDirectory) { | ||
false -> deleteOnExit() | ||
true -> listFiles()?.forEach { inner -> inner.deleteOnExitRecursively()} | ||
} | ||
} | ||
|
||
perform { | ||
writeHtmlReport(Gson(), suites, outputDir).subscribe(subscriber) | ||
subscriber.awaitTerminalEvent(5, SECONDS) | ||
outputDir.deleteOnExitRecursively() | ||
} | ||
|
||
it("completes") { | ||
subscriber.assertCompleted() | ||
} | ||
|
||
it("does not emit error") { | ||
subscriber.assertNoErrors() | ||
} | ||
|
||
it("creates index.json") { | ||
assertThat(File(outputDir, "index.json").readText()).isEqualTo( | ||
"""{"suites":[{"id":"0","passed_count":2,"ignored_count":0,"failed_count":1,"duration_millis":2468,"devices":[{"id":"device1","logcat_path":"device1.logcat","instrumentation_output_path":"device1.instrumentation"}]}]}""" | ||
) | ||
} | ||
|
||
it("creates suite json") { | ||
assertThat(File(File(outputDir, "suites"), "0.json").readText()).isEqualTo( | ||
"""{"id":"0","tests":[{"id":"com.gojuno.example1TestClasstest1","package_name":"com.gojuno.example1","class_name":"TestClass","name":"test1","duration_millis":1234,"status":"passed","deviceId":"device1","properties":{}},{"id":"com.gojuno.example1TestClasstest2","package_name":"com.gojuno.example1","class_name":"TestClass","name":"test2","duration_millis":1234,"status":"failed","deviceId":"device1","properties":{}}],"passed_count":2,"ignored_count":0,"failed_count":1,"duration_millis":2468,"devices":[{"id":"device1","logcat_path":"device1.logcat","instrumentation_output_path":"device1.instrumentation"}]}""" | ||
) | ||
} | ||
|
||
it("creates json for 1st test") { | ||
assertThat(File(File(File(File(outputDir, "suites"), "0"), "device1"), "com.gojuno.example1TestClasstest1.json").readText()).isEqualTo( | ||
"""{"package_name":"com.gojuno.example1","class_name":"TestClass","name":"test1","id":"com.gojuno.example1TestClasstest1","duration_millis":1234,"status":"passed","logcat_path":"com.gojuno.example1.TestClass/test1.logcat","deviceId":"device1","properties":{},"file_paths":["com.gojuno.example1.TestClass.test1/file1","com.gojuno.example1.TestClass.test1/file2"],"screenshots_paths":["com.gojuno.example1.TestClass.test1/screenshot1","com.gojuno.example1.TestClass.test1/screenshot2"]}""" | ||
) | ||
} | ||
|
||
it("creates json for 2nd test") { | ||
assertThat(File(File(File(File(outputDir, "suites"), "0"), "device1"), "com.gojuno.example1TestClasstest2.json").readText()).isEqualTo( | ||
"""{"package_name":"com.gojuno.example1","class_name":"TestClass","name":"test2","id":"com.gojuno.example1TestClasstest2","duration_millis":1234,"status":"failed","stacktrace":"abc","logcat_path":"com.gojuno.example1.TestClass/test2.logcat","deviceId":"device1","properties":{},"file_paths":["com.gojuno.example1.TestClass.test2/file1","com.gojuno.example1.TestClass.test2/file2"],"screenshots_paths":["com.gojuno.example1.TestClass.test2/screenshot1","com.gojuno.example1.TestClass.test2/screenshot2"]}""" | ||
) | ||
} | ||
} | ||
}) |
41 changes: 41 additions & 0 deletions
41
composer/src/test/kotlin/com/gojuno/composer/html/HtmlShortTestSpec.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,41 @@ | ||
package com.gojuno.composer.html | ||
|
||
import org.assertj.core.api.Assertions.assertThat | ||
import org.jetbrains.spek.api.Spek | ||
import org.jetbrains.spek.api.dsl.context | ||
import org.jetbrains.spek.api.dsl.it | ||
|
||
class HtmlShortTestSpec : Spek({ | ||
|
||
context("HtmlFullTest.toHtmlShortTest") { | ||
|
||
val htmlFullTest = HtmlFullTest( | ||
packageName = "com.gojuno.example", | ||
className = "TestClass", | ||
name = "test1", | ||
status = HtmlFullTest.Status.Passed, | ||
durationMillis = 1234, | ||
stacktrace = null, | ||
logcatPath = "testLogcatPath", | ||
filePaths = listOf("testFilePath1", "testFilePath2"), | ||
screenshotsPaths = listOf("testScreenshotPath1", "testScreenshotPath2"), | ||
deviceId = "test-device-id", | ||
properties = mapOf("key1" to "value1", "key2" to "value2") | ||
) | ||
|
||
val htmlShortTest = htmlFullTest.toHtmlShortTest() | ||
|
||
it("converts HtmlFullTest to HtmlShortTest") { | ||
assertThat(htmlShortTest).isEqualTo(HtmlShortTest( | ||
id = htmlFullTest.id, | ||
packageName = "com.gojuno.example", | ||
className = "TestClass", | ||
name = "test1", | ||
status = HtmlFullTest.Status.Passed, | ||
durationMillis = 1234, | ||
deviceId = "test-device-id", | ||
properties = mapOf("key1" to "value1", "key2" to "value2") | ||
)) | ||
} | ||
} | ||
}) |
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