Back to Repositories

Testing Vector Drawable Decoding Functionality in Apktool

This test suite validates the decoding functionality of vector drawable resources in Android APK files using Apktool. It specifically focuses on ensuring proper extraction and decoding of XML-based vector drawable files from APK resources.

Test Coverage Overview

The test suite covers the decoding of vector drawable resources from APK files, focusing on XML-based Android vector graphics.

Key areas tested include:
  • Proper extraction of .xml vector drawable files
  • Verification of file paths and structures
  • Handling of multiple vector drawable resources
  • Validation of decoded file integrity

Implementation Analysis

The testing approach utilizes JUnit framework with a modular setup extending BaseTest class. The implementation employs resource copying for test preparation and uses ExtFile for APK manipulation.

Testing patterns include:
  • Resource directory setup via TestUtils
  • APK decoding verification
  • File existence assertions
  • Structured test organization with @BeforeClass setup

Technical Details

Testing tools and configuration:
  • JUnit 4 testing framework
  • ApkDecoder utility class
  • ExtFile for extended file operations
  • TestUtils for resource management
  • BrutException handling for error cases
  • Temporary directory management for test isolation

Best Practices Demonstrated

The test implementation showcases several testing best practices for Android APK resource handling.

Notable practices include:
  • Proper test isolation using temporary directories
  • Clear test method naming conventions
  • Resource cleanup and management
  • Explicit test setup and teardown
  • Focused test scope for specific functionality

ibotpeaches/apktool

brut.apktool/apktool-lib/src/test/java/brut/androlib/decode/VectorDrawableTest.java

            
/*
 *  Copyright (C) 2010 Ryszard Wiśniewski <[email protected]>
 *  Copyright (C) 2010 Connor Tumbleson <[email protected]>
 *
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *       https://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 */
package brut.androlib.decode;

import brut.androlib.ApkDecoder;
import brut.androlib.BaseTest;
import brut.androlib.TestUtils;
import brut.common.BrutException;
import brut.directory.ExtFile;

import java.io.File;

import org.junit.*;
import static org.junit.Assert.*;

public class VectorDrawableTest extends BaseTest {
    private static final String TEST_APK = "issue1456.apk";

    @BeforeClass
    public static void beforeClass() throws Exception {
        TestUtils.copyResourceDir(VectorDrawableTest.class, "decode/issue1456", sTmpDir);
    }

    @Test
    public void checkIfDrawableFileDecodesProperly() throws BrutException {
        ExtFile testApk = new ExtFile(sTmpDir, TEST_APK);
        ExtFile testDir = new ExtFile(testApk + ".out");
        new ApkDecoder(testApk, sConfig).decode(testDir);

        assertTrue(new File(testDir, "res/drawable/ic_arrow_drop_down_black_24dp.xml").isFile());
        assertTrue(new File(testDir, "res/drawable/ic_android_black_24dp.xml").isFile());
    }
}