API Testing Test 1 — Questions and Answers
Question 1: Which variable is provided by default for environment variables in Jenkins Pipeline?
- global
- environment
- env (Correct answer)
- none of the above
Correct answer: env
In Jenkins Pipeline scripts, the `env` global variable is automatically provided and serves as a map-like object to access and manipulate environment variables. You can read existing environment variables (e.g., `env.BUILD_NUMBER`) or set new ones (e.g., `env.MY_VAR = 'value'`) using this variable within your pipeline stages, making it essential for managing build environments.
Question 2: For the json-schema-validator module, which library does REST Assured use?
- fge library (Correct answer)
- efg library
- egf library
- feg library
Correct answer: fge library
REST Assured's `json-schema-validator` module leverages the `fge` JSON Schema Validator library (specifically, `com.github.fge.jsonschema`). This library provides the underlying functionality for validating JSON responses against a defined JSON schema. It ensures that the structure, data types, and content of the API's output conform to the expected contract, enhancing API reliability.
Question 3: Which Postman variables are available across all requests in a collection and are not affected by environment?
- Local variables
- Global variables
- Collection variables (Correct answer)
- Environment variables
Correct answer: Collection variables
Collection variables in Postman are specifically designed to be accessible by all requests within a particular collection. Unlike environment variables, which can change based on the selected environment, collection variables remain constant across all environments for that collection. This makes them ideal for values common to the entire collection, such as base URLs or authentication tokens that don't vary by environment.
Question 4: Which Postman console offers diagnostic data during development?
- DevTools console (Correct answer)
- User console
- Postman console
- None of the above
Correct answer: DevTools console
The Postman DevTools console, similar to browser developer tools, provides detailed diagnostic information during API development and testing. It allows users to inspect network requests, view console logs, examine variable values, and debug scripts. This offers crucial insights into the execution flow and helps identify potential issues within requests or scripts.
Question 5: Which data provider function in PHPUnit allows a test method to accept any number of arguments?
- Provider
- addition
- additionProvider (Correct answer)
- Provideraddition
Correct answer: additionProvider
In PHPUnit, a data provider method is used to supply multiple sets of arguments to a single test method, allowing it to be executed with various inputs. The `additionProvider` (or any method named `*Provider`) is a convention for such a data provider function. It returns an array of arrays, where each inner array represents a set of arguments for one execution of the test method, enabling robust testing with diverse data.
Question 6: What is the REST guaranteed default port?
- 8080 (Correct answer)
- 800
- 8000
- none of the above
Correct answer: 8080
While REST itself is an architectural style and doesn't mandate a specific port, the common convention for many web servers and application servers that host RESTful APIs, especially during development or for non-standard HTTP/HTTPS, is port 8080. This port is frequently used for HTTP traffic when port 80 (standard HTTP) is unavailable or reserved, making it a de facto default for many REST implementations.
Question 7: Which activities should not be included in end-to-end testing design as build conditions?
- timing and data conditions
- Building a set of conditions for each user function defined
- sequence conditions
- none of the above (Correct answer)
Correct answer: none of the above
End-to-end testing aims to simulate real user scenarios by testing an application's entire workflow from start to finish. This includes considering various conditions like timing, data, and sequence, as these factors directly impact how a user interacts with the system. Therefore, all the listed activities (timing and data conditions, building a set of conditions for each user function, sequence conditions) are crucial for a comprehensive end-to-end testing design, meaning none of them should be excluded.
Question 8: What is Pytest's mechanism for executing code before each test method?
- Running tests in parallel
- Parameterized tests
- Pytest fixtures (Correct answer)
- None of the above
Correct answer: Pytest fixtures
Pytest fixtures are functions that run before (and optionally after) test functions, modules, or sessions. They are used to set up a stable and known environment for tests, such as creating temporary files, setting up database connections, or providing test data. This mechanism ensures that each test starts with the required preconditions, promoting reusability and isolation.
Question 9: Which Postman variables enable data access across collections, requests, test scripts, and environments?
- Local variables
- Environment variables
- Collection variables
- Global variables (Correct answer)
Correct answer: Global variables
Global variables in Postman have the broadest scope, meaning they can be accessed by any request, collection, or environment within your Postman workspace. This makes them ideal for storing data that needs to be shared across multiple tests or workflows, such as authentication tokens or base URLs that might change infrequently. Their wide accessibility ensures data consistency across your testing efforts.
Which variable is provided by default for environment variables in Jenkins Pipeline?