Skip to content

Commit

Permalink
Fix test
Browse files Browse the repository at this point in the history
  • Loading branch information
takahirom committed Oct 12, 2024
1 parent 2564abe commit d7cdd7c
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -129,4 +129,8 @@ object DefaultFileNameGenerator {
return testName
}

@InternalRoborazziApi
fun reset() {
testNameToTakenCount.clear()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
package com.github.takahirom.roborazzi.sample.boxed

import android.widget.TextView
import androidx.compose.ui.test.junit4.createAndroidComposeRule
import androidx.test.espresso.Espresso.onView
import androidx.test.espresso.matcher.ViewMatchers
import androidx.test.ext.junit.runners.AndroidJUnit4
import com.github.takahirom.roborazzi.DefaultFileNameGenerator
import com.github.takahirom.roborazzi.ROBORAZZI_DEBUG
import com.github.takahirom.roborazzi.RobolectricDeviceQualifiers
import com.github.takahirom.roborazzi.RoborazziOptions
import com.github.takahirom.roborazzi.RoborazziTaskType
import com.github.takahirom.roborazzi.captureRoboImage
import com.github.takahirom.roborazzi.roborazziSystemPropertyOutputDirectory
import com.github.takahirom.roborazzi.sample.MainActivity
import com.github.takahirom.roborazzi.sample.R
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith
import org.robolectric.annotation.Config
import org.robolectric.annotation.GraphicsMode
import java.io.File

@RunWith(AndroidJUnit4::class)
@GraphicsMode(GraphicsMode.Mode.NATIVE)
@Config(
sdk = [30],
qualifiers = RobolectricDeviceQualifiers.NexusOne
)
class SizeChangeTest {
@get:Rule
val composeTestRule = createAndroidComposeRule<MainActivity>()

@Test
fun sizeChangeTest() {
boxedEnvironment {
ROBORAZZI_DEBUG = true
val prefix =
"${roborazziSystemPropertyOutputDirectory()}/${this::class.qualifiedName}.sizeChangeTest"
val expectedOutput =
File("$prefix.png")
val expectedCompareOutput = File("${prefix}_compare.png")
expectedOutput.delete()
try {
onView(ViewMatchers.withId(R.id.textview_first))
.captureRoboImage(
roborazziOptions = RoborazziOptions(
taskType = RoborazziTaskType.Record
)
)
composeTestRule.activity.findViewById<TextView>(R.id.textview_first)
.text = "Hello, Roborazzi! This is a test for size change."
DefaultFileNameGenerator.reset()

onView(ViewMatchers.withId(R.id.textview_first))
.captureRoboImage(
roborazziOptions = RoborazziOptions(
taskType = RoborazziTaskType.Compare
)
)
println(expectedCompareOutput.absolutePath + ":" + expectedCompareOutput.exists())
assert(expectedCompareOutput.exists())
} finally {
expectedCompareOutput.delete()
}
}
}
}

0 comments on commit d7cdd7c

Please sign in to comment.