All tests can be found under the src/test directory. The tests files can be categorized into three different categories. These are unit test files, an integration test file, and two utility files for testing.
These tests are located in the subdirectories of src/test/java/org/troy/capstone/. They test individual methods and classes in isolation from most of the program. Tests have been designed to target most methods individually, with test cases being used to go after each branch of each method. Many tests make use of the ParameterizedTest annotation to allow multiple cases to run for each test written into code.
There is one integration test file, src/test/java/org/troy/capstone/MainTest.java. This file tests the SearchEngine class, which is responsible for applying all filters and sorting to the data. This class is a good candidate for integration testing, as it relies on many different classes and methods to operate correctly.
testDisplayInSimilarItemsAndRecentlyViewedItems clicks on an item in the SearchedItemPagination and checks that it gets displayed in the RecentlyViewedWindow as well as checking that the similar items are correctly displayed in the SimilarItemsContainer. A video of the test running can be seen HERE.testFilteredSearch makes a selection for each filter type and checks that the right number of results are returned, and that the SearchedItemPagination is updated with the correct number of pages. A video of the test running can be seen HERE.
TestUtils.java contains three utility methods for testing.
public static <T extends Node> T lookupByTestFXId(TestFXId testFXId)
Node or descendant of Node in the scene graph that matches the given TestFXId. public static <T extends Node> T lookupByTestFXId(String testFXId)
lookupByTestFXId method, but it takes in a String, since the ID for some nodes are a template and then the full ID is not known until runtime. public static boolean equals(Table table1, Table table2)
Table objects are equal by checking that they have the same number of columns, the same number of rows, the same column names in the same order, and the same values in every column of every row.generated_docs/coverage/ directory. To properly view the report open the index.html file in that directory in a web browser once cloned (or view it in GitHub Pages). This detailed report includes coverage for methods, lines, and branches for each class in the project. The tests have been designed to give as much coverage as possible.
AttributedImageContainer, except one is for the author name and the other is for the source name.
imageView.setOnMouseClicked(e -> {
try {
desktop.browse(new URI(item.getImageUrl()));
} catch (IOException | URISyntaxException ex) {
System.err.println("Failed to open image URL: " + item.getImageUrl());
}
});
AttributedItemContainer tests from opening a web browser during testing. In this case, we tested that the right link was clicked, but we prevented the link from opening a browser tab.GeneralManager and QueryFilter tests, where we verified that certain methods were called the expected number of times with the expected arguments. This allowed for more thorough testing of the interactions between different components and methods.|| and && were broken into separate conditionals to achieve higher coverage. This was necessary because the coverage sees a 2 expression conditional as having 4 branches, and this makes it harder to achieve full branch coverage, especially in cases where one half checks for null and the other half checks for an empty value.Config.java is used to load in an app.properties file that contains a configuration for enabling/disabling building the SimilarItemsGraph. This is important as the process of building the SimilarItemsGraph is time-consuming, and it is not necessary to build it for most tests. By using this config file, we can easily enable or disable the building of the SimilarItemsGraph for testing purposes, which allows for faster testing when the graph is not needed. The file in the main directory contains an enabled value for building the graph, while the file in the test directory contains a disabled value for building the graph.
String values to access fields and methods, which can break if the names of these fields and methods are changed. This is a negative for reflection, but is necessary to avoid changing access modifiers. Additionally, if parameters of methods are changed, this can also break reflection calls to these methods.