Skip to content

Instantly share code, notes, and snippets.

@halitbatur
Last active July 21, 2023 20:32
Show Gist options
  • Save halitbatur/5e0f845b8ec30da545ce58b91d46fdb1 to your computer and use it in GitHub Desktop.
Save halitbatur/5e0f845b8ec30da545ce58b91d46fdb1 to your computer and use it in GitHub Desktop.
Testing Disscusion

Testing in JS disscusion

  1. What is the purpose of unit testing in JavaScript development? How does it contribute to the overall quality of a software application?
  2. Explain the difference between manual testing and automated testing. What are the advantages of using automated testing in JavaScript projects?
  3. What is a test suite, and how does it relate to test cases in JavaScript testing? Provide an example of a test suite and its corresponding test cases.
  4. Describe the concept of test-driven development (TDD) in JavaScript. How does TDD influence the development process and help in writing robust and reliable code?
  5. What are the popular testing frameworks and libraries available for JavaScript? Compare and contrast two of them, highlighting their key features and use cases.
@AmmarAlmuain
Copy link

@masterofalune @badrnasher @nezirAydin @nourkrimesh @Younesnz
1 - The purpose of unit testing in JavaScript development is to verify the correctness of individual units, typically functions or classes, in isolation. It involves writing automated tests that cover different scenarios and inputs to ensure that each unit behaves as expected.
2 - Manual testing refers to the process of manually executing test cases and validating the behavior of a software application. On the other hand, automated testing involves using software tools to execute test cases and compare the actual results with the expected outcomes without human intervention. It typically involves writing scripts or test code to automate the testing process.
Automated Testing Saves Time and Money.
3 - In JavaScript testing, a test suite typically consists of one or more test files or modules. Each test file within the suite contains multiple test cases, which are individual units of testing that verify specific aspects or behaviors of the code being tested.
4 -Test-driven development (TDD) is a coding practice where you write the result you want your program to produce before creating the program. In other words, TDD requires you to pre-specify the output your intended program must produce to pass the test of functioning the way you envisioned.
5 - Selenium, mocha, jest and cypress => Cypress uses a browser. Jest uses fake DOM and isn't eligible for frontend e2e or intergration tests that need full DOM support, unless used with Puppeteer or else

@0Rawan
Copy link

0Rawan commented May 20, 2023

Room #3, @handedemirbay, @MOHAMMAD-ALMOHAMMAD, @0Rawan and Abdullah karakli

  1. The main objective of unit testing is to isolate written code to test and determine if it works as intended. Unit testing is an important step in the development process. It contributes to the overall quality of a software application in multiple ways:

    Error Detection: Unit tests catch bugs and errors early in development.
    Code Refactoring: Tests provide confidence when modifying code.
    Documentation: Tests serve as executable documentation of code behavior.
    Maintainability: Tests ensure changes don't break existing functionality.
    Collaboration: Tests facilitate team communication and understanding.
    Regression Prevention: Tests act as a safety net against recurring issues.
    CI/CD: Tests are crucial in automated pipelines to ensure code quality.

  2. When manually testing, the tester validates the key features of a software application. Analysts execute test cases and develop summary error reports without specialized automation tools. Automated testing helps testers execute more test cases and improve test coverage. When comparing manual vs. automation testing, manually takes longer. Automated testing is more efficient.
    image

  3. In JavaScript testing, a test suite is a collection of related test cases that verify the behavior of a specific component. For example:

Test Suite: Calculator

  • Test Case 1: Addition (2 + 3 = 5)
  • Test Case 2: Subtraction (5 - 3 = 2)
  • Test Case 3: Multiplication (4 * 6 = 24)
  • Test Case 4: Division (10 / 2 = 5)
  • Test Case 5: Error Handling (10 / 0 should throw an error)
  1. Test-driven development (TDD) is an approach where tests are written before writing the actual code. In JavaScript, TDD involves writing failing tests, implementing code to pass those tests, and then refactoring as needed. TDD influences the development process by providing clear specifications, improving code design, preventing regressions, boosting code confidence, and promoting collaboration. It helps in writing robust and reliable code by catching defects early, encouraging small iterations, increasing test coverage, enforcing better code structure, and facilitating refactoring. TDD integrates testing from the beginning, resulting in higher-quality software.
  2. a. Mocha

