Back to Repositories

Validating Keyframe Animation Timing in Lottie Android

This test suite validates the Keyframe functionality in Lottie Android’s animation system. It focuses on verifying keyframe timing, progression, and interpolation mechanics that are crucial for smooth animations in the Lottie library.

Test Coverage Overview

The test suite covers essential keyframe animation functionality in Lottie Android.

Key areas tested include:
  • Keyframe start and end frame synchronization
  • Frame progression validation
  • Animation timing consistency
  • Composition initialization verification

Implementation Analysis

The testing approach employs JUnit to verify keyframe timing mechanics.

Technical implementation features:
  • Linear interpolation testing
  • Composition initialization with multiple parameters
  • Precise floating-point comparisons for frame timing
  • Direct keyframe object instantiation and validation

Technical Details

Testing infrastructure includes:
  • JUnit 4 testing framework
  • Android graphics and animation components
  • LottieComposition test initialization
  • Custom Keyframe class testing
  • LinearInterpolator for animation timing

Best Practices Demonstrated

The test implementation showcases robust testing practices for animation systems.

Notable practices include:
  • Precise floating-point equality assertions
  • Comprehensive composition setup
  • Clear test method naming
  • Isolated keyframe testing
  • Proper test initialization patterns

airbnb/lottie-android

lottie/src/test/java/com/airbnb/lottie/value/KeyframeTest.java

            
package com.airbnb.lottie.value;

import static org.junit.Assert.*;

import android.graphics.Rect;
import android.view.animation.LinearInterpolator;
import androidx.collection.LongSparseArray;
import androidx.collection.SparseArrayCompat;
import com.airbnb.lottie.LottieComposition;
import org.junit.Test;

import java.util.ArrayList;
import java.util.HashMap;

public class KeyframeTest {

  @Test
  public void testStartFrame() {
    LottieComposition composition = new LottieComposition();
    composition.init(
        new Rect(),
        0f,
        504.99f,
        60f,
        new ArrayList<>(),
        new LongSparseArray<>(),
        new HashMap<>(),
        new HashMap<>(),
        1f,
        new SparseArrayCompat<>(),
        new HashMap<>(),
        new ArrayList<>(),
        0,
        0
    );
    Keyframe<Float> keyframe1 = new Keyframe<>(composition, 200f, 321f, new LinearInterpolator(), 28f, 48f);
    Keyframe<Float> keyframe2 = new Keyframe<>(composition, 321f, 300f, new LinearInterpolator(), 48f, 56f);
    assertEquals(keyframe2.getStartProgress(), keyframe1.getEndProgress(), 0f);
  }
}