concepts, asserts, test classes, and coverages

0.0(0)
Studied by 0 people
call kaiCall Kai
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
GameKnowt Play
Card Sorting

1/14

encourage image

There's no tags or description

Looks like no tags are added yet.

Last updated 11:57 AM on 6/4/26
Name
Mastery
Learn
Test
Matching
Spaced
Call with Kai

No analytics yet

Send a link to your students to track their progress

15 Terms

1
New cards

concept testing

executing code with intentional inputs to verify its behavior matches its design

2
New cards

asserts

python keywords used to conduct sanity checks; if evaluated to false, python raises an AssertionError and terminates execution

3
New cards

syntax of an assert

assert [condition], “optional error message”

4
New cards

Unit Testing

automated tool built into python that allows you to test your code systematically without the need to verify your code using print statements; needs to be imported as import unittest and inherits properties from the parent class unittest.TestCase

5
New cards

how to write a test class

import unittest, inheritance: class [class name](unittest.TestCase):, every test has to start with def test_[something] otherwise it’ll be ignored by framework

6
New cards

test coverage

a percentage that tells you how much of your source code is executed during testing; passing unit tests is only good if your test coverage is high; if low it means you’re never checking majority of your code

7
New cards

statement coverage

measures whether a specific line of code was executed

8
New cards

branch coverage

measures whether every possible branch/choice in a conditional statement was tested(ie passing a true value for an if statement is 50% branch coverage because you didn’t also pass a false statement)

9
New cards

which is a better indicator of bug-free code, statement coverage or branch coverage?

branch coverage, its stricter

10
New cards

how can you increase your test coverage metric?

write more unit tests with different input arguments that target else/elif blocks or exception handlers

11
New cards

purpose of testing

to prevent regression(mistakes made when changing code in one part breaks another component)

12
New cards

purpose of asserts vs unittest

asserts are used to catch violations inside source code, unittest is used to externally validate APIs and function edge cases

13
New cards

what unittest statement checks when 2 things are equal

self.assertEqual(actual, expected)

14
New cards

what unittest checks if a statement evaluates to True

self.assertTrue(condition)

15
New cards

what unittest allows for code to throw an error instead of crashing silently

with self.assertRaises(ExceptionType)