🧪 Testing & Frameworks

 ðŸ§ª What is Testing?

Testing is the process of checking whether your application works as expected. It helps you:


Catch bugs early


Ensure code quality


Prevent regressions (bugs that come back)


Gain confidence in deploying changes


🧰 Types of Testing

Type Description Example Tool

Unit Testing Test individual functions/components Jest, Mocha

Integration Test multiple parts working together Supertest, Chai

End-to-End (E2E) Test full workflows like a user would Cypress, Playwright

Manual Testing Click and test the UI manually No tools (human check)

API Testing Verify backend APIs respond correctly Postman, Insomnia


⚙️ Testing in MERN Stack

1. Node.js + Express (Backend)

Frameworks & Tools:

Jest – Testing framework


Supertest – HTTP assertions for API testing


Mocha & Chai – Alternatives to Jest


Example:

js

Copy

Edit

// app.test.js

const request = require('supertest');

const app = require('./app');


test('GET /api/upload should return 200', async () => {

  const res = await request(app).get('/api/upload');

  expect(res.statusCode).toBe(200);

});

2. React (Frontend)

Frameworks & Tools:

Jest – Built into Create React App


React Testing Library (RTL) – Test components as users would use them


Cypress – For full end-to-end browser tests


Example:

jsx

Copy

Edit

// FileUpload.test.js

import { render, screen } from '@testing-library/react';

import FileUpload from './FileUpload';


test('renders upload button', () => {

  render(<FileUpload />);

  const button = screen.getByText(/upload/i);

  expect(button).toBeInTheDocument();

});

3. MongoDB (Database)

Use in-memory databases like mongodb-memory-server for fast and isolated tests.


Mock or stub DB calls using tools like Sinon or Jest Mocks.


Example:

js

Copy

Edit

// Mocking MongoDB call

jest.mock('../models/File', () => ({

  create: jest.fn().mockResolvedValue({ filename: 'test.jpg' })

}));

🔄 Test Automation Workflow (Example)

Write test files alongside your code.


Run tests locally using npm test.


Use CI/CD pipelines (like GitHub Actions or Jenkins) to run tests automatically on push.


Fix failing tests before deploying.


✅ Best Practices

Write small, focused tests (test one thing at a time)


Use mocking to isolate components and services


Automate your tests in CI/CD


Keep test coverage high, but meaningful


Name tests clearly to describe what’s being tested


🚀 Summary

Testing improves code quality and reliability


Use Jest and Supertest for Node.js APIs


Use React Testing Library or Cypress for frontend tests


Keep tests fast and meaningful

Learn Selenium Python Training in Hyderabad

Read More

How to Read Data from Excel or CSV for Selenium Test Automation

Selenium with Python for Testing Login Pages

Taking Screenshots with Selenium WebDriver in Python

How to Handle Multiple Browser Tabs or Windows in Selenium

Visit Our Quality Thought Training in Hyderabad

Get Directions

Comments

Popular posts from this blog

Understanding Snowflake Editions: Standard, Enterprise, Business Critical

Why Data Science Course?

How To Do Medical Coding Course?