Quiz: Testing and Code Quality
Validate your mastery of unit testing, pytest fixtures, mocking dependencies, and static analysis questions.
We'll cover the following...
We'll cover the following...
Technical Quiz
1.
We have a test class utilizing the unittest framework. Consider the following setup:
import unittest
class TestDatabase(unittest.TestCase):
data = []
def setUp(self):
self.data.append(1)
def test_add_one(self):
self.assertEqual(len(self.data), 1)
def test_add_two(self):
self.assertEqual(len(self.data), 1)
What happens when we run this test suite (assuming that the execution order is test_add_one then test_add_two)?
A.
Both tests pass.
B.
test_add_one passes, but test_add_two fails because len(self.data) is 2.
C.
test_add_one fails because data is not initialized in __init__.
D.
Both tests fail because setUp cannot modify class attributes.
1 / 8
...