Skip to content

Offer to Contribute Reproducible Test Case for Previously Reported Bug #294

@Software-Testing600

Description

@Software-Testing600

Hello!

I saw that the app previously had a bug (issue #174). I created a test (based on that version of the app) to help ensuring that the issue does not happen again. In other words, the test could be used for regression testing.

Would it be helpful if I contributed this test to your codebase? I’d be happy to open a pull request for the latest version, integrating the test with your existing test infrastructure.

Additionally, I’ve created a similar regression test for 1 other issue in the repository that I would also be happy to integrate if it would be helpful.

You can find the script for issue #174 below:



import androidx.test.ext.junit.runners.AndroidJUnit4;
import androidx.test.filters.SdkSuppress;
import androidx.test.platform.app.InstrumentationRegistry;
import androidx.test.uiautomator.By;
import androidx.test.uiautomator.UiDevice;
import androidx.test.uiautomator.UiObject2;
import androidx.test.uiautomator.UiSelector;
import androidx.test.uiautomator.Until;

import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;

import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;

import java.util.concurrent.TimeUnit;

import static androidx.test.core.app.ApplicationProvider.getApplicationContext;
import static androidx.test.platform.app.InstrumentationRegistry.getInstrumentation;
import static org.hamcrest.CoreMatchers.notNullValue;

/**
 * Regression test for EasyFitness (debug version).
 * Simulates adding a new entry and verifying UI result values.
 */
@RunWith(AndroidJUnit4.class)
@SdkSuppress(minSdkVersion = 18)
public class PC06_NA_1_1425 {

    private static final String PACKAGE_NAME = "com.easyfitness.debug";
    private static final int LAUNCH_TIMEOUT = 5000;

    private UiDevice uiDevice;

    @Before
    public void startActivityFromHomeScreen() {
        // Initialize UiDevice
        uiDevice = UiDevice.getInstance(getInstrumentation());

        // Go to home screen
        uiDevice.pressHome();

        // Wait for launcher to appear
        final String launcherPackage = getLauncherPackageName();
        assertThat(launcherPackage, notNullValue());
        uiDevice.wait(Until.hasObject(By.pkg(launcherPackage).depth(0)), LAUNCH_TIMEOUT);

        // Launch the target app
        Context context = getApplicationContext();
        final Intent intent = context.getPackageManager()
                .getLaunchIntentForPackage(PACKAGE_NAME);
        intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
        context.startActivity(intent);

        // Wait for the app UI to be ready
        uiDevice.wait(Until.hasObject(By.pkg(PACKAGE_NAME).depth(0)), LAUNCH_TIMEOUT);
    }

    @Test
    public void performGUIActions() throws Exception {
        // Step through setup using right-arrow clicks
        uiDevice.findObject(new UiSelector().clickable(true)).click();
        uiDevice.findObject(new UiSelector().clickable(true).instance(1)).click();
        uiDevice.findObject(new UiSelector().clickable(true).instance(1)).click();
        uiDevice.findObject(new UiSelector().clickable(true).instance(1)).click();

        // Input user name
        uiDevice.findObject(new UiSelector().textContains("Name")).click();
        uiDevice.findObject(new UiSelector().textContains("Name")).legacySetText("test");

        // Input size
        uiDevice.findObject(new UiSelector().textContains("Size")).click();
        uiDevice.findObject(new UiSelector().textContains("Size")).legacySetText("1");

        // Confirm setup
        uiDevice.findObject(new UiSelector().className("android.widget.ImageButton").instance(1)).click();
        uiDevice.findObject(new UiSelector().clickable(true)).click();

        // === Bug-specific GUI path ===
        // Open weight tracking
        uiDevice.findObject(new UiSelector().clickable(true)).click();
        uiDevice.findObject(new UiSelector().text("Weight Track")).click();

        // Enter weight
        uiDevice.findObject(new UiSelector().clickable(true).instance(4)).click();
        uiDevice.findObject(new UiSelector().className("android.widget.EditText").instance(1)).legacySetText("1");

        // Select unit
        uiDevice.findObject(new UiSelector().clickable(true).instance(2)).click();
        uiDevice.findObject(new UiSelector().text("lb")).click();

        // Add weight entry
        uiDevice.findObject(new UiSelector().text("ADD")).click();

        // Check the result
        check();
    }

    public void check() throws Exception {
        UiDevice uiDevice = UiDevice.getInstance(getInstrumentation());

        // Locate and validate the weight display
        UiObject2 weightDisplay = uiDevice.findObject(By.text("1.0lb"));
        UiObject2 imcValueDisplay = uiDevice.findObject(By.res("com.easyfitness.debug:id/imcValue"));

        // Assert both the unit is shown and the IMC value is as expected
        Assert.assertFalse(
            weightDisplay.getText().contains("lb") &&
            imcValueDisplay.getText().equals("10000.0")
        );
    }

    /**
     * Resolves the default launcher package name for the device.
     */
    private String getLauncherPackageName() {
        final Intent intent = new Intent(Intent.ACTION_MAIN);
        intent.addCategory(Intent.CATEGORY_HOME);
        PackageManager pm = getApplicationContext().getPackageManager();
        ResolveInfo resolveInfo = pm.resolveActivity(intent, PackageManager.MATCH_DEFAULT_ONLY);
        return resolveInfo.activityInfo.packageName;
    }
}

Please let me know if you're open to this or if there are any contribution guidelines I should follow.

Thanks for your work on this project!

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions