|
| 1 | +package com.gojuno.composer.html |
| 2 | + |
| 3 | +import com.gojuno.commander.android.AdbDevice |
| 4 | +import com.gojuno.composer.AdbDeviceTest |
| 5 | +import com.gojuno.composer.Device |
| 6 | +import com.gojuno.composer.Suite |
| 7 | +import com.gojuno.composer.perform |
| 8 | +import com.google.gson.Gson |
| 9 | +import org.assertj.core.api.Assertions.assertThat |
| 10 | +import org.jetbrains.spek.api.Spek |
| 11 | +import org.jetbrains.spek.api.dsl.context |
| 12 | +import org.jetbrains.spek.api.dsl.it |
| 13 | +import rx.observers.TestSubscriber |
| 14 | +import java.io.File |
| 15 | +import java.util.concurrent.TimeUnit.MILLISECONDS |
| 16 | +import java.util.concurrent.TimeUnit.SECONDS |
| 17 | + |
| 18 | +class HtmlReportSpec : Spek({ |
| 19 | + |
| 20 | + context("writeHtmlReport") { |
| 21 | + |
| 22 | + val adbDevice1 = AdbDevice( |
| 23 | + id = "device1", |
| 24 | + online = true |
| 25 | + ) |
| 26 | + |
| 27 | + val suites = listOf( |
| 28 | + Suite( |
| 29 | + testPackage = "com.gojuno.example1", |
| 30 | + devices = listOf(Device(id = "device1", logcat = File("device1.logcat"), instrumentationOutput = File("device1.instrumentation"))), |
| 31 | + tests = listOf( |
| 32 | + AdbDeviceTest( |
| 33 | + adbDevice = adbDevice1, |
| 34 | + className = "com.gojuno.example1.TestClass", |
| 35 | + testName = "test1", |
| 36 | + durationNanos = MILLISECONDS.toNanos(1234), |
| 37 | + status = AdbDeviceTest.Status.Passed, |
| 38 | + logcat = File("com.gojuno.example1.TestClass", "test1.logcat"), |
| 39 | + files = listOf(File("com.gojuno.example1.TestClass.test1", "file1"), File("com.gojuno.example1.TestClass.test1", "file2")), |
| 40 | + screenshots = listOf(File("com.gojuno.example1.TestClass.test1", "screenshot1"), File("com.gojuno.example1.TestClass.test1", "screenshot2")) |
| 41 | + ), |
| 42 | + AdbDeviceTest( |
| 43 | + adbDevice = adbDevice1, |
| 44 | + className = "com.gojuno.example1.TestClass", |
| 45 | + testName = "test2", |
| 46 | + durationNanos = MILLISECONDS.toNanos(1234), |
| 47 | + status = AdbDeviceTest.Status.Failed(stacktrace = "abc"), |
| 48 | + logcat = File("com.gojuno.example1.TestClass", "test2.logcat"), |
| 49 | + files = listOf(File("com.gojuno.example1.TestClass.test2", "file1"), File("com.gojuno.example1.TestClass.test2", "file2")), |
| 50 | + screenshots = listOf(File("com.gojuno.example1.TestClass.test2", "screenshot1"), File("com.gojuno.example1.TestClass.test2", "screenshot2")) |
| 51 | + ) |
| 52 | + ), |
| 53 | + passedCount = 2, |
| 54 | + ignoredCount = 0, |
| 55 | + failedCount = 1, |
| 56 | + durationNanos = MILLISECONDS.toNanos(1234 * 2), |
| 57 | + timestampMillis = 1805 |
| 58 | + ) |
| 59 | + ) |
| 60 | + |
| 61 | + val outputDir by memoized { File("${System.nanoTime()}") } |
| 62 | + |
| 63 | + val subscriber = TestSubscriber<Unit>() |
| 64 | + |
| 65 | + fun File.deleteOnExitRecursively() { |
| 66 | + when (isDirectory) { |
| 67 | + false -> deleteOnExit() |
| 68 | + true -> listFiles()?.forEach { inner -> inner.deleteOnExitRecursively()} |
| 69 | + } |
| 70 | + } |
| 71 | + |
| 72 | + perform { |
| 73 | + writeHtmlReport(Gson(), suites, outputDir).subscribe(subscriber) |
| 74 | + subscriber.awaitTerminalEvent(5, SECONDS) |
| 75 | + outputDir.deleteOnExitRecursively() |
| 76 | + } |
| 77 | + |
| 78 | + it("completes") { |
| 79 | + subscriber.assertCompleted() |
| 80 | + } |
| 81 | + |
| 82 | + it("does not emit error") { |
| 83 | + subscriber.assertNoErrors() |
| 84 | + } |
| 85 | + |
| 86 | + it("creates index.json") { |
| 87 | + assertThat(File(outputDir, "index.json").readText()).isEqualTo( |
| 88 | + """{"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"}]}]}""" |
| 89 | + ) |
| 90 | + } |
| 91 | + |
| 92 | + it("creates suite json") { |
| 93 | + assertThat(File(File(outputDir, "suites"), "0.json").readText()).isEqualTo( |
| 94 | + """{"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"}]}""" |
| 95 | + ) |
| 96 | + } |
| 97 | + |
| 98 | + it("creates json for 1st test") { |
| 99 | + assertThat(File(File(File(File(outputDir, "suites"), "0"), "device1"), "com.gojuno.example1TestClasstest1.json").readText()).isEqualTo( |
| 100 | + """{"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"]}""" |
| 101 | + ) |
| 102 | + } |
| 103 | + |
| 104 | + it("creates json for 2nd test") { |
| 105 | + assertThat(File(File(File(File(outputDir, "suites"), "0"), "device1"), "com.gojuno.example1TestClasstest2.json").readText()).isEqualTo( |
| 106 | + """{"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"]}""" |
| 107 | + ) |
| 108 | + } |
| 109 | + } |
| 110 | +}) |
0 commit comments