পরীক্ষা অ্যানিমেশন
সেভ করা পৃষ্ঠা গুছিয়ে রাখতে 'সংগ্রহ' ব্যবহার করুন
আপনার পছন্দ অনুযায়ী কন্টেন্ট সেভ করুন ও সঠিক বিভাগে রাখুন।
কম্পোজ ComposeTestRule
অফার করে যা আপনাকে পরীক্ষার ঘড়ির উপর সম্পূর্ণ নিয়ন্ত্রণের সাথে একটি নির্ধারক পদ্ধতিতে অ্যানিমেশনের জন্য পরীক্ষা লিখতে দেয়। এটি আপনাকে মধ্যবর্তী অ্যানিমেশন মান যাচাই করতে দেয়। উপরন্তু, একটি পরীক্ষা অ্যানিমেশনের প্রকৃত সময়কালের চেয়ে দ্রুত চলতে পারে।
ComposeTestRule
এর পরীক্ষার ঘড়িটি mainClock
হিসাবে প্রকাশ করে। আপনি আপনার পরীক্ষার কোডে ঘড়ি নিয়ন্ত্রণ করতে autoAdvance
বৈশিষ্ট্য মিথ্যা সেট করতে পারেন। আপনি যে অ্যানিমেশনটি পরীক্ষা করতে চান তা শুরু করার পরে, ঘড়ি অগ্রসর করা যেতে পারে advanceTimeBy
দিয়ে।
এখানে উল্লেখ্য একটি বিষয় হল যে advanceTimeBy
নির্দিষ্ট সময়কালের দ্বারা ঘড়িটিকে ঠিকভাবে সরায় না। বরং, এটি এটিকে নিকটতম সময়কাল পর্যন্ত বৃত্তাকার করে যা ফ্রেমের সময়কালের গুণক।
@get:Rule
val rule = createComposeRule()
@Test
fun testAnimationWithClock() {
// Pause animations
rule.mainClock.autoAdvance = false
var enabled by mutableStateOf(false)
rule.setContent {
val color by animateColorAsState(
targetValue = if (enabled) Color.Red else Color.Green,
animationSpec = tween(durationMillis = 250)
)
Box(Modifier.size(64.dp).background(color))
}
// Initiate the animation.
enabled = true
// Let the animation proceed.
rule.mainClock.advanceTimeBy(50L)
// Compare the result with the image showing the expected result.
// `assertAgainGolden` needs to be implemented in your code.
rule.onRoot().captureToImage().assertAgainstGolden()
}
{% শব্দার্থে %}
{% endverbatim %} আপনার জন্য প্রস্তাবিত
{% শব্দার্থে %} {% endverbatim %}
এই পৃষ্ঠার কন্টেন্ট ও কোডের নমুনাগুলি Content License-এ বর্ণিত লাইসেন্সের অধীনস্থ। Java এবং OpenJDK হল Oracle এবং/অথবা তার অ্যাফিলিয়েট সংস্থার রেজিস্টার্ড ট্রেডমার্ক।
2025-08-28 UTC-তে শেষবার আপডেট করা হয়েছে।
[[["সহজে বোঝা যায়","easyToUnderstand","thumb-up"],["আমার সমস্যার সমাধান হয়েছে","solvedMyProblem","thumb-up"],["অন্যান্য","otherUp","thumb-up"]],[["এতে আমার প্রয়োজনীয় তথ্য নেই","missingTheInformationINeed","thumb-down"],["খুব জটিল / অনেক ধাপ","tooComplicatedTooManySteps","thumb-down"],["পুরনো","outOfDate","thumb-down"],["অনুবাদ সংক্রান্ত সমস্যা","translationIssue","thumb-down"],["নমুনা / কোড সংক্রান্ত সমস্যা","samplesCodeIssue","thumb-down"],["অন্যান্য","otherDown","thumb-down"]],["2025-08-28 UTC-তে শেষবার আপডেট করা হয়েছে।"],[],[],null,["Compose offers `ComposeTestRule` that allows you to write tests for animations\nin a deterministic manner with full control over the test clock. This allows you\nto verify intermediate animation values. In addition, a test can run quicker\nthan the actual duration of the animation.\n\n`ComposeTestRule` exposes its test clock as `mainClock`. You can set the\n`autoAdvance` property to false to control the clock in your test code. After\ninitiating the animation you want to test, the clock can be moved forward with\n`advanceTimeBy`.\n\nOne thing to note here is that `advanceTimeBy` doesn't move the clock exactly by\nthe specified duration. Rather, it rounds it up to the nearest duration that is\na multiplier of the frame duration.\n\n\n```kotlin\n@get:Rule\nval rule = createComposeRule()\n\n@Test\nfun testAnimationWithClock() {\n // Pause animations\n rule.mainClock.autoAdvance = false\n var enabled by mutableStateOf(false)\n rule.setContent {\n val color by animateColorAsState(\n targetValue = if (enabled) Color.Red else Color.Green,\n animationSpec = tween(durationMillis = 250)\n )\n Box(Modifier.size(64.dp).background(color))\n }\n\n // Initiate the animation.\n enabled = true\n\n // Let the animation proceed.\n rule.mainClock.advanceTimeBy(50L)\n\n // Compare the result with the image showing the expected result.\n // `assertAgainGolden` needs to be implemented in your code.\n rule.onRoot().captureToImage().assertAgainstGolden()\n}https://github.com/android/snippets/blob/7a0ebbee11495f628cf9d574f6b6069c2867232a/compose/snippets/src/androidTest/java/com/example/compose/snippets/animation/AnimationTestingSnippets.kt#L57-L82\n```\n\n\u003cbr /\u003e\n\nRecommended for you\n\n- Note: link text is displayed when JavaScript is off\n- [Testing your Compose layout](/develop/ui/compose/testing)\n- [Other considerations](/develop/ui/compose/migrate/other-considerations)\n- [Customize animations {:#customize-animations}](/develop/ui/compose/animation/customize)"]]