Mocha is a popular JavaScript testing framework that runs both in the browser and in the Node.js runtime environment. Known for simple asynchronous testing, Mocha is able to connect unmapped exceptions to the correct test cases while also enabling accurate reporting.
b. Jest

If you’re looking for a ‘zero-configuration’ testing experience, Jest might be what you’re looking for. Release by Facebook, Jest focuses on simplicity and works out of the box with no additional setup required.
Puppeteer

c. Puppeteer is not a framework, but a Node.js library enabling users to control a headless Chrome or Chromium browser. Despite not being a framework, Puppeteer offers many advantages regarding JavaScript testing in Chrome, hence its presence on this list.
d. Selenium is a collection of open-source tools that support browser application testing. Selenium was started by a company called ThoughtWorks and launched in 2004. Its primary focus is browser application testing. It has three major components: Selenium WebDriver, Selenium IDE, and Selenium Grid. Selenium supports application testing for several browsers: Chrome, Firefox, Safari, Internet Explorer, Edge, and Opera. Selenium scripts support JavaScript, Java, Ruby, C#, and Python.
image

@cyberRasam
Copy link

@cyberRasam @afrakucukaydin @AsliSema @MAHMOUDAlshahin

1- The purpose of unit testing in JavaScript development is; Detecting Bugs Early, Ensuring Correct Functionality, Refactoring with Confidence, Supporting Collaboration, and Regression Prevention. It involves writing and executing automated tests on individual units, such as functions, modules, or classes, to verify their correctness and ensure they behave as expected. Unit tests can detect early flaws in code which may be more difficult to find in later testing stages.

2- Manual testing involves the process of manually executing test cases to verify the functionality and quality of a software application. Automated testing involves using software tools and scripts to execute test cases and verify the application's behavior.

3- A test suite is a collection of related test cases or tests that are grouped together, cases are individual test scenarios that verify the correctness of a particular function, method, or behavior of the software.

`// Test Suite: Math Operations
describe('Math Operations', () => {

// Test Case: Addition
it('should correctly add two numbers', () => {
const result = add(2, 3);
expect(result).toBe(5);
});

// Test Case: Subtraction
it('should correctly subtract two numbers', () => {
const result = subtract(5, 2);
expect(result).toBe(3);
});

// Test Case: Multiplication
it('should correctly multiply two numbers', () => {
const result = multiply(4, 3);
expect(result).toBe(12);
});

// Test Case: Division
it('should correctly divide two numbers', () => {
const result = divide(10, 2);
expect(result).toBe(5);
});

});
`

4- Test-driven development (TDD) is a coding practice where you write the result you want your program to produce before creating the program. In TDD, the development process follows a cycle of writing a failing test, implementing the minimum amount of code required to pass the test, and then refactoring the code if necessary. This cycle is repeated for each new feature or change. By following the TDD approach, developers can produce more robust and reliable code. TDD encourages a disciplined and systematic approach to development, focusing on testability, immediate feedback, and incremental progress. This leads to improved code quality, reduced bugs, increased confidence in code changes, and enhanced collaboration among developers.

5- Some popular testing frameworks can be listed as
MochaJS
Jest
Jasmine
Karma
Puppeteer (Node Library)
NightwatchJS
Playwright (Node Library)

Two widely used testing frameworks in JS are Jest and Mocha.

Jest is a versatile testing framework suitable for various types of JavaScript applications, including web applications, Node.js applications, and libraries. It works well for unit testing, integration testing, and snapshot testing scenarios.

Key features: Out-of-the-box Configuration, Assertion Library and Mocking, Snapshot Testing, Code Coverage, Parallel Test Execution


Mocha is well-suited for projects that require flexibility and customization. It is commonly used in large-scale applications, frameworks, and projects that demand a more tailored testing setup. Mocha's flexibility also makes it suitable for projects that span multiple technologies and testing scenarios.

Key features: Flexible and Extensible, Support for Different Test Styles, Asynchronous Testing, Test Runner, Wide Ecosystem

In summary, Jest provides an all-in-one testing solution with built-in features like configuration, assertion library, mocking, and code coverage. It works well for a wide range of JavaScript applications. On the other hand, Mocha offers flexibility, allowing you to customize your testing setup using different assertion libraries and mocking libraries. It is suitable for projects that require more control and customization in their testing approach.

