Web Testing & Debugging MCQs for the NSCT
Web testing checks automatically that a site behaves as specified, through unit, integration and end-to-end (E2E) tests, while debugging finds the cause of a failure, mostly with the browser's developer tools (DevTools). It is the 14th of the 17 topics in the Web Development area, which carries 10% of the NSCT according to HEC's Areas of Competencies.
HEC's NSCT report shows analysis questions had the lowest accuracy nationally (44.8%), and this topic is rich in them: a flaky test, a CORS error or a leak to diagnose. Most code here is JavaScript, so revise promises and the event loop too.
DevTools
Browser developer tools (F12 in Chrome, Edge and Firefox) let you inspect and pause a running page. Know what each panel is for:
| Panel | Use it to |
|---|---|
| Elements | Inspect the live DOM, edit CSS, see event listeners |
| Console | Read errors, run JavaScript, console.table, console.assert |
| Sources | Set breakpoints, step through code, use source maps |
| Network | See each request's status, headers, payload, timing; throttle |
| Performance | Record a trace to find long tasks and layout work |
| Memory | Take heap snapshots to find leaks |
| Application | Cookies, localStorage, IndexedDB, service workers |
Breakpoints and stepping
A line breakpoint pauses at a line. A conditional breakpoint pauses only when an expression is true, for example i === 99. A logpoint logs without pausing. DOM change breakpoints pause when an element's subtree or attributes change, and event listener breakpoints pause in any handler for an event such as click. The debugger; statement is a breakpoint written in code.
While paused, step over runs a call as one step, step into enters the function, and step out finishes the current function.
Exam angle: "which panel" questions are easy marks. Network shows the request and response; Application shows storage.
Unit and end-to-end testing
A unit test checks one function or component in isolation. An integration test checks several parts working together, such as a route and its database. An E2E test drives a real browser through a full user flow.
| Unit | Integration | End-to-end | |
|---|---|---|---|
| Scope | One function | A few modules | Whole app |
| Speed | Milliseconds | Hundreds of ms | Seconds |
| Typical tools | Jest, Vitest, Mocha | Jest with a test DB, Supertest | Playwright, Cypress, Selenium |
| How many | Many | Some | Few |
The testing pyramid keeps many fast unit tests at the base and few slow, brittle E2E tests on top. Its upside-down version, the "ice-cream cone", gives slow and flaky builds.
Test doubles replace real dependencies. Following Meszaros and Fowler, a stub returns canned data, a mock also verifies that expected calls happened, a fake is a simpler working version (such as an in-memory database) and a dummy is only a placeholder. Frameworks often call everything a "mock", so read the definition in the question.
Code coverage reports what ran: statement coverage counts executed statements, and branch coverage counts true and false outcomes. With 18 of 20 statements and 3 of 4 branches executed, coverage is 90% and 75%. Coverage measures execution, not correctness.
In TDD (test-driven development) you cycle red (write a failing test), green (make it pass), refactor. Regression testing reruns the suite after every change.
Exam angle: an assertion that runs before a promise resolves tests nothing. Return or await the promise.
Common traps
- Confusing step over with step into.
- Treating 100% coverage as proof that code is correct.
- Calling
console.asserta thrower. It only logs when the condition is false. - Fixing a flaky E2E test with a longer
sleepinstead of waiting for a condition. - Trying to fix a CORS error in front-end code. The server must send the header.
- Comparing objects or floats with strict equality in assertions.
Worked examples
1. Understanding. Which kind of test should be most numerous in a healthy suite? Answer: unit tests. They are fastest and most stable, so the pyramid puts them at the base.
2. Application. A loop runs 1,000 times and fails only when i is 734. How do you stop at that iteration without clicking Resume 734 times?
Answer: add a conditional breakpoint with i === 734 on the line inside the loop.
3. Analysis. A test checks that getTotal() returns 0.6 for items priced 0.1, 0.2 and 0.3, using strict equality, and it fails. The code adds the prices correctly. What is wrong?
Answer: in binary floating point, 0.1 + 0.2 + 0.3 is 0.6000000000000001, so strict equality fails. Assert with a tolerance (for example toBeCloseTo) or keep money in integer units such as paisa.
Practise
The quiz below has 100 questions on this topic, filterable by tier and difficulty.
Practise: 100 questions
FAQs
What is the difference between unit testing and end-to-end testing?
A unit test checks one function or component alone, with dependencies replaced by stubs or mocks, and runs in milliseconds. An end-to-end test drives a real browser through a whole flow, such as login to checkout, across frontend, backend and database. It catches integration problems but is slower and more fragile.
Which DevTools panel should I open first when an API call fails?
Open the Network panel and select the request. It shows the status code, request headers, the payload you sent and the response body. Then check the Console for errors such as CORS blocks, and use the Sources panel to pause in the code that made the call.
Is Jest a unit-testing or an end-to-end tool?
Jest is mainly a unit and integration test runner for JavaScript. It runs in Node.js, often with a simulated DOM, and includes assertions, mocks and coverage. For true end-to-end tests in real browsers, teams use Playwright, Cypress or Selenium alongside it.
How do I make a flaky test reliable?
Find the source of non-determinism. Replace fixed sleeps with waits for a condition, give every test fresh data instead of shared state, replace real network calls with stubs in unit tests, and control time and randomness. Only quarantine a test while you fix it.
Next step
Continue with Deployment & Hosting, the next topic in HEC's order. You can also return to the Web Development MCQs hub or test yourself in an NSCT mock test.