Back to Repositories

Validating APK Property Consistency Testing in Apktool

This test suite validates the consistent property handling in Apktool by verifying APK information loading and property assertions. It ensures accurate parsing and validation of critical APK metadata from YAML configuration files.

Test Coverage Overview

The test suite provides comprehensive coverage of APK property validation, focusing on essential metadata attributes.

Key areas tested include:
  • Version information and file naming
  • Framework integration flags
  • SDK version compatibility ranges
  • Package identification and manifest details
  • Resource configuration settings

Implementation Analysis

The testing approach employs JUnit assertions to validate APK information loaded from YAML configuration files. The implementation uses a systematic property-by-property verification pattern, leveraging the ApkInfo class to parse and validate configuration data.

Key testing patterns include:
  • Direct property assertion checks
  • Boolean flag validation
  • Collection size verification
  • String value matching

Technical Details

Testing Tools & Configuration:
  • JUnit test framework
  • YAML configuration files
  • BaseTest extension for common functionality
  • BrutException handling
  • Resource stream loading for test data

Best Practices Demonstrated

The test implementation showcases several testing best practices for property validation.

Notable practices include:
  • Comprehensive property coverage
  • Clear test method naming
  • Proper exception handling
  • Organized assertion structure
  • Resource-based test data management

ibotpeaches/apktool

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

import brut.androlib.BaseTest;
import brut.common.BrutException;

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

public class ConsistentPropertyTest extends BaseTest {

    @Test
    public void testAssertingAllKnownApkInfoProperties() throws BrutException {
        ApkInfo apkInfo = ApkInfo.load(
            getClass().getResourceAsStream("/apk/basic.yml"));

        assertEquals("2.8.0", apkInfo.version);
        assertEquals("basic.apk", apkInfo.apkFileName);
        assertFalse(apkInfo.isFrameworkApk);
        assertEquals(1, apkInfo.usesFramework.ids.size());
        assertEquals("tag", apkInfo.usesFramework.tag);
        assertEquals("4", apkInfo.getMinSdkVersion());
        assertEquals("22", apkInfo.getTargetSdkVersion());
        assertEquals("30", apkInfo.getMaxSdkVersion());
        assertEquals("127", apkInfo.packageInfo.forcedPackageId);
        assertEquals("com.test.basic", apkInfo.packageInfo.renameManifestPackage);
        assertEquals("71", apkInfo.versionInfo.versionCode);
        assertEquals("1.0.70", apkInfo.versionInfo.versionName);
        assertFalse(apkInfo.sharedLibrary);
        assertTrue(apkInfo.sparseResources);
        assertEquals(2, apkInfo.doNotCompress.size());
    }
}