@abdulsalamhamandoush22
Copy link

Abdulsalam Hamandoush &&& Ahmad Al-Ashtar &&& Zakaria Ali room 11

  1. unit testing in JavaScript development helps ensure the correctness, reliability, and maintainability of individual units of code. It contributes to the overall quality of a software application by detecting bugs early, promoting good coding practices, preventing regressions, facilitating refactoring, acting as documentation, and supporting collaboration and efficient development processes.

  2. Manual testing involves human testers executing test cases, while automated testing uses scripts or testing frameworks to automate test execution. Automated testing in JavaScript projects offers efficiency, repeatability, time savings, increased test coverage, reliability, integration with CI/CD, and cost-effectiveness compared to manual testing.

  3. A test suite refers to a collection of test cases that are grouped together based on a common functionality or a specific module/component of the software application. It represents a higher-level organizational structure that contains multiple individual test cases, allowing for better management and execution of tests.

EXAMPLE:

// Test Suite: Calculator
describe('Calculator', () => {
// Test Case 1: Addition
test('should correctly add two numbers', () => {
// Test input and expected output
const result = add(2, 3);

// Assertion
expect(result).toBe(5);

});

// Test Case 2: Subtraction
test('should correctly subtract two numbers', () => {
// Test input and expected output
const result = subtract(5, 3);

// Assertion
expect(result).toBe(2);

});

// Test Case 3: Division
test('should correctly divide two numbers', () => {
// Test input and expected output
const result = divide(10, 2);

// Assertion
expect(result).toBe(5);

});
});

// Test Suite: String Utilities
describe('String Utilities', () => {
// Test Case 1: Capitalize
test('should capitalize the first letter of a string', () => {
// Test input and expected output
const result = capitalize('hello');

// Assertion
expect(result).toBe('Hello');

});

// Test Case 2: Reverse
test('should reverse a string', () => {
// Test input and expected output
const result = reverseString('hello');

// Assertion
expect(result).toBe('olleh');

});
});

  1. Test-driven development (TDD) is a methodology where tests are written before code. It improves code quality by ensuring clear requirements, better design, high code coverage, early bug detection, regression prevention, and increased confidence in code changes. TDD enhances the development process and leads to robust and reliable code.

  2. Jest is a comprehensive testing framework that provides a full-featured testing solution out of the box, including assertion library, mocking, snapshot testing, and code coverage. It is popular in the React ecosystem and favors convention over configuration. On the other hand, Mocha is a flexible framework that allows developers to choose their preferred assertion and mocking libraries, making it suitable for different types of JavaScript projects. It offers excellent support for asynchronous testing and provides more control and customization options for test organization and execution.

@2O0K
Copy link

2O0K commented May 20, 2023

Team members : rayan alrouh + @tareqharh + @TesnimNakilci + khaled Naes + Harith Riyadh

  1. The purpose of unit testing in JavaScript development is to verify that individual units of code, such as functions or classes, work as intended. It contributes to the overall quality of a software application by detecting errors early, providing code confidence, acting as documentation, preventing regressions, facilitating refactoring, and supporting continuous integration and deployment.

  2. Automated testing: is the process in which testers utilize tools and scripts to automate testing efforts.
    Manual testing: is the process in which QA analysts execute tests one-by-one in an individual manner.
    The biggest difference between manual and automation testing is who executes the test case. In manual testing, the human tester does it. In automation testing, the tool does it.
    the advantage of using automated testing is it saves time for comparing the manual testing.

  3. A test suite also acts as a container for test cases. It also has multiple stages for specifying the status of the test execution process, like in-progress, active, and completed. It is also known as the validations suite, with detailed information and objectives for different test cases and system configurations required for testing.
    Once you create a test plan, test suites are created, which can have multiple test cases.
    For example, we make a test suite for math operations as follows:
    describe("Math Operations", () => {

             // Test Case 1: Addition
             test("Adds two numbers correctly", () => {
               expect(add(2, 3)).toBe(5);
             });
           
             // Test Case 2: Subtraction
             test("Subtracts two numbers correctly", () => {
               expect(subtract(5, 3)).toBe(2);
             });
           
             // Test Case 3: Division
             test("Divides two numbers correctly", () => {
               expect(divide(10, 2)).toBe(5);
             });
           });
    
  4. Test-driven development (TDD) in JavaScript is an approach where tests are written before writing the actual code. It influences the development process by clarifying requirements, improving code quality, detecting errors early, preventing regressions, enabling confident refactoring, and providing a faster feedback loop. TDD helps in writing robust and reliable code by ensuring comprehensive test coverage and promoting modular and maintainable code design. In other words, TDD requires you to pre-specify the output your intended program must produce to pass the test of functioning the way you envisioned.

  5. MochaJS vs JEST

  • Mocha is a little more complicated than Jest when it comes to ease of use. Jest is designed to be simple and straightforward, while Mocha has more options and can be more difficult to learn. However, Mocha can be pretty powerful once you know how to use it.

  • Jest is also faster than Mocha. It has built-in support for snapshot testing, which means tests are run automatically on each change to the code. This makes it easy to keep your tests up to date as you work.

  • Mocha has more features out of the box since it is a more mature tool with a larger community of contributors. Jest has fewer features than Mocha and doesn’t support some valuable things like asynchronous tests.

