This directory contains comprehensive visual testing tools for the tf_ggplot functionality. These tools help ensure that tf_ggplot produces sensible, correct, and visually appealing plots.
The visual testing system provides three levels of testing:
test-tf-ggplot-visual.R - Main visual tests with plot generationtest-tf-ggplot-basic.R - Basic functionality teststest-tf-ggplot-advanced.R - Advanced feature teststest-tf-ggplot-aesthetic-equivalence.R - Aesthetic specification equivalence testshelper-tf-ggplot.R - Test utilities and helper functionsvisual-test-runner.R - Comprehensive test runner with HTML report generationquick-visual-check.R - Interactive development testing toolREADME-visual-testing.md - This documentationFor rapid development and debugging:
# Load the quick testing tools
source("tests/quick-visual-check.R")
# Run interactive test menu
run_interactive_tests()
# Or run specific tests
test_basic_line() # Test basic line plots
test_ribbon_plot() # Test confidence bands
test_faceting() # Test faceted plots
test_multiple_aesthetics() # Test complex aesthetic mappings
For thorough testing with HTML reports:
# Load the test runner
source("tests/visual-test-runner.R")
# Run all tests and create HTML report
run_tf_ggplot_visual_tests()
# Options:
run_tf_ggplot_visual_tests(
interactive_display = TRUE, # Show plots as they're created
create_report = TRUE, # Generate HTML report (default)
open_report = TRUE # Auto-open report in browser (default)
)
# Just create report from existing plots
create_visual_report()
Run through testthat:
# Run specific visual test file
testthat::test_file("tests/testthat/test-tf-ggplot-visual.R")
# Run all tf_ggplot tests
testthat::test_dir("tests/testthat", filter = "tf-ggplot")
The visual testing system creates organized output:
tests/
├── visual-output/
│ ├── plots/ # Individual plot PNG files
│ │ ├── 01_basic_line_constructor.png
│ │ ├── 02_basic_line_geom.png
│ │ ├── ...
│ │ └── 17_wide_range.png
│ ├── reports/ # HTML reports
│ │ └── visual_test_report.html
│ └── comparisons/ # Side-by-side comparisons
└── test-plots/ # Basic test output (legacy)
When reviewing plots, check for:
# Quick check during development
source("tests/quick-visual-check.R")
test_basic_line() # Will show current geom_spaghetti for reference
# Test specific features as you implement them
test_ribbon_plot() # For ribbon geom support
test_multiple_aesthetics() # For complex aesthetic handling
# Full test suite with report
source("tests/visual-test-runner.R")
run_tf_ggplot_visual_tests()
# Review HTML report for all plots
# Standard unit tests
testthat::test_dir("tests/testthat")
Add tests to test-tf-ggplot-visual.R:
test_that("my new feature looks correct", {
skip_if_not_installed("ggplot2")
skip_if_no_tf_ggplot()
# Create test data
data <- create_test_tf_data(...)
# Create plot
p <- tf_ggplot(data, aes(...)) + geom_xxx(...)
# Save for visual inspection
save_test_plot(p, "my_new_feature")
# Basic validation
expect_s3_class(p, "ggplot")
# ... other checks
})
Modify save_visual_test_plot() in visual-test-runner.R to add new categories.
For automated testing, disable interactive features:
run_tf_ggplot_visual_tests(
interactive_display = FALSE,
create_report = TRUE,
open_report = FALSE
)
open_report = FALSE and open manuallyFor large test suites:
- Use coarser evaluation grids during development
- Limit number of functions in test data
- Use ggsave() with lower DPI for faster saving
open/xdg-open commandsinteractive_display = FALSEWhen adding new tf_ggplot features:
The visual testing system is designed to grow with the tf_ggplot functionality and provide confidence that the implementation produces correct, beautiful functional data visualizations.
Any scripts or data that you put into this service are public.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.