Skip to content

Instantly share code, notes, and snippets.

@K3ndev
Last active May 29, 2024 06:06
Show Gist options
  • Save K3ndev/67b3c77df67a117528058cff6b31b14c to your computer and use it in GitHub Desktop.
Save K3ndev/67b3c77df67a117528058cff6b31b14c to your computer and use it in GitHub Desktop.

Test-Driven Development

Test-Driven Development (TDD) is a software development approach where tests are written before the actual code. The process follows these steps:

  1. Write a Test: Create a test for a new function or feature.
  2. Run the Test: The test will fail initially because the feature isn't implemented yet.
  3. Write Code: Write the minimal code needed to pass the test.
  4. Run the Test Again: Ensure the code passes the test.
  5. Refactor: Clean up the code while ensuring the test still passes.
  6. Repeat: Continue this cycle for each new feature or function.

image

different type of testing

  • Unit testing
    • goal: ensure that each part of the program works correctly on its own.
  • Integration testing
    • goal: to identify issues that may arise when these components work together.
  • End to End testing
    • goal: ensures that the complete system operates as expected, including interactions with external interfaces and databases.
  • Acceptance testing
    • goal: ensures the software does what it is supposed to do based on client requirements.
  • Performance testing
    • goal: identify performance bottlenecks and ensure the software can handle expected user loads.
  • Smoke testing
    • goal: ensures that the major functions of the software work correctly before proceeding with more detailed testing.

Writing test

// vitest
import {describe, it} from "vitest"

// format; 
// sucess 
// invalid 
// empty

// just test the functionality!

describe((), () => {
  it("",() => {
    
    expect()
  })
}) 

vitest expect() api

react lib test screen() api

react lib test render() api

github action with vitest

faker

tuturial

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment