-
Notifications
You must be signed in to change notification settings - Fork 10
Description
@bzkrouse as we discussed:
Problem: unit test coverage at file level is currently a bit more difficult to track. Not easy to identify if a function is tested directly and in which file.
Solution: reorganise the existing unit tests and fill in gaps (if needed).
Approach:
I propose the following steps:
- rebuild the 1-to-1 relationship between files under
R/
and files undertests/testthat/
- basically each file underR/
to have its matching test file. - check to see if any tests need to be moved around. For example,
function_a()
is defined inR/function_a.R
, but its tests live intests/testthat/test-function_b.R
. This would require moving the test forfunction_a()
totest-function_a.R
- this will allow us to identify gaps a bit easier. If
function_a()
could benefit from additional tests (let's say it's error behaviour is not tested) they should be added to the corresponding test file.
It might be more difficult and risky to do this in one go (one or more PRs corresponding to the above points) and definitely more tedious to review. It might be better to agree to do this in principle and tackle it in smaller chunks, as we go. e.g. if we touch a file, check to see it has tests and they are in the expected location.
Example: frmt_structure()
is defined in R/frmt_plans.R
. The function seems to only be indirectly tested and there is no matching test file (tests/testthat/test-frmt_plans.R
does not exist).
- create
test-frmt_plans.R
- move any relevant tests here (if they exist)
- write more tests if needed
Code used to check which `R/` files do not have matching test files
definition_files <- fs::dir_ls("R/")
build_expected_test_file_path <- function(file_name) {
file_path_without_dir <- fs::path_file(file_name)
fs::path(
"tests",
"testthat",
paste0(
"test-",
usethis:::compute_name(
file_path_without_dir
)
)
)
}
expected_test_files <- purrr::map_chr(definition_files, build_expected_test_file_path)
files_and_matching_test_file <- purrr::map_lgl(expected_test_files, fs::file_exists)
files_without_matching_test_file <- files_and_matching_test_file[files_and_matching_test_file == FALSE]
Files without a matching test-
file:
-
"R/apply_col_plan.R"
-
"R/apply_col_style_plan.R"
-
"R/apply_frmt_methods.R"
-
"R/apply_table_frmt_plan.R"
-
"R/body_plan.R"
-
"R/col_style_plan.R"
-
"R/data.R"
- does not need atest-
file -
"R/eval_tidyselect.R"
-
"R/frmt_plans.R"
-
"R/frmt_utils.R"
-
"R/mock_tbl.R"
-
"R/page_plan.R"
-
"R/print_to_ggplot.R"
-
"R/print_to_gt.R"
-
"R/row_group_plan.R"
-
"R/struct_utils.R"
-
"R/tfrmt.R"
-
"R/tfrmt_layer.R"
-
"R/theme_element.R"
-
"R/utils-pipe.R"
- does not need atest-
file -
"R/zzz.R"
- does not need atest-
file