Questions and Verified Answers |
Already Graded A+
segment code - 🧠ANSWER ✔✔methods should perform one well-defined
functionality
how does segment code increase testability? - 🧠ANSWER ✔✔more
reusable and maintainable, the methods don't depend on each other
anymore
DRY - 🧠ANSWER ✔✔Don't Repeat Yourself
DRYL why shouldn't we repeat ourselves? - 🧠ANSWER ✔✔- Increased
code to maintain, more room for error
- Less timetable → have to do increased testing and when there is a defect,
the bug fix has to be replicated in all copies
,DRY: what do i do with similar code? - 🧠ANSWER ✔✔merge them!
functionally similar w/ diff types? - 🧠ANSWER ✔✔polymorphism
DRY: which type of classes and methods should we make use of? -
🧠ANSWER ✔✔- generic ones
- parameterized types
use generic classes when - 🧠ANSWER ✔✔there is no superclass
TUFs - 🧠ANSWER ✔✔Test-Unfriendly Features
TUCs - 🧠ANSWER ✔✔Test-Unfriendly Constructs
no TUFs inside - 🧠ANSWER ✔✔TUCs
TUFs are - 🧠ANSWER ✔✔features that you want to fake using stubs
(because they take too long to set up to work correctly, or test, or testing
them causes unwanted side-effects
examples of TUFs - 🧠ANSWER ✔✔- printing to console
- reading / writing from a database / to a filesystem
- access a diff program or system / the network
,TUCs are - 🧠ANSWER ✔✔methods that are hard to fake using stubbing or
overriding
stubbing def - 🧠ANSWER ✔✔replacing a method in a mocked object using
Mockito
overriding def - 🧠ANSWER ✔✔overriding a method in a "fake" class that
subclasses real class
TUCs examples - 🧠ANSWER ✔✔- object constructors / destroctors
- private methods
- final methods
(the above four are impossible to override)
- static methods: impossible to override or to stub (since static methods are
called on classes not objects)
so what does no TUFs inside TUCs mean? - 🧠ANSWER ✔✔do not put
code that you want to fake (TUFs) inside methods that are hard to fake
(TUCs)
3
COPYRIGHT©JOSHCLAY 2025/2026. YEAR PUBLISHED 2025. COMPANY REGISTRATION NUMBER: 619652435. TERMS OF USE. PRIVACY
STATEMENT. ALL RIGHTS RESERVED
, make it easy to satisfy preconditions - 🧠ANSWER ✔✔- depnednece on
external data is bad for testing
external data examples - 🧠ANSWER ✔✔- val of global vars
- val extracted from a global data structure
- val read from a file / database
- basically any val that you did not pass in as args
- aka side-effects
pass in data using args (will need less external data) and for the remaining
external data - 🧠ANSWER ✔✔- segregate hard-to-test code w/ side-effects
into a small corner
- keep as many methods pure as possible
make it easy to reprouce - 🧠ANSWER ✔✔- dependence on random data is
bad for testing
- random data = impossible to reproduce result
if you pass in Die d var, - 🧠ANSWER ✔✔you can do