Unit Testing and TDD Flashcards
(16 cards)
What is the primary concept behind Test-Driven Development (TDD)?
Write tests based on specifications before writing the code, then build code that passes those tests.
What are the benefits of TDD?
Integrates specs, coding, and testing; encourages planning before coding; ensures ongoing functionality after changes.
What type of testing is TDD an example of?
Open Box Testing — because the developer knows the internal structure of the code being tested.
What is the difference between open and closed box testing?
Open box tests with knowledge of the code test how it is supposed to work (developer testing); closed box tests with no internal knowledge test outputs for inputs (user/release testing).
How does JUnit help with TDD?
It allows writing tests in separate files using annotations and built-in functions, improving organization and readability.
What are some common JUnit assertions?
assertEquals, assertTrue, assertFalse, assertNull, assertNotNull, assertSame, assertNotSame.
What are JUnit’s @BeforeAll and @AfterAll used for?
To set up and tear down test resources (e.g. test files) before and after all tests are run.
What are good practices in writing tests?
Aim for full line, function, condition, path, and entry/exit coverage; include multiple asserts; don’t modify tests for each case.
What is the difference between automated and manual testing?
Automated testing uses scripts/code and can run continuously; manual testing involves human interaction and is typically run at stages.
What does @Disabled do in JUnit?
Temporarily disables a test, similar to commenting it out.
What is assertThrows used for in JUnit?
To test that a specific exception is thrown by the code.
What is a sign of a good test in TDD?
It fails initially before the feature is implemented, then passes after correct code is written.
What unit testing frameworks exist in other languages?
PyUnit (Python), CppTest (C++), NUnit (C#), and many others.
What does “testing for the right error” mean?
A test should pass when the correct error or exception is triggered, indicating robust error handling.
Automated vs manual testing
Automated - large amounts of scripted or coded tests, automate large volume data testing, run as often as the code is compiled
Manual - testing example user interactions, run at planned times
Good tests have…
Line coverage, function coverage, condition coverage, path coverage, entry/exit coverage