Explore essential concepts of testing in CI/CD pipelines, focusing on understanding unit, integration, and end-to-end tests. Evaluate your grasp of test types, their purposes, scopes, and common scenarios in software development workflows.
Which type of test is focused on checking a single function or component in isolation from the rest of the system?
Explanation: A unit test verifies the behavior of a single function, method, or component without depending on other parts of the system. Integration tests involve combining components to test their interactions, which covers more than isolated units. End-to-end tests simulate real user flows through the entire application. Acceptance tests check compliance with business requirements but might span multiple components.
What is the main goal of an integration test in a CI/CD context?
Explanation: Integration tests are designed to verify that different components or modules work together as intended. They do not focus on individual code statements; that's the role of unit tests. End-to-end tests are used for simulating complete real-world scenarios, not just interactions. Deployment speed measurement is unrelated to testing types.
A test scenario fills out a registration form on a website and then verifies the creation of a user account in the system. What type of test is this?
Explanation: End-to-end tests simulate a user's journey through the entire application, such as registering and checking account creation. Smoke tests are basic checks to see if an application launches or main features work, not full workflows. Unit tests only examine small units of code, not full flows. Performance tests measure responsiveness and speed, rather than correctness of user journeys.
In a CI/CD pipeline, at which stage are unit tests typically run to provide the fastest feedback on new changes?
Explanation: Unit tests are usually executed early, often before code changes are integrated, to quickly identify issues with small units of code. Running unit tests after deploying to production would delay detection of bugs. Manual code reviews are for human inspection, not automated tests. Typically, end-to-end tests are run after unit tests, not before.
Why should unit tests avoid relying on external systems like databases or APIs?
Explanation: Unit tests are meant to test isolated pieces of code, helping quickly locate bugs. If they rely on external systems, they risk introducing unrelated failures. Reducing resource usage and speeding up deployments are secondary benefits but not the primary purpose. Checking integration is handled by integration tests, not unit tests.
Suppose you write a test to confirm that a user profile can be created only after user authentication succeeds. What type of test is this?
Explanation: This test checks the interaction between authentication and profile creation modules, making it an integration test. Configuration tests check system settings, not feature interactions. Unit tests only examine a single function in isolation. UI tests focus on the appearance and functionality of the user interface, not necessarily the interaction of backend modules.
Which of the following best describes the purpose of end-to-end testing?
Explanation: End-to-end tests check how all parts of the application function together in real user scenarios. They are not concerned with individual code variables, which is the job of unit tests. Testing only the database layer is too narrow and is covered by integration or unit tests. Resolving merge conflicts is a version control task, not related to testing.
Within a CI/CD testing pyramid, which type of test should generally have the largest number of cases?
Explanation: The testing pyramid suggests having many unit tests, fewer integration tests, and the least end-to-end tests, as unit tests are fast and granular. Integration and end-to-end tests are more complex, slower, and should be fewer. Smoke tests are a minimal set run for basic application checks, not intended for large quantities.
A test sometimes passes and sometimes fails under the same conditions, often due to timing issues or external dependencies. What is this test called?
Explanation: A flaky test is inconsistent, often failing due to external factors rather than errors in the code being tested. 'Silent test' and 'flat test' are not recognized terms in testing, and 'static test' usually refers to analysis without execution, not flaky behavior.
What is a primary benefit of automating unit, integration, and end-to-end tests in a CI/CD process?
Explanation: Automating tests provides rapid feedback, improving code quality and deployment confidence. Test automation does not automatically generate documentation or replace the value of code reviews. While it reduces risk, it cannot guarantee that no production issues will ever occur.