Back to Repositories

Testing Asset Skip Configuration in APK Decoding for Apktool

This test suite validates the asset skipping functionality in APK decoding process within Apktool. It specifically tests the ability to selectively skip Kotlin builtin asset files during APK decoding, ensuring proper configuration handling and file management.

Test Coverage Overview

The test suite provides comprehensive coverage of asset skipping functionality in APK decoding:

  • Verification of asset skip configuration through Config.DECODE_ASSETS_NONE setting
  • Validation of complete asset decoding using Config.DECODE_ASSETS_FULL
  • Testing of specific Kotlin builtin asset file handling
  • Verification of nested asset directory structures

Implementation Analysis

The testing approach utilizes JUnit framework with a structured setup and validation pattern. It implements two primary test cases comparing different decode configurations:

  • Asset skip verification using configuration flags
  • Control test with full asset decoding
  • File existence validation through assertion checks

Technical Details

Testing infrastructure includes:

  • JUnit test framework
  • ApkDecoder utility class
  • ExtFile for extended file operations
  • TestUtils for resource management
  • Custom configuration through Config class

Best Practices Demonstrated

The test suite exemplifies several testing best practices:

  • Clear test method naming conveying purpose
  • Proper test setup using @BeforeClass
  • Isolated test cases with specific assertions
  • Resource cleanup through configuration management
  • Comprehensive validation of both positive and negative scenarios

ibotpeaches/apktool

brut.apktool/apktool-lib/src/test/java/brut/androlib/aapt1/SkipAssetTest.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.aapt1;

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

import java.io.File;

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

public class SkipAssetTest extends BaseTest {
    private static final String TEST_APK = "issue1605.apk";

    @BeforeClass
    public static void beforeClass() throws Exception {
        TestUtils.copyResourceDir(SkipAssetTest.class, "aapt1/issue1605", sTmpDir);
    }

    @Test
    public void checkIfEnablingSkipAssetWorks() throws BrutException {
        sConfig.setForceDelete(true);
        sConfig.setDecodeAssets(Config.DECODE_ASSETS_NONE);

        ExtFile testApk = new ExtFile(sTmpDir, TEST_APK);
        ExtFile testDir = new ExtFile(testApk + ".out");
        new ApkDecoder(testApk, sConfig).decode(testDir);

        assertFalse(new File(testDir, "assets/kotlin.kotlin_builtins").isFile());
        assertFalse(new File(testDir, "assets/ranges/ranges.kotlin_builtins").isFile());
    }

    @Test
    public void checkControl() throws BrutException {
        sConfig.setForceDelete(true);
        sConfig.setDecodeAssets(Config.DECODE_ASSETS_FULL);

        ExtFile testApk = new ExtFile(sTmpDir, TEST_APK);
        ExtFile testDir = new ExtFile(testApk + ".out");
        new ApkDecoder(testApk, sConfig).decode(testDir);

        assertTrue(new File(testDir, "assets/kotlin.kotlin_builtins").isFile());
        assertTrue(new File(testDir, "assets/ranges/ranges.kotlin_builtins").isFile());
    }
}