In summary, Jest is a comprehensive testing framework for JavaScript applications, while Mocha offers flexibility and extensibility, particularly for asynchronous testing and Node.js projects.

@jimaa-maya
Copy link

@sheidanouri, @OmarQaqish, @noorin99, @jimaa-maya, Atakan Serbes.

1-The main objective of unit testing is to isolate written code to test and determine if it works as intended, Unit testing contributes to the overall quality of a software application in several ways:
A- Bug detection and prevention.
B- Code maintainability.
C-Refactoring and code evolution.
D-Regression prevention.
E-Facilitates collaboration.
F-Automated testing and CI/CD.

2-In manual testing, a human performs the tests step by step, without test scripts. In automated testing, tests are executed automatically via test automation frameworks, along with other tools and software.
A-Greater accuracy.
B-Cost saving.
C-Reduces regression testing time.
D-Performs tasks that cannot be done by manual testers.
E-Reusability of test scripts.
F-Time Saving.
G-Maximum Test Coverage.
H- Scalability.

3-In software development, a test suite, less commonly known as a validation suite, is a collection of test cases that are intended to be used to test a software program to show that it has some specified set of behaviors.
Test suites group related test cases together, providing organization and structure to the testing process in JavaScript. Test cases represent specific scenarios and are organized within test suites for effective testing and validation of code behavior.
Test suites can identify gaps in a testing effort where the successful completion of one test case must occur before you begin the next test case. For instance, you cannot add new products to a shopping cart before you successfully log in to the application. When you run a test suite in sequential mode, you can choose to stop the suite execution if a single test case does not pass. Stopping the execution is useful if running a test case in a test suite depends on the success of previous test cases.

4-Test Driven Development (TDD)'s main idea is to simply start working on code by writing automated tests BEFORE writing the code that is being tested. There are many test-running systems in Javascript: Jasmine, Jest, Tape, and Mocha to name a few. They have their special features but the syntax is very similar.
Test driven development helps you create more robust, reliable code. Because TDD tests are written before the code is written, it helps developers think through all possible scenarios and create a more comprehensive final product.
TDD improves code quality by emphasizing writing tests before code, leading to more thoughtful implementation and comprehensive test coverage.
It facilitates faster debugging and refactoring cycles, as failing tests pinpoint issues and provide a safety net for making changes.
TDD promotes better design, continuous feedback, and increased developer confidence, resulting in robust and reliable code.

5-
A. MochaJS
B. Jest
C. Jasmine
D. Karma
E. Puppeteer (Node Library)
F. NightwatchJS
G. Cypress
H. Playwright (Node Library)
I. Selenium

Mocha is a mature testing tool that has been around for many years. It has a large user base and is well-supported. Jest is a newer tool created by the team at Facebook. It has many of the same features as Mocha and some unique advantages.

Mocha is a little more complicated than Jest when it comes to ease of use. Jest is designed to be simple and straightforward, while Mocha has more options and can be more difficult to learn. However, Mocha can be pretty powerful once you know how to use it.

