Unit Testing & JUnit 4 Flashcards
What is unit testing?
The independent testing of a certain code block to validate that it works as intended under certain circumsrtances.
What is unit testing trying to prove?
That a code block works under certain conditions. It’s infeasible to test all conditions though.
When should code be tested?
Before of concurrently to the test code being implemented into the production code base.
What are the 3 main benefits of unit testing?
- Reduces amount of bugs implemented into production code.
- Tests make program functionality easier to understand.
- Defined tests help keep project goals defined and prevent scope creep.
What is the acronym for producing a good unit test?
Rightness : Results are as expected.
Boundaries : Operates in defined boundaries.
Inverse : Can check the inverse relationship of the method.
Cross-check : Can be cross-checked by some means.
Errors : Can force error conditions.
Performance Characteristics : Performs as expected under defined conditions.
What are the properties of good unit tests?
Automatic, Thorough, Repeatable, Independent, Professional (well structured).
What is JUnit4?
A unit testing framework for java.
What are the 4 admin actions all tests should take for good testing?
- Set up testing conditions.
- Call the methods to be tested.
- Verify the test results are as expected.
- Clear up after the test.
Which concept underpins almost all testing?
Assertions.
Can a test have multiple / no assertions?
Yes and Yes.
Why is it unwise to assertEquals a floating point number?
Because, due to memory finiteness, it may not be possible to achieve equality. Therefore, it’s best to use some form of proximity test.
How does the fail(String msg) test method work?
If the fail() is executed, the test has failed and terminates.
What are the typical imports needed for unit testing in JUnit4?
Before, BeforeClass, Test, After, AfterClass, Assert.