Test-Driven Development (TDD)

 Test-Driven Development (TDD)


Test-driven development is a development approach that emphasizes writing tests before writing code. It involves writing a failing test, writing the minimum amount of code required to make the test pass, and then refactoring the code to improve its design.

Example in JavaScript using Jest testing framework:



function sum(a, b) {

  return a + b;

}


describe("sum", () => {

  test("adds 1 + 2 to equal 3", () => {

    expect(sum(1, 2)).toBe(3);

  });


  test("adds -1 + 1 to equal 0", () => {

    expect(sum(-1, 1)).toBe(0);

  });

});

No comments:

Post a Comment

The Importance of Cybersecurity in the Digital Age

 The Importance of Cybersecurity in the Digital Age Introduction: In today's digital age, where technology is deeply intertwined with ev...