Jest is also faster than Mocha. It has built-in support for snapshot testing, which means tests are run automatically on each change to the code. This makes it easy to keep your tests up to date as you work.
aslo:
Mocha
Supports asynchronous testing with done() callback

Jest
Automatically runs tests after each change to ensure they are up to date. Many users report that this reduces development time.

Mocha
Supports mocking, which lets you avoid slow network requests during tests. Supports BDD syntax. Allows users to define their own assert functions.

Jest
Automatically mocks any modules not explicitly required in the test file, which can save time during development.

@Eng-NUREDDIN
Copy link

@Eng.NUREDDIN @HishamWattar @JoudKh22 @talal-bakkour

1-(npm test/yarn test) Unit testing in JavaScript development involves writing small tests to verify the behavior of individual units of code, such as functions or methods, It verifies whether a small and isolated piece of the codebase called “unit” behaves as the developer intended. It serves the following purposes:

Early bug detection: Identifying issues in the code early in the development cycle.
Code maintainability: Acting as documentation and making code easier to understand and maintain.
Regression prevention: Validating that existing functionality is not broken by changes.
Improved design: Encouraging modular and loosely coupled code.
Confidence and productivity: Providing developers with confidence in their code and increasing productivity.
By following a test-driven development approach, where tests are written before the code, developers ensure that their code meets requirements and functions correctly. This systematic testing improves the overall quality and reliability of software applications.

2- In manual testing, a human performs the tests step by step, without test scripts. In automated testing, tests are executed automatically via test automation frameworks and other tools and software.
The biggest difference between manual and automation testing is who executes the test case. In manual testing, the human tester does it. In automation testing, the tool does it.
Done automatically using automation tools and scripts
More testing in less time and greater efficiency
Most tasks can be automated, including real-user simulations
Easy to ensure greater test coverage

3- Test suites are the logical grouping or collection of test cases to run a single job with different test scenarios.
so it is a container with a set of tests which helps testers execute and report the test execution status. It can take any of the three states namely Active, in progress and completed.

For instance, a test suite for product purchase has multiple test cases, like:

Test Case 1: Login
Test Case 2: Adding Products
Test Case 3: Checkout
Test Case 4: Logout

4- Test-driven development (TDD) is an approach where tests are written before writing the code. It follows a cycle of writing failing tests, implementing the minimum code to make the tests pass, and then refactoring the code. TDD influences the development process and code quality by clarifying requirements, ensuring test coverage, simplifying design, detecting bugs early, preventing regressions, and building code confidence. Overall, TDD promotes disciplined development, improves code quality, and leads to robust and reliable JavaScript code.


5-

@sncey
Copy link

sncey commented May 20, 2023

@tomiece317 @ilaydanurguzel1 @saidbaradai @Abd2023

1- Unit testing in JavaScript development improves the overall quality of software applications by detecting errors early, providing code confidence, supporting refactoring efforts, aiding collaboration, and preventing regressions. It promotes stability, maintainability, and reliability throughout the development process.

2- Manual testing and automated testing are two approaches to testing software applications. Manual testing refers to the process of manually executing test cases to identify defects and ensure that the software meets the specified requirements. In this approach, testers perform various tests on the application by interacting with it as end-users would. Automated testing involves using specialized tools and scripts to automate the execution of test cases. Test scripts are created to simulate user interactions, validate expected results, and compare them with actual outcomes. Advantages of Automated Testing in JavaScript projects: -Time and Cost Efficiency -Increased Test Coverage -Improved Accuracy -Regression Testing -Continuous Integration and Delivery.

3- A test suite is a collection of test cases that are grouped together based on a common functionality, module, or component of the software application being tested. It serves as a container for organizing and executing related tests.
Test cases, on the other hand, are individual units of testing that define a specific scenario or condition to be tested. They typically consist of a set of inputs, actions, and expected outcomes.

Test Suite: Addition Operations:
Test Case 1: add(5, 10) => 15
Test Case 2: add(-7, -3) => -10
Test Case 3: add(0, 8) => 8

Test Suite: Subtraction Operations:
Test Case 1: subtract(15, 7) => 8
Test Case 2: subtract(-12, -5) => -7
Test Case 3: subtract(10, 0) => 10

