1. What is the primary goal of unit testing?
a) To test the entire application
b) To test individual components in isolation
c) To find performance bottlenecks
d) To verify the user interface
Answer: b) To test individual components in isolation
2. Which of the following is not a common unit testing framework for Java?
a) JUnit
b) TestNG
c) PyTest
d) Mockito
Answer: c) PyTest
3. What is a "test fixture" in unit testing?
a) A test case
b) A collection of test cases
c) A setup and cleanup code for a test case
d) A testing tool
Answer: c) A setup and cleanup code for a test case
4. Which testing principle suggests that tests should be independent and not rely on the order of execution?
a) Code coverage
b) Test isolation
c) Test-driven development
d) Test automation
Answer: b) Test isolation
5. In unit testing, what is a "mock object" used for?
a) Simulating real objects that are expensive or complex
b) Testing only the public API of a class
c) Verifying code coverage
d) Measuring performance
Answer: a) Simulating real objects that are expensive or complex
6. What is the purpose of a test double in unit testing?
a) It's a fake test case
b) It's a placeholder for unfinished tests
c) It stands in for a real object to facilitate testing
d) It's an alternative name for a test case
Answer: c) It stands in for a real object to facilitate testing
7. Which testing approach focuses on writing tests before writing the actual code?
a) Unit testing
b) Integration testing
c) Test-driven development (TDD)
d) Regression testing
Answer: c) Test-driven development (TDD)
8. What is a "code coverage" metric used for in unit testing?
a) Measuring the quality of the code
b) Identifying code that is not executed by tests
c) Counting the lines of code in a project
d) Measuring test execution time
Answer: b) Identifying code that is not executed by tests
9. Which assertion method is commonly used in JUnit to check if two values are equal?
a) assertTrue()
b) assertEquals()
c) assertSame()
d) assertEqual()
Answer: b) assertEquals()
10. What is the purpose of a "test harness" in unit testing?
a) To make tests run faster
b) To generate test data automatically
c) To set up the test environment and execute test cases
d) To collect code coverage data
Answer: c) To set up the test environment and execute test cases
11. Which of the following is a common pattern for organizing unit tests in a project?
a) Test spaghetti
b) Test factory
c) Test pyramid
d) Test bridge
Answer: c) Test pyramid
12. What does "Arrange, Act, Assert" (AAA) stand for in unit testing?
a) A programming paradigm
b) A testing framework
c) A testing pattern for structuring tests
d) A software architecture pattern
Answer: c) A testing pattern for structuring tests
13. What is the purpose of a "test runner" in unit testing?
a) To write test cases
b) To execute test cases and report results
c) To create mock objects
d) To generate code coverage reports
Answer: b) To execute test cases and report results
14. Which type of testing focuses on the interaction between different components or modules of a system?
a) Unit testing
b) Integration testing
c) System testing
d) Acceptance testing
Answer: b) Integration testing
15. Which of the following is not a commonly used mocking framework in Java?
a) JMock
b) Mockito
c) PowerMock
d) Jest
Answer: d) Jest
16. What is the purpose of a "test double" in unit testing?
a) To make tests run faster
b) To replace real code with simulated or controlled code
c) To run tests in parallel
d) To generate random test data
Answer: b) To replace real code with simulated or controlled code
17. In unit testing, what is the purpose of a "test runner"?
a) To generate test data
b) To execute test cases and report results
c) To create mock objects
d) To measure code coverage
Answer: b) To execute test cases and report results
18. What is the primary objective of "mutation testing"?
a) To test individual units of code
b) To generate random test data
c) To measure code coverage
d) To evaluate the quality of test cases by introducing artificial defects
Answer: d) To evaluate the quality of test cases by introducing artificial defects
19. What is the purpose of the "teardown" phase in unit testing?
a) To set up the test environment
b) To execute the test case
c) To clean up resources and return the system to its original state
d) To generate code coverage reports
Answer: c) To clean up resources and return the system to its original state
20. Which unit testing framework is often used for testing JavaScript code?
a) JUnit
b) TestNG
c) Mocha
d) PyTest
Answer: c) Mocha
21. What is "stubbing" in the context of mocking in unit testing?
a) Creating a fake object with real behavior
b) Replacing a method with a fake implementation
c) Measuring the execution time of a method
d) Testing a method without any mocks
Answer: b) Replacing a method with a fake implementation
22. Which of the following is not a common assertion method in JUnit?
a) assertArrayEquals()
b) assertNotNull()
c) assertNotEquals()
d) assertEmpty()
Answer: d) assertEmpty()
23. What is "test coverage" in the context of unit testing?
a) A measure of how many test cases have been executed
b) A measure of how much of the code is exercised by tests
c) A measure of how many lines of code are in a project
d) A measure of how many unit tests have been written
Answer: b) A measure of how much of the code is exercised by tests
24. Which of the following is a common anti-pattern in unit testing?
a) Over-testing
b) Test-driven development (TDD)
c) Test isolation
d) Test harness
Answer: a) Over-testing
25. What is a "spike" in the context of unit testing?
a) A testing framework
b) A type of unit test
c) A short, time-boxed investigation into a specific problem
d) A test double
Answer: c) A short, time-boxed investigation into a specific problem
26. In unit testing, what does "test granularity" refer to?
a) The size of the test case code
b) The level of detail and scope of the tests
c) The testing tool used
d) The order in which tests are executed
Answer: b) The level of detail and scope of the tests
27. What is a "test smell" in unit testing?
a) A pleasant aroma during test execution
b) A bad practice or warning sign indicating issues in the test code
c) A type of assertion
d) A term for code coverage problems
Answer: b) A bad practice or warning sign indicating issues in the test code
28. Which of the following is not a benefit of unit testing?
a) Improved code quality
b) Faster development
c) Early bug detection
d) Reduced development costs
Answer: b) Faster development
29. What is "mockito" primarily used for in unit testing?
a) Creating mock objects
b) Running unit tests
c) Measuring code coverage
d) Writing test cases
Answer: a) Creating mock objects
30. Which type of testing is performed by testers who were not involved in the development of the code?
a) Unit testing
b) Integration testing
c) System testing
d) Acceptance testing
Answer: d) Acceptance testing
31. What is the purpose of "test-driven development" (TDD)?
a) To write tests after the code is written
b) To write code without any tests
c) To write tests before writing the actual code
d) To focus on system-level testing
Answer: c) To write tests before writing the actual code
Top comments (0)