Learn R Programming

reproducible (version 0.2.11)

isInteractive: Alternative to interactive() for unit testing

Description

This is a suggestion from https://www.mango-solutions.com/blog/testing-without-the-internet-using-mock-functions as a way to test interactive code in unit tests. Basically, in the unit tests, we use testthat::with_mock, and inside that we redefine isInteractive just for the test. In all other times, this returns the same things as interactive().

Usage

isInteractive()

Arguments

Examples

Run this code
# NOT RUN {
testthat::with_mock(
`isInteractive` = function() {browser(); TRUE},
{
  tmpdir <- tempdir()
  aa <- Cache(rnorm, 1, cacheRepo = tmpdir, userTags = "something2")
  # Test clearCache -- has an internal isInteractive() call
  clearCache(tmpdir, ask = FALSE)
  })
  
# }

Run the code above in your browser using DataLab