4- Test-driven development (TDD) is an approach where tests are written before the code. It improves code quality, detects bugs early, promotes better code design, increases confidence, and provides faster feedback loops in JavaScript development.

5- Jest is a user-friendly and comprehensive testing framework with built-in mocking capabilities, suitable for React, Vue.js, and Node.js applications. Mocha provides flexibility and customization options, supporting various testing styles and allowing developers to choose their preferred assertion libraries and test runners. Jest focuses on simplicity and productivity, while Mocha offers extensibility and is commonly used for backend applications and JavaScript libraries.

@idincer944
Copy link

Members: @idincer944 İsmail | @irzooqi Yasir Irzooqi | @Gullied Guled Khadar Abdi | Adib Naser

  1. The purpose of unit testing in JavaScript development is to verify the correctness and reliability of individual units, or small isolated parts, of code. It involves writing test cases that specifically target and validate the behavior of these units, typically functions or methods. Unit testing contributes to the overall quality of a software application by reducing bugs, improving maintainability and scalability, fostering collaboration, and enabling efficient development and deployment processes.

Manual Testing:
Manual testing involves human testers executing test cases manually, step by step, without the aid of any automated tools. Testers interact with the software application as end-users would, exploring its features, functionalities, and user interfaces. They observe the system's behavior, identify bugs, and report their findings.

Automated Testing:
Automated testing involves using specialized software tools to execute pre-scripted tests automatically. Testers create test scripts or test cases using programming languages or dedicated test automation frameworks. These scripts interact with the software application programmatically, simulating user actions and verifying expected outcomes.

Advantages of automated testing:
Faster, more reliable, more accurate, easier to document and it makes it easier to understand the code.

  1. You develop test cases to define the things that you must validate to ensure that the system is working correctly and is built with a high level of quality. A test suite is a collection of test cases that are grouped for test execution purposes.

// Test suite for the add function

describe("add", () => {
it("should add two numbers together correctly", () => {
expect(add(1, 2)).toBe(3);
});

it("should handle negative numbers correctly", () => {
expect(add(-1, -2)).toBe(-3);
});

it("should handle numbers that are too large for the JavaScript number type correctly", () => {
expect(add(Number.MAX_SAFE_INTEGER, 1)).toBe(Number.MAX_SAFE_INTEGER);
});
});

  1. Test-driven development (TDD) is a software development process that relies on the repetition of a very short development cycle: first the developer writes a failing unit test case that defines a desired improvement or new function, then produces the minimum amount of code to pass that test, and finally refactors the new code to acceptable standards.

TDD is a popular technique for improving the quality of software. It helps to ensure that code is well-tested and that changes to the code do not break existing functionality. TDD can also help to improve the design of code by forcing developers to think about the expected behavior of the code before they start writing it.

Test-driven development is a software development process relying on software requirements being converted to test cases before software is fully developed, and tracking all software development by repeatedly testing the software against all test cases. This is as opposed to software being developed first and test cases created later.

Mocha
Jest
Jasmine
Karma
Puppeteer
NightwatchJS
Cypress
Playwright
Selenium

Mocha

Mocha is a feature-rich testing framework that is easy to use and configure. It supports asynchronous testing, which makes it ideal for testing JavaScript code that makes use of asynchronous APIs. Mocha also has a large community of users and contributors, which means that there are many resources available to help you get started with it.

Jest

Jest is a fast, lightweight testing framework that is built by Facebook. It is designed to be easy to use and configure, and it supports a wide range of testing features, including asynchronous testing, mocking, and assertions. Jest also has a built-in coverage reporter, which can help you to identify areas of your code that are not being tested.

Mocha is a good choice for projects that require a feature-rich testing framework. It is also a good choice for projects that have a large community of users and contributors.

Jest is a good choice for projects that require a fast, lightweight testing framework. It is also a good choice for projects that are being developed by Facebook.

@fatimaali200
Copy link

