Soft target for code coverage: 80 % (with exceptions not being tested)
This document goes over the testing of this app.
Source code for tests available on GitHub.
Run the following command on your favorite shell/terminal/console/command prompt:
gradlew test --console verbose
If that doesn't work, try this one (especially on Windows):
gradlew.bat test --console verbose
If you don't want verbose output, you can remove --console verbose
from the command.
JUnit
was chosen as the testing framework. It had just got a new release, version 5, but its use was purposefully deferred within this project. So version 4.12 was used instead.
This app has somewhat extensive unit tests. Integration tests were not part of the requirements, but naturally some have been made as well.
Huffman coding and LZW both rely on BinaryReadTool
and BinaryWriteTool
-tools. Testing those in an integration test also tests these binary tools.
Even enums are tested in case someone accidentally changes or breaks them. They were also driving the code coverage percentage down.
Both Huffman and LZW have tests for the following:
- Compress a deterministic binary file
- Decompress a previously compressed file
- Benchmark both algorithms against each other
A class called _Generic
is used by multiple different tests. It provides functionality to create deterministic TXT and binary files, return random integer values as well as the ability to compare two files together (to see if they are identical).
Huffman and LZW both use tree structures, which have been defined in their own files (HuffmanNode
, LZWNode
and LZWTree
). Unit tests have been created targeting just those parts.
You can find the code coverage reports on Codecov.
The Main-class as well as the UI components have been ignored in code coverage.
The functionality provided by the app is tested directly without using any UI components.
One might wonder why the code coverage isn't 100 %. I've set a soft target of 80 % for this project, due to the following reasons.
Exceptions are currently not being tested and, as far as I know, they cannot be ignored in the code coverage reports.
Here's an example of an exception (Java):
try {
this.binaryReadTool = new BinaryReadTool(source);
} catch (IOException ex) {
UiController.printErrorMessage(ex);
return;
}
Code in the try
-section is tested, but the code in the catch
-block is not.