Learn R Programming

svUnit (version 1.0.6)

svSuiteData: Objects of class 'svSuiteData' contain results from running test suites

Description

The 'svSuiteData' object contains results of all test run in one or more test suites. The checkxxx() functions and the runTest() method generate data (objects 'svTestData') contained in the default 'svSuiteData' named .Log and located in .GlobalEnv. It is then possible to display and report information it contains in various ways to analyze the results.

Usage

is.svSuiteData(x)

# S3 method for svSuiteData stats(object, ...)

metadata(object, ...)

# S3 method for svSuiteData metadata( object, fields = c("R.version", "sessionInfo", "time", "description"), ... )

# S3 method for svSuiteData print(x, all = FALSE, file = "", append = FALSE, ...)

# S3 method for svSuiteData summary(object, ...)

protocol(object, type = "text", file = "", append = FALSE, ...)

# S3 method for default protocol(object, type = "text", file = "", append = FALSE, ...)

# S3 method for svSuiteData protocol(object, type = "text", file = "", append = FALSE, ...)

protocol_text(object, file = "", append = FALSE, ...)

# S3 method for svSuiteData protocol_text(object, file = "", append = FALSE, ...)

protocol_junit(object, ...)

# S3 method for svSuiteData protocol_junit(object, file = "", append = FALSE, ...)

Arguments

x

Any kind of object, or a 'svSuiteData' object in the case of print().

object

A 'svSuiteData' object.

...

Further arguments to pass to methods. Not used yet.

fields

Character vector. The name of all metadata items you want to extract for the object. The default value is an exhaustive list of all available metadata (i.e., defined by default) in the object, but you can add more: just add a corresponding attribute to your object.

all

Do we print concise report for all test, or only for the tests that fail or produce an error?

file

Character. The path to the file where to write the report. If file = "", the protocol report is output to the console.

append

Do we append to this file?

type

Character. The type of protocol report to create. For the moment, only type = "text" and type = "junit" are supported, but further types (HTML, LaTeX, Wiki, etc.) could be provided later.

Value

is.svSuiteData() returns TRUE if the object is an 'svSuiteData'. The various methods serve to extract or print content in the object.

Details

A 'svSuiteData' is, indeed, an environment. The results for the various tests runs are in non hidden (i.e., names not starting with a dot) objects that are of class 'svTestData' in this environment. Various other objects that control the execution of the test, their context, etc. are contained as hidden objects with name starting with a dot. Note that using an environment instead of a list for this object allows for a call by reference instead of a usual call by value in R, when passing this object to a function. This property is largely exploited in all svUnit functions to make sure results of test runs are centralized in the same log ('svSuiteData' object).

See Also

svSuite(), is.svTestData(), Log(), checkEquals()

Examples

Run this code
# NOT RUN {
clearLog()    # Clear any existing log

# Run some tests
checkTrue(1 < 2)
checkException(log("a"))
foo <- function(x, y = 2)
  return(x * y)
test(foo) <- function() {
  checkEqualsNumeric(4, foo(2))
  checkEqualsNumeric(6, foo(2, nonexisting))
  checkTrue(is.test(foo))
  warning("This is a warning")
  cat("Youhou from test!\n")  # Don't use, except for debugging!
  checkTrue(is.test(test(foo)))
  checkIdentical(attr(foo, "test"), test(foo))
  checkException(foo(2, nonexisting))
  #DEACTIVATED("My deactivation message")
  checkException(foo(2))  # This test fails
}
runTest(foo)

# Now inspect the log, which is a 'svSuiteData' object
is.svSuiteData(Log())
stats(Log())
metadata(Log())
Log()    # Print method
summary(Log())

# }
# NOT RUN {
# To get a print of the test protocol on file, use:
protocol(Log(), type = "text", file = "RprofProtocol.out")
file.show("RprofProtocol.out")
unlink("RprofProtocol.out")
# }
# NOT RUN {
rm(foo)

# }
# NOT RUN {
# Profiling of very simple test runs
library(utils)
createLog(description = "test profiling", deleteExisting = TRUE)
imax <- 3
jmax <- 100
l <- 50
Rprof()
for (i in 1:imax) {
  # Change the context for these tests
  .Log$..Test <- paste("Test", i, sep = "")
  .Log$..Tag <- paste("#", i, sep = "")
  res <- system.time({
    for (j in 1:jmax) checkTrue(i <= j, "My test")
  }, gcFirst = TRUE)[3]
  print(res)
  flush.console()
}
Rprof(NULL)
# Look at profile
summaryRprof()
unlink("Rprof.out")

# Look at the log
summary(Log())
# }

Run the code above in your browser using DataLab