Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to define a test suite using unittest in Python.
Testing Fundamentals
import unittest class MyTests(unittest.[1]): def test_example(self): self.assertEqual(1 + 1, 2)
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using TestSuite instead of TestCase for defining test classes.
✗ Incorrect
The TestCase class is used to create individual test cases in unittest.
2fill in blank
mediumComplete the code to add a test case to a test suite.
Testing Fundamentals
suite = unittest.TestSuite() suite.addTest(MyTests('[1]'))
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using lifecycle methods like setup or tearDown instead of test methods.
✗ Incorrect
The method name test_example is the test method to add to the suite.
3fill in blank
hardFix the error in the code to run the test suite using unittest.
Testing Fundamentals
runner = unittest.TextTestRunner()
runner.[1](suite) Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using incorrect method names like runTests or execute.
✗ Incorrect
The correct method to run a test suite is run.
4fill in blank
hardFill both blanks to create a test suite from multiple test cases.
Testing Fundamentals
loader = unittest.TestLoader()
suite = unittest.TestSuite([
loader.[1](MyTests),
loader.[2](OtherTests)
]) Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using non-existent functions like runSuite or buildSuite.
✗ Incorrect
The makeSuite method creates a suite from a TestCase class.
5fill in blank
hardFill all three blanks to filter and run tests with unittest.
Testing Fundamentals
loader = unittest.TestLoader() suite = loader.[1]('test_example') runner = unittest.TextTestRunner() runner.[2](suite) # To run only tests matching a pattern, use [3] method.
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Confusing loadTestsFromTestCase with loadTestsFromName.
Using runTests instead of run.
✗ Incorrect
loadTestsFromName loads tests by name, run executes the suite, and discover finds tests matching a pattern.