Skip to content
Prev 38679 / 63424 Next

How to use the RUnit tracker in unit tests?

R-developers

Does anybody know how I incorporate the use of the tracker in RUnit
in the unit tests?

I have read the RUnit Vignette, help pages and searched around,
but I could find no examples of using 'inspect' in the unit
test functions. Moreover, doing so, I tried something like

library(RUnit)
myFunction <- function(x) {
	return(x)
}
track <- tracker()
track$init()

test.someTestFunction <- function() {
   y <- 10
   res <- inspect(myFunction(y), track = track)
   checkEquals(res, 10)
}

which works fine, when calling test.someTestFunction() from
the command line, but embedded in a test suite, I get
Error in eval(expr, envir, enclos) : object 'y' not found

Another question/suggestion: The 'inspect' function inserts
track points in the code, and this could perhaps be used
differently. Instead of doing it in a local copy of the code
(as I understand it is done), it could be done in the original
function, like 'trace' can replace the original code, I believe.
Then every subsequent call will be tracked, until inspection is
stopped. I imagine something like

startInspection(myFunction, track = track)
[ or startInspection(myFunction, signature = "numeric", track = track)]
myFunction(10)
stopInspection(myFunction)

Is this already around?

Best, Niels