POC POC Testing & Quality Assurance 1 — Questions and Answers
Question 1: Which Python module provides built-in unit testing capabilities?
- unittest (Correct answer)
- pytest
- nose
- doctest
Correct answer: unittest
The `unittest` module is Python's built-in testing framework inspired by JUnit.
Question 2: What decorator is used in unittest to mark a test that should be skipped?
- @skip
- @unittest.skip (Correct answer)
- @ignore
- @pytest.skip
Correct answer: @unittest.skip
The `@unittest.skip` decorator marks a test to be skipped with an optional reason string.
Question 3: In pytest, what naming convention must test files follow to be automatically discovered?
- test_*.py or *_test.py (Correct answer)
- *.test.py
- tests/*.py
- check_*.py
Correct answer: test_*.py or *_test.py
Pytest discovers test files named `test_*.py` or `*_test.py` in the current directory tree by default.
Question 4: What method in unittest is used to verify that two values are equal?
- assertEqual() (Correct answer)
- assertSame()
- assertEquals()
- verify()
Correct answer: assertEqual()
`assertEqual(a, b)` checks that `a` and `b` are equal and raises AssertionError if not.
Question 5: What is the purpose of `setUp()` in a unittest TestCase class?
- To run code before each test method (Correct answer)
- To initialize the test suite
- To configure test output format
- To load test data from files
Correct answer: To run code before each test method
`setUp()` is automatically called before each individual test method to prepare the test environment.
Question 6: What does TDD stand for in software development?
- Test-Driven Development (Correct answer)
- Test Data Definition
- Top-Down Design
- Technical Design Document
Correct answer: Test-Driven Development
TDD (Test-Driven Development) is a methodology where tests are written before the actual implementation code.
Which Python module provides built-in unit testing capabilities?