Module 3: Basic Testing
Knowledge Check: Introduction to software testing
Practice Assignment
1. Which type of functional testing is used to test individual components?
- Integration testing
- Performance testing
- Unit testing
- Acceptance testing
2. Complete the sentence: Advantages of automated testing include…
Select all that apply.
- Requires less initial effort.
- Increased test coverage.
- Better suitability for repetitive tasks and higher accuracy.
- Faster execution of tests.
3. Which of the following are components of a well-defined test case? Select all that apply.
- Test case ID
- Screenshots of the application.
- Preconditions
- Expected results
4. What is the primary benefit of Git for version control in software development?
- It enables tracking changes and collaboration among project team members.
- Git can always automatically merge all conflicts between developers.
- Git is a remote-only version control system and so allows you to store the repository remotely. Since it is remote-only it saves you space on your local machine.
- It enables direct file transfer between members.
5. You have edited a file named Calculator.java. What is the correct sequence of next steps to save the changes to the Git repository?
- Commit, add, modify file.
- Add, modify file, commit
- Modify file, add, commit.
- Modify file, commit, add.
Knowledge Check: JUnit testing
Practice Assignment
6. True or false: JUnit Is a framework for writing and running tests?
- True
- False.
7. Which annotation in JUnit 5 is used to indicate that a method is a test?
- @AfterAll
- @BeforeEach
- @Test
- @AfterEach
8. You are writing a test class in JUnit 5. You want to run some setup code which should be executed before each test method. Which annotation should you use?
- @Before
- @BeforeEach
- @BeforeAll
- @AfterEach
9. Which annotation is used to indicate that the values for the parameters of the test method will be passed using @ValueSource or @CsvSource? The test method should use these values automatically to run the the same test method multiple times with values provided via @ValueSource or @CsvSource.
- @Test
- @ParameterizedTest
- @CsvSource
- @ValueSource
10. What is the purpose of a test suite in JUnit 5?
- To compile the test classes.
- To group multiple test classes together and run them as a single unit.
- To exclude some test classes.
- To generate test data automatically.
Knowledge Check: TDD
Practice Assignment
11. Which of the following is a direct benefit of using Test-Driven Development (TDD)?
- TDD removes the dependency on version control systems like Git.
- TDD decreases dependency on debugging tools.
- TDD guarantees that the software will be completely free from bugs.
- TDD helps reduce the number of developers in a project.
12. True or false: The objective of Test-Driven Development (TDD) is to ensure that specifications are set out as test cases.
- True
- False
13. A developer writes a test for a new feature to check that the username and password passed are the same. The test fails because no such feature is in the code yet. Which phase of TDD is the developer in now?
- Refactor
- Deployment
- Red
- Green
14. What does refactoring accomplish?
- Refactoring codes to make the test pass.
- Refactoring increases the number of times the test runs with different values.
- Refactoring makes the test fail.
- Refactoring makes the code better, improves quality, and removes duplication.
15. You are developing new software with TDD that calculates the total installments payable to a bank account. You have written a test to verify that the software correctly calculates the total installments. Your tests fail. What should you do next?
- Write the full amount of code to create all required functionality.
- Implement the refactor phase of TDD.
- Deploy the code.
- Write the minimum amount of code necessary to make the failing test pass.
Module Quiz: Basic testing
Practice Assignment
16. Which of the following is used for black box testing? Select all that apply.
- Acceptance testing
- System testing
- Integration testing
- Unit testing
17. Which of the following is an advantage of automated testing over manual testing? Select all that apply.
- More flexible
- Consistent repetition of tests
- Detects complex issues via observation
- Faster execution time
18. Which of the following components are included in a test case? Select all that apply.
- Pre-conditions
- A set of instructions
- Deadline for testing
- Expected results
19. What is the first step when writing a test case for a feature?
- Identify the test scenario or feature to be tested.
- Define the expected result.
- Write the test scripts.
- Write the actual results.
20. Which of the following automated tools are used to test core Java applications? Select all that apply.
- TestNG
- Jenkins
- Selenium
- JUnit
21. True or False: Version control systems are primarily used to test code.
- False
- True
22. You are working on a new project in IntelliJ and want to set up Git for version control. After creating the project, what is the first step to start using Git for the project?
- Initialize the repository with git init.
- Create a new branch.
- Clone the repository for Git.
- Run the git addcommand to create the repository.
23. You are developing a new feature using test-driven development in Java. How does JUnit help in the TDD process. Select all that apply.
- It allows you to test the functionality of all the features of the Java program.
- It allows you to write tests before implementing the feature.
- It facilitates refactoring by ensuring that the existing tests still pass.
- It helps identify whether new code passes or fails.
24. You have implemented a method -add(int a, int b) - in a class named Calculator, using TDD and it works perfectly. Now, the requirements have changed, and you are required to first multiply each number passed by 2 before adding them. Which stage of the Red-Green-Refactor cycle are you in?
- Green – implement the updated functionality in a new method.
- Refactor – improve the code for efficiency without changing the method.
- None. Make the required changes in the method add() directly, and ensure the tests pass.
- Red – write a new failing test for the updated functionality in a new method.
25. You have several test classes for your application, namely AddTest, SubtractTest, and MultipleTest. What is the primary benefit of running them as part of a test suite?
- It helps remove the use of the @Testannotation from the test methods.
- It allows you to test multiple functionalities and test classes in one execution.
- It speeds up the execution of the individual tests.
- It removes the need to run tests individually.