Skip to content

Commit 9f7e890

Browse files
author
Daniel Jette
committed
wip
1 parent b4041fd commit 9f7e890

17 files changed

Lines changed: 61 additions & 109 deletions

File tree

Ext/src/main/java/com/shopify/testify/ext/TestHarnessActivity.kt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
2222
* THE SOFTWARE.
2323
*/
24+
@file:Suppress("deprecation")
25+
2426
package com.shopify.testify.ext
2527

2628
import android.graphics.Color
@@ -50,5 +52,14 @@ open class TestHarnessActivity : AppCompatActivity() {
5052
setBackgroundColor(Color.WHITE)
5153
id = R.id.harness_root
5254
})
55+
56+
if (intent?.hasExtra(EXTRA_TESTIFY_HARNESS_ACTIVITY_TITLE) == true) {
57+
title = intent.getStringExtra(EXTRA_TESTIFY_HARNESS_ACTIVITY_TITLE)
58+
}
5359
}
60+
61+
companion object {
62+
const val EXTRA_TESTIFY_HARNESS_ACTIVITY_TITLE = "extra_title"
63+
}
64+
5465
}

Library/src/main/java/com/shopify/testify/ScreenshotRule.kt

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,6 @@ import com.shopify.testify.annotation.TestifyLayout
5252
import com.shopify.testify.internal.DeviceIdentifier
5353
import com.shopify.testify.internal.DeviceIdentifier.DEFAULT_NAME_FORMAT
5454
import com.shopify.testify.internal.TestName
55-
import com.shopify.testify.internal.processor.compare.FuzzyCompare
56-
import com.shopify.testify.internal.processor.compare.RegionCompare
57-
import com.shopify.testify.internal.processor.compare.SameAsCompare
5855
import com.shopify.testify.internal.exception.ActivityNotRegisteredException
5956
import com.shopify.testify.internal.exception.AssertSameMustBeLastException
6057
import com.shopify.testify.internal.exception.MissingAssertSameException
@@ -75,8 +72,11 @@ import com.shopify.testify.internal.modification.HidePasswordViewModification
7572
import com.shopify.testify.internal.modification.HideScrollbarsViewModification
7673
import com.shopify.testify.internal.modification.HideTextSuggestionsViewModification
7774
import com.shopify.testify.internal.modification.SoftwareRenderViewModification
78-
import com.shopify.testify.internal.processor.diff.HighContrastDiff
7975
import com.shopify.testify.internal.output.OutputFileUtility
76+
import com.shopify.testify.internal.processor.compare.FuzzyCompare
77+
import com.shopify.testify.internal.processor.compare.RegionCompare
78+
import com.shopify.testify.internal.processor.compare.SameAsCompare
79+
import com.shopify.testify.internal.processor.diff.HighContrastDiff
8080
import com.shopify.testify.report.ReportSession
8181
import com.shopify.testify.report.Reporter
8282
import org.junit.Assert.assertFalse
@@ -99,9 +99,10 @@ typealias ExclusionRectProvider = (rootView: ViewGroup, exclusionRects: MutableS
9999

100100
@Suppress("unused", "MemberVisibilityCanBePrivate")
101101
open class ScreenshotRule<T : Activity> @JvmOverloads constructor(
102+
protected val activityClass: Class<T>,
102103
@IdRes protected var rootViewId: Int = android.R.id.content,
103104
initialTouchMode: Boolean = false,
104-
protected val launchActivity: Boolean = true
105+
protected val launchActivity: Boolean = true,
105106
enableReporter: Boolean = false
106107
) : ActivityTestRule<T>(activityClass, initialTouchMode, launchActivity), TestRule {
107108

Library/src/main/java/com/shopify/testify/TestifyFeatures.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ enum class TestifyFeatures(internal val tags: List<String>, private val defaultV
3434
GenerateDiffs(listOf("testify-generate-diffs"), defaultValue = false),
3535
Locale(listOf("testify-experimental-locale"), defaultValue = true),
3636
CanvasCapture(listOf("testify-canvas-capture")),
37-
PixelCopyCapture(listOf("testify-experimental-capture", "testify-pixelcopy-capture"));
37+
PixelCopyCapture(listOf("testify-experimental-capture", "testify-pixelcopy-capture")),
3838
Reporter(listOf("testify-reporter"));
3939

4040
private var override: Boolean? = null

Library/src/main/java/com/shopify/testify/internal/processor/diff/HighContrastDiff.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import android.content.Context
44
import android.graphics.Bitmap
55
import android.graphics.Color
66
import com.shopify.testify.ScreenshotUtility
7+
import com.shopify.testify.internal.output.OutputFileUtility
78
import com.shopify.testify.internal.processor.ParallelPixelProcessor
89
import com.shopify.testify.internal.processor.createBitmap
910

@@ -30,7 +31,7 @@ class HighContrastDiff {
3031
screenshotUtility.saveBitmapToFile(
3132
context = context,
3233
bitmap = transformResult.createBitmap(),
33-
outputFilePath = screenshotUtility.getOutputFilePath(context, "$fileName.diff")
34+
outputFilePath = OutputFileUtility().getOutputFilePath(context, "$fileName.diff")
3435
)
3536
}
3637

Library/src/main/java/com/shopify/testify/report/ReportSession.kt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -63,12 +63,12 @@ internal open class ReportSession {
6363

6464
fun insertSessionInfo(builder: StringBuilder): StringBuilder {
6565
return builder.insert(0, StringBuilder().apply {
66-
appendln("- session: $sessionId")
66+
appendLine("- session: $sessionId")
6767
val timestamp = getTimestamp(Calendar.getInstance().time)
68-
appendln("- date: $timestamp")
69-
appendln("- failed: $failCount")
70-
appendln("- passed: $passCount")
71-
appendln("- total: $testCount")
68+
appendLine("- date: $timestamp")
69+
appendLine("- failed: $failCount")
70+
appendLine("- passed: $passCount")
71+
appendLine("- total: $testCount")
7272
})
7373
}
7474

Library/src/main/java/com/shopify/testify/report/Reporter.kt

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -66,10 +66,10 @@ internal open class Reporter(
6666
fun startTest(rule: ScreenshotRule<*>, description: Description) {
6767
session.addTest()
6868

69-
builder.appendln("- test:", indent = 4)
70-
builder.appendln("name: ${rule.testMethodName}", indent = 8)
71-
builder.appendln("class: ${description.testClass.simpleName}", indent = 8)
72-
builder.appendln("package: ${description.testClass.`package`?.name}", indent = 8)
69+
builder.appendLine("- test:", indent = 4)
70+
builder.appendLine("name: ${rule.testMethodName}", indent = 8)
71+
builder.appendLine("class: ${description.testClass.simpleName}", indent = 8)
72+
builder.appendLine("package: ${description.testClass.`package`?.name}", indent = 8)
7373
}
7474

7575
/**
@@ -78,27 +78,27 @@ internal open class Reporter(
7878
* modifications have been applied
7979
*/
8080
fun captureOutput(rule: ScreenshotRule<*>) {
81-
builder.appendln("baseline_image: assets/${getBaselinePath(rule)}", indent = 8)
82-
builder.appendln("test_image: ${getOutputPath(rule)}", indent = 8)
81+
builder.appendLine("baseline_image: assets/${getBaselinePath(rule)}", indent = 8)
82+
builder.appendLine("test_image: ${getOutputPath(rule)}", indent = 8)
8383
}
8484

8585
/**
8686
* Records a passing test
8787
*/
8888
fun pass() {
8989
session.pass()
90-
builder.appendln("status: ${TestStatus.PASS.name}", indent = 8)
90+
builder.appendLine("status: ${TestStatus.PASS.name}", indent = 8)
9191
}
9292

9393
/**
9494
* Records that a test has failed and the cause of the failure
9595
*/
9696
fun fail(throwable: Throwable) {
9797
session.fail()
98-
builder.appendln("status: ${TestStatus.FAIL.name}", indent = 8)
98+
builder.appendLine("status: ${TestStatus.FAIL.name}", indent = 8)
9999
val cause = ErrorCause.match(throwable)
100-
builder.appendln("cause: ${cause.name}", indent = 8)
101-
builder.appendln("description: \"${cause.description}\"", indent = 8)
100+
builder.appendLine("cause: ${cause.name}", indent = 8)
101+
builder.appendLine("description: \"${cause.description}\"", indent = 8)
102102
}
103103

104104
/**
@@ -115,8 +115,8 @@ internal open class Reporter(
115115
file.appendText(builder.toString())
116116
}
117117

118-
private fun StringBuilder.appendln(value: String, indent: Int): StringBuilder {
119-
return append("".padStart(indent)).appendln(value)
118+
private fun StringBuilder.appendLine(value: String, indent: Int): StringBuilder {
119+
return append("".padStart(indent)).appendLine(value)
120120
}
121121

122122
@VisibleForTesting
@@ -195,7 +195,7 @@ internal open class Reporter(
195195

196196
insertHeader()
197197
lines.forEach {
198-
builder.appendln(it)
198+
builder.appendLine(it)
199199
}
200200
}
201201

Sample/build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ dependencies {
5555
implementation 'de.hdodenhof:circleimageview:3.0.0'
5656

5757
androidTestImplementation project(":Library")
58+
androidTestImplementation project(":Ext")
5859
androidTestImplementation "androidx.test.espresso:espresso-contrib:${versions.androidx.test.espresso}"
5960
androidTestImplementation "androidx.test.espresso:espresso-core:${versions.androidx.test.espresso}"
6061
androidTestImplementation "androidx.test.ext:junit:${versions.androidx.test.junit}"

Sample/src/androidTest/java/com/shopify/testify/sample/OrientationTest.kt

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ import android.content.pm.ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE
44
import android.content.pm.ActivityInfo.SCREEN_ORIENTATION_PORTRAIT
55
import com.shopify.testify.ScreenshotRule
66
import com.shopify.testify.annotation.ScreenshotInstrumentation
7+
import com.shopify.testify.ext.TestHarnessActivity
78
import com.shopify.testify.sample.clients.details.ClientDetailsView
8-
import com.shopify.testify.sample.test.TestHarnessActivity
99
import com.shopify.testify.sample.test.getViewState
1010
import org.junit.Assert.assertFalse
1111
import org.junit.Rule
@@ -23,7 +23,7 @@ class OrientationTest {
2323
var rule = ScreenshotRule(
2424
activityClass = TestHarnessActivity::class.java,
2525
launchActivity = false,
26-
rootViewId = R.id.harness_root
26+
rootViewId = com.shopify.testify.ext.R.id.harness_root
2727
)
2828

2929
@Test
@@ -62,7 +62,8 @@ class OrientationTest {
6262
.setTargetLayoutId(R.layout.view_client_details)
6363
.setOrientation(orientation)
6464
.setViewModifications { harnessRoot ->
65-
val viewState = harnessRoot.context.getViewState(title + if (orientation == SCREEN_ORIENTATION_PORTRAIT) " Portrait" else " Landscape")
65+
val viewState =
66+
harnessRoot.context.getViewState(title + if (orientation == SCREEN_ORIENTATION_PORTRAIT) " Portrait" else " Landscape")
6667
val view = harnessRoot.getChildAt(0) as ClientDetailsView
6768
view.render(viewState)
6869
rule.activity.title = viewState.name

Sample/src/androidTest/java/com/shopify/testify/sample/ScreenshotRuleExampleTests.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,10 @@ import com.shopify.testify.ScreenshotRule
3636
import com.shopify.testify.TestifyFeatures
3737
import com.shopify.testify.annotation.ScreenshotInstrumentation
3838
import com.shopify.testify.annotation.TestifyLayout
39+
import com.shopify.testify.ext.TestHarnessActivity
40+
import com.shopify.testify.ext.TestHarnessActivity.Companion.EXTRA_TESTIFY_HARNESS_ACTIVITY_TITLE
3941
import com.shopify.testify.extensions.boundingBox
4042
import com.shopify.testify.internal.exception.ScreenshotIsDifferentException
41-
import com.shopify.testify.sample.test.TestHarnessActivity
42-
import com.shopify.testify.sample.test.TestHarnessActivity.Companion.EXTRA_TITLE
4343
import com.shopify.testify.sample.test.clientDetailsView
4444
import com.shopify.testify.sample.test.getViewState
4545
import org.junit.Rule
@@ -59,7 +59,7 @@ class ScreenshotRuleExampleTests {
5959
var rule = ScreenshotRule(
6060
activityClass = TestHarnessActivity::class.java,
6161
launchActivity = false,
62-
rootViewId = R.id.harness_root
62+
rootViewId = com.shopify.testify.ext.R.id.harness_root
6363
)
6464

6565
/**
@@ -93,7 +93,7 @@ class ScreenshotRuleExampleTests {
9393
fun addIntentExtras() {
9494
rule
9595
.addIntentExtras {
96-
it.putString(EXTRA_TITLE, "addIntentExtras")
96+
it.putString(EXTRA_TESTIFY_HARNESS_ACTIVITY_TITLE, "addIntentExtras")
9797
}
9898
.assertSame()
9999
}

Sample/src/androidTest/java/com/shopify/testify/sample/TestingResourceConfigurationsExampleTest.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ class TestingResourceConfigurationsExampleTest {
4747
@get:Rule var rule = ScreenshotRule(
4848
activityClass = TestLocaleHarnessActivity::class.java,
4949
launchActivity = false,
50-
rootViewId = R.id.harness_root
50+
rootViewId = com.shopify.testify.ext.R.id.harness_root
5151
)
5252

5353
/**
@@ -122,4 +122,4 @@ class TestingResourceConfigurationsExampleTest {
122122
.setLocale(locale)
123123
.assertSame()
124124
}
125-
}
125+
}

0 commit comments

Comments
 (0)