Skip to main content

Testing

Here are my personal notes on various testing methodologies that I've applied in my software development projects.

Shift-left Paradigm

The Shift-left Paradigm is a methodology that emphasizes testing early and often in the software development lifecycle. Instead of testing after a product is nearly complete, testing is performed much earlier. This approach helps me to catch and fix issues sooner, which improves quality and reduces development time and costs.

Test Driven Development (TDD)

Test Driven Development (TDD) is a software development approach where tests are written before the actual code. The process follows a simple cycle: write a test, run all tests and see the new one fail, write code to make the test pass, run tests again to ensure all pass, and then refactor the code for optimization. This cycle is repeated for each new feature or functionality. For me, I don't always use TDD on every project I create, but I think this TDD method is very important if the scale of the project is very large and consists of many team members so that the team speed graph over time in coding work can be at the peak just at the beginning of coding.

Unit Testing

Unit Testing involves breaking down the software into its smallest parts, or units, and testing each one individually. Unit tests are automated, run quickly, and are repeated often to ensure each unit continues to work correctly as changes are made.

E2E Testing

End-to-End (E2E) Testing involves testing the complete flow of an application from start to finish, simulating real user scenarios to ensure that all components and systems interact correctly. This type of testing helps ensure that the software functions as expected in a real-world environment, providing a comprehensive validation of both functionality and user experience.

React Component Testing

Best Practice: Focus on testing user interactions and outputs of components.

Tool: React Testing Library

// ButtonComponent.test.js
import { render, screen, fireEvent } from '@testing-library/react';
import ButtonComponent from './ButtonComponent';

test('changes text on click', () => {
render(<ButtonComponent />);
fireEvent.click(screen.getByText('Click Me'));
expect(screen.getByText('Clicked')).toBeInTheDocument();
});

JS Function Testing

Best Practice: Test for correct output with different inputs.

Tool: Jest

// add.test.js
const add = (a, b) => a + b;

test('adds 1 + 2 to equal 3', () => {
expect(add(1, 2)).toBe(3);
});

Python Testing

Best Practice: Test function behavior with mocking external dependencies.

Tool: Pytest with Mock.

# test_user.py
import pytest
from unittest.mock import MagicMock
from user_service import get_user_info

def test_get_user_info():
# Mock the database call
db = MagicMock()
db.get_user.return_value = {'id': 1, 'name': 'Test User'}
# Assert the expected output
assert get_user_info(1, db) == {'id': 1, 'name': 'Test User'}

For further exploration of testing techniques, I recommend the following resources from some of the big tech companies:

Blogs

  1. Modern Testing by Mercary
  2. Autonomous Testing at Meta
  3. Effective Test Pipeline by Airbnb
  4. Selective Testing by Agoda
  5. Load Testing by Spotify
  6. Integration Test at Twitter
  7. Preseeding Run Test
  8. Grab Quality Testing
  9. Flaky Test at Uber
  10. Uber’s Accounting Data Testing Strategies

Guides

  1. Writing Test by Modern Web
  1. Quality Assurance at Mercari (DevDojo)

My go-to tools for testing

  1. Jest
  2. Cypress
  3. React Testing Library
  4. PyTest
  5. Playwright
  6. Vitest