Team: @fatimaali200 , @TasneemAkkad, @mohamadAid , Ahmad ramin
1-JavaScript unit testing allows you to test small, self-contained units of JavaScript code, which are part of a web page or web application or to isolate written code to test and determine if it works as intended.Good unit tests create testable code, which improves quality. That code will have fewer defects, which means fewer bug fixes, for faster project completion.
2-In manual testing, a human performs the tests step by step, without test scripts. In automated testing, tests are executed automatically via test automation frameworks, along with other tools and software.
a)Automated Testing Saves Time and Money
b)Vastly Increases Your Test Coverage:Automated software testing can increase the depth and scope of tests to help improve software quality.
3-In software development, a test suite, less commonly known as a validation suite, is a collection of test cases that are intended to be used to test a software program to show that it has some specified set of behaviors.

an ex code of a test suit
const mathFunctions = {
add: (a, b) => a + b,
};
module.exports = mathFunctions;
const mathFunctions = require('./mathFunctions');
describe('Math Functions', () => {
test('Addition', () => {
expect(mathFunctions.add(2, 3)).toBe(5);
expect(mathFunctions.add(-1, 1)).toBe(0);
});

4-Test-driven development (TDD) is a coding practice where you write the result you want your program to produce before creating the program. In other words, TDD requires you to pre-specify the output your intended program must produce to pass the test of functioning the way you envisioned.TDD helps you to develop the logic in your code
For example, here is a possible test suite and its corresponding test cases for testing a function that checks whether a value is an integer number1:

// isInteger.js
module.exports = (value) => !isNaN(parseInt(value, 10));

// isInteger.test.js
const isInteger = require('./isInteger');

describe('isInteger function', () => {
// Test suite for isInteger function

test('should return true for integer numbers', () => {
// Test case for integer numbers
expect(isInteger(42)).toBe(true); // Assertion
expect(isInteger(-5)).toBe(true); // Assertion
});

test('should return false for non-integer numbers', () => {
// Test case for non-integer numbers
expect(isInteger(3.14)).toBe(false); // Assertion
expect(isInteger(NaN)).toBe(false); // Assertion
});

test('should return false for non-numeric values', () => {
// Test case for non-numeric values
expect(isInteger('hello')).toBe(false); // Assertion
expect(isInteger(true)).toBe(false); // Assertion
});
});

@omikay
Copy link

omikay commented May 20, 2023

Omid Kayhani | Houzifa Haboo | Ftma Zehra Aydın | Abdurrahman Abuzaid

  1. Unit testing in JavaScript development involves writing and running tests for individual parts of code, like functions or modules. It helps catch bugs early, making it easier to fix them. Unit tests act as documentation, making code easier to understand. They prevent regressions and enable collaboration among developers. Unit tests also support continuous integration and delivery, ensuring code quality and stability. Overall, unit testing contributes to better software quality and maintainability.

  2. In manual testing, a human performs the tests step by step, without test scripts. In automated testing, tests are executed automatically via test automation frameworks, along with other tools and software. The biggest pro of automation testing over manual testing is that it allows you to do more testing in less time. It increases productivity and expands how much you can test.

  3. A test suite in JavaScript testing is a collection of related test cases that are grouped together for a specific purpose. It represents a logical unit of testing, such as a module, a class, or a feature of an application. A test suite encompasses multiple test cases that verify different aspects or scenarios of the functionality being tested. For example, a test suite for a JavaScript shopping cart module may include test cases for adding items to or removing them from the cart, calculating the total price, and applying discounts. Each test case within the suite would focus on testing a specific behavior or scenario, such as checking if the correct item is added or removed or verifying the accuracy of the calculated price.
    image

  4. Test-driven development (TDD) is a software development approach where tests are written before the code. It follows the "Red-Green-Refactor" cycle: write a failing test, implement code to make it pass, and then refactor the code.

TDD influences the development process by improving code quality, enabling regression testing, guiding code design, facilitating faster debugging, providing confidence in refactoring, promoting collaboration, and acting as executable documentation. It helps in writing robust and reliable JavaScript code by ensuring that code behavior is defined, catching bugs early, and promoting incremental and disciplined development.

  1. Jest and Mocha are among the most popular testing frameworks in JS.

Jest is a comprehensive testing framework with built-in assertions, mocking, snapshot testing, and code coverage, making it an excellent choice for JavaScript projects, particularly those using React or Vue. On the other hand, Mocha offers more flexibility and customizability, allowing developers to choose their preferred assertion and mocking libraries. It excels in handling asynchronous code and is suitable for a wide range of JavaScript projects, including frontend and backend applications.

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