mobile-app-testing

from aj-geddes/useful-ai-prompts

A curated collection of useful AI prompts for various tasks and use cases

50 stars4 forksUpdated Dec 28, 2025
npx skills add https://github.com/aj-geddes/useful-ai-prompts --skill mobile-app-testing

SKILL.md

Mobile App Testing

Overview

Implement comprehensive testing strategies for mobile applications including unit tests, UI tests, integration tests, and performance testing.

When to Use

  • Creating reliable mobile applications with test coverage
  • Automating UI testing across iOS and Android
  • Performance testing and optimization
  • Integration testing with backend services
  • Regression testing before releases

Instructions

1. React Native Testing with Jest & Detox

// Unit test with Jest
import { calculate } from '../utils/math';

describe('Math utilities', () => {
  test('should add two numbers', () => {
    expect(calculate.add(2, 3)).toBe(5);
  });

  test('should handle negative numbers', () => {
    expect(calculate.add(-2, 3)).toBe(1);
  });
});

// Component unit test
import React from 'react';
import { render, screen } from '@testing-library/react-native';
import { UserProfile } from '../components/UserProfile';

describe('UserProfile Component', () => {
  test('renders user name correctly', () => {
    const mockUser = { id: '1', name: 'John Doe', email: 'john@example.com' };
    render(<UserProfile user={mockUser} />);

    expect(screen.getByText('John Doe')).toBeTruthy();
  });

  test('handles missing user gracefully', () => {
    render(<UserProfile user={null} />);
    expect(screen.getByText(/no user data/i)).toBeTruthy();
  });
});

// E2E Testing with Detox
describe('Login Flow E2E Test', () => {
  beforeAll(async () => {
    await device.launchApp();
  });

  beforeEach(async () => {
    await device.reloadReactNative();
  });

  it('should login successfully with valid credentials', async () => {
    await waitFor(element(by.id('emailInput')))
      .toBeVisible()
      .withTimeout(5000);

    await element(by.id('emailInput')).typeText('user@example.com');
    await element(by.id('passwordInput')).typeText('password123');
    await element(by.id('loginButton')).multiTap();

    await waitFor(element(by.text('Home Feed')))
      .toBeVisible()
      .withTimeout(5000);
  });

  it('should show error with invalid credentials', async () => {
    await element(by.id('emailInput')).typeText('invalid@example.com');
    await element(by.id('passwordInput')).typeText('wrongpass');
    await element(by.id('loginButton')).multiTap();

    await waitFor(element(by.text(/invalid credentials/i)))
      .toBeVisible()
      .withTimeout(5000);
  });

  it('should navigate between tabs', async () => {
    await element(by.id('profileTab')).tap();
    await waitFor(element(by.text('Profile')))
      .toBeVisible()
      .withTimeout(2000);

    await element(by.id('homeTab')).tap();
    await waitFor(element(by.text('Home Feed')))
      .toBeVisible()
      .withTimeout(2000);
  });
});

2. iOS Testing with XCTest

import XCTest
@testable import MyApp

class UserViewModelTests: XCTestCase {
  var viewModel: UserViewModel!
  var mockNetworkService: MockNetworkService!

  override func setUp() {
    super.setUp()
    mockNetworkService = MockNetworkService()
    viewModel = UserViewModel(networkService: mockNetworkService)
  }

  func testFetchUserSuccess() async {
    let expectedUser = User(id: UUID(), name: "John", email: "john@example.com")
    mockNetworkService.mockUser = expectedUser

    await viewModel.fetchUser(id: expectedUser.id)

    XCTAssertEqual(viewModel.user?.name, "John")
    XCTAssertNil(viewModel.errorMessage)
    XCTAssertFalse(viewModel.isLoading)
  }

  func testFetchUserFailure() async {
    mockNetworkService.shouldFail = true

    await viewModel.fetchUser(id: UUID())

    XCTAssertNil(viewModel.user)
    XCTAssertNotNil(viewModel.errorMessage)
    XCTAssertFalse(viewModel.isLoading)
  }
}

class MockNetworkService: NetworkService {
  var mockUser: User?
  var shouldFail = false

  override func fetch<T: Decodable>(
    _: T.Type,
    from endpoint: String
  ) async throws -> T {
    if shouldFail {
      throw NetworkError.unknown
    }
    return mockUser as! T
  }
}

// UI Test
class LoginUITests: XCTestCase {
  override func setUp() {
    super.setUp()
    continueAfterFailure = false
    XCUIApplication().launch()
  }

  func testLoginFlow() {
    let app = XCUIApplication()

    let emailTextField = app.textFields["emailInput"]
    let passwordTextField = app.secureTextFields["passwordInput"]
    let loginButton = app.buttons["loginButton"]

    emailTextField.tap()
    emailTextField.typeText("user@example.com")

    passwordTextField.tap()
    passwordTextField.typeText("password123")

    loginButton.tap()

    let homeText = app.staticTexts["Home Feed"]
    XCTAssertTrue(homeText.waitForExistence(timeout: 5))
  }

  func testNavigationBetweenTabs() {
    let app = XCUIApplication()
    let profileTab = app.tabBars.buttons["Profile"]
    let homeTab = app.tabBars.buttons["Home"]

    profileTab.tap()
    XCTAssertTrue(app.staticTexts["Profile"].exists)

    homeTab.tap()
    XCTAssertTrue(app.staticTexts["Home"].e

...
Read full content

Repository Stats

Stars50
Forks4
LicenseMIT License