Instructions

  • 1. Your final score will reflect your grasp of the concepts—approach each question with precision.
  • 2. Thoroughly review each solution before proceeding to ensure full understanding.
  • 3. Final results will be available after submission to provide insights into areas for further improvement.
  • 4. Maintain academic integrity—plagiarism undermines learning and professional growth.
  • 5. Once submitted, responses are final, so ensure you’re confident in your answers.
  • 6. These challenges are designed to test practical knowledge; apply your skills as you would in real-world scenarios.

All Problems

Question

Action

What is the primary purpose of mocking in unit testing?

View

Which of the following best describes a "spy" in unit testing?

View

What is a "stub" in the context of unit testing?

View

Which type of test is typically more expensive and time-consuming than unit tests?

View

Why should unit tests be isolated from each other?

View

Which of the following is a key difference between unit and integration testing?

View

In unit testing, what is code coverage?

View

Which of the following tools can be used to measure code coverage in JavaScript?

View

Why is testing edge cases important in unit tests?

View

Which Jest method resets all mocks and clears their usage data?

View

What is the primary purpose of mocking in unit testing?

To test the actual external services
To simulate external dependencies or APIs
To generate test data automatically
To run tests in parallel

Which of the following best describes a "spy" in unit testing?

A test case that runs conditionally
A function that records interactions with the code
A function that runs in the background
A hidden function used to generate logs

What is a "stub" in the context of unit testing?

A temporary placeholder for a function or method
A mock that replaces the actual implementation
A testing library for generating logs
A function that throws an error

Which type of test is typically more expensive and time-consuming than unit tests?

Performance tests
Integration tests
UI tests
Acceptance tests

Why should unit tests be isolated from each other?

To run them in parallel
To ensure they don't fail because of dependencies
To reduce the number of tests
To avoid testing edge cases

Which of the following is a key difference between unit and integration testing?

Unit tests test interactions between modules
Unit tests are slower than integration tests
Integration tests check how different parts of the application work together
Integration tests are not necessary

In unit testing, what is code coverage?

The amount of time tests take to run
The percentage of the code that is executed by tests
The number of external libraries tested
The total number of test cases written

Which of the following tools can be used to measure code coverage in JavaScript?

ESLint
Babel
Istanbul
Prettier

Why is testing edge cases important in unit tests?

To ensure code works only in typical scenarios
To reduce the overall complexity of the test suite
To validate the code's behavior in unusual or boundary conditions
To skip the testing of error-handling code

Which Jest method resets all mocks and clears their usage data?

resetAllMocks()
clearMocks()
jest.resetMocks()
jest.resetAllMocks()