Menu

#9 Provide an easy way to locate problem tests

open
nobody
None
5
2014-04-15
2014-04-15
No

When I run a test suite, I mostly care about the tests that have failed, since they are the ones that need fixing. The print.RUnitTestData method gives too little information about the source of the problem tests, whereas the summary.RUnitTestData method hides it within too much output.

I'd like a function that shows which test suite, file and test a failure or error message belongs to. Suggested implementation, with roxygen2 comments:

#' Find problematic tests
#' 
#' Finds tests that failed or threw an error.
#' @param x An object of class 'RUnitTestData'.
#' @return A data frame with columns
#' \describe{
#'  \item{suite}{The test suite that the problem occured in.}
#'  \item{file}{The file that the problem occured in.}
#'  \item{test}{The test that the problem occured in.}
#'  \item{kind}{Either 'error' or 'failure'.}
#'  \item{message}{The error message.}
#' }
problems <- function(x)
{
  if(!inherits(x, "RUnitTestData"))
  {
    stop("x is not an object of class 'RUnitTestData'.")
  }
  y <- do.call(
    rbind,
    Map(    
      function(suite, suitename)
      {
        do.call(
          rbind,
          Map(
            function(tests, filename)
            {
              do.call(
                rbind,
                Map(
                  function(test, testname)
                  {           
                    if(test$kind != "success")
                    {
                      data.frame(
                        suite   = suitename, 
                        file    = filename, 
                        test    = testname, 
                        kind    = test$kind,  
                        message = test$msg
                      )
                    }
                  },
                  tests,
                  names(tests)
                )
              )
            },
            suite$sourceFileResults,
            names(suite$sourceFileResults)
          )
        )
      },
      x,
      names(x)
    )
  )
  rownames(y) <- NULL
  y
}

Discussion


Log in